func (g *GenKey) Export() (err error) { id, err := GetId() if err != nil { return } data, err := utils.ExecOutput(g.Root, "gpg", "-a", "--export-secret-keys", id) if err != nil { return } err = utils.CreateWrite(filepath.Join(g.Root, "sign.key"), data) if err != nil { return } data, err = utils.ExecOutput(g.Root, "gpg", "-a", "--export", id) if err != nil { return } err = utils.CreateWrite(filepath.Join(g.Root, "sign.pub"), data) if err != nil { return } return }
func GetName() (name string, err error) { output, err := utils.ExecOutput("", "gpg", "--list-keys") if err != nil { return } for _, line := range strings.Split(output, "\n") { if !strings.HasPrefix(line, "uid") { continue } index := strings.Index(line, "]") if index == -1 { fields := strings.Fields(line) if len(fields) < 2 { continue } name = strings.Join(fields[1:], " ") } else { name = strings.TrimSpace(line[index+1:]) } return } err = &LookupError{ errors.New("signing: Failed to find gpg name"), } return }
func (d *Debian) getSums() (err error) { output, err := utils.ExecOutput(d.Pack.PackageDir, "find", ".", "-type", "f", "-exec", "md5sum", "{}", ";") if err != nil { return } d.sums = "" for _, line := range strings.Split(output, "\n") { d.sums += strings.Replace(line, "./", "", 1) + "\n" } return }
func (r *Redhat) getFiles() (files []string, err error) { backup := set.NewSet() paths := set.NewSet() for _, path := range r.Pack.Backup { if !strings.HasPrefix(path, "/") { path = "/" + path } backup.Add(path) } rpmPath, err := r.getRpmPath() if err != nil { return } output, err := utils.ExecOutput(r.Pack.PackageDir, "rpm", "-qlp", rpmPath) if err != nil { return } for _, path := range strings.Split(output, "\n") { if len(path) < 1 { continue } paths.Remove(filepath.Dir(path)) paths.Add(path) } for pathInf := range paths.Iter() { path := pathInf.(string) if backup.Contains(path) { path = `%config "` + path + `"` } else { path = `"` + path + `"` } files = append(files, path) } return }
func GetId() (id string, err error) { output, err := utils.ExecOutput("", "gpg", "--list-keys") if err != nil { return } hasKey := false for _, line := range strings.Split(output, "\n") { if hasKey { id = strings.TrimSpace(line) break } if !strings.HasPrefix(line, "pub") { continue } if !strings.Contains(line, "/") { hasKey = true continue } fields := strings.Fields(line) if len(fields) < 2 { continue } split := strings.Split(fields[1], "/") if len(split) < 2 { continue } id = split[1] break } if id == "" { err = &LookupError{ errors.New("signing: Failed to find gpg id"), } } return }