func SignRepo(fp string) error {
	repo, fperr := GetRepo(fp)
	if fperr != nil {
		return fperr
	}
	releaseFile := repo + "/Release"
	outputFile := repo + "/Release.gpg"
	_, err := ioutil.ReadFile(releaseFile)
	if err != nil {
		return err
	}
	_, gpgerr := exec.Command("gpg", "-abs", "-o", outputFile, releaseFile).Output()
	if gpgerr != nil {
		return gpgerr
	}
	return nil
}
SignRepo signs the repo's Packages and Packages.bz2 using devs' GPG key.
package afutil
import (
	"errors"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"runtime"
	"strconv"
	"github.com/hako/afto/deb"
	"github.com/hako/afto/release"
)
var (
	debFilesNotFound = "no .deb file(s) found. unable to continue"
	debFileNotFound  = " not found. unable to continue"
)
func ParseDir(indir string) (bool, error) {
	var reqfiles = []string{"Packages", "Release"}
	var valid = false
	var reqcount = 0
	files, err := ioutil.ReadDir(indir)
	if err != nil {
		return valid, errors.New("directory " + indir + " not found or valid.")
	}
	for _, file := range files {
		for _, reqfile := range reqfiles {
			if file.Name() == reqfile {
				reqcount++
			}
		}
	}
	if reqcount < len(reqfiles) {
		count := len(reqfiles) - reqcount
		return valid, errors.New(strconv.Itoa(count) + " required files missing. (Need Packages and Release)")
	}
	valid = true
	return valid, nil
}
func CheckDpkg() error {
	_, err := exec.LookPath("dpkg")
	if err != nil {
		return errors.New("Unable to find required command 'dpkg'")
	}
	return nil
}
func CheckBzip2() error {
	_, err := exec.LookPath("bzip2")
	if err != nil {
		return errors.New("Unable to find required command 'bzip2'")
	}
	return nil
}
func GetRepo(dir string) (string, error) {
	_, direrr := ParseDir(dir)
	if direrr != nil {
		return "", errors.New(direrr.Error())
	}
	finalPath, abserr := filepath.Abs(dir)
	if abserr != nil {
		return "", errors.New(abserr.Error())
	}
	return finalPath, nil
}
func ParseDeb(debName string) (*deb.Control, error) {
	fields, parseerr := exec.Command("dpkg", "-f", debName).Output()
	if parseerr != nil {
		return nil, parseerr
	}
	c := deb.NewControl()
	controlFile, errs := c.ParseString(string(fields))
	if errs != nil {
		return nil, errs
	}
	return controlFile, nil
}
func BzipPackages() error {
	_, bzcmderr := exec.Command("bzip2", "-kf", "Packages").Output()
	if bzcmderr != nil {
		return bzcmderr
	}
	return nil
}
func CheckDeb() ([]string, error) {
	cwdir, err := os.Getwd()
	if err != nil {
		return nil, err
	}
	files, err := ioutil.ReadDir(cwdir)
	if err != nil {
		return nil, err
	}
	var deb []string
	for _, file := range files {
		if IsDeb(file.Name()) == true {
			deb = append(deb, file.Name())
		}
	}
	if len(deb) == 0 {
		return nil, errors.New(debFilesNotFound)
	}
	return deb, nil
}
func CheckDebWithPath(path string) ([]string, error) {
	files, err := ioutil.ReadDir(path)
	if err != nil {
		return nil, err
	}
	var deb []string
	for _, file := range files {
		if IsDeb(file.Name()) == true {
			deb = append(deb, file.Name())
		}
	}
	if len(deb) == 0 {
		return nil, errors.New(debFilesNotFound)
	}
	return deb, nil
}
func CheckDebWithFile(fp string) (string, error) {
	path, fperr := filepath.Abs(fp)
	if fperr != nil {
		return "", errors.New("\"" + fp + "\"" + debFileNotFound)
	}
	if IsDeb(path) != true {
		return "", errors.New("\"" + fp + "\"" + debFileNotFound)
	}
	return path, nil
}