Add --gpg' and --gpgflags` flags

`--gpg' is the GnuPG binary, while `--gpgflags' are extra
arguments to be passed to  GnuPG.

Also Update man page and usage regarding GnuPG options.
This commit is contained in:
Sergio Correia 2018-03-17 16:40:24 -04:00
parent 03d3753a39
commit 32f8396eca
No known key found for this signature in database
GPG key ID: CE624C7096FE4BB6
7 changed files with 39 additions and 17 deletions

9
cmd.go
View file

@ -46,6 +46,7 @@ Permanent configuration options:
--pacman <file> pacman command to use
--tar <file> bsdtar command to use
--git <file> git command to use
--gpg <file> gpg command to use
--config <file> pacman.conf file to use
--requestsplitn <n> Max amount of packages to query per AUR request
@ -63,9 +64,10 @@ Permanent configuration options:
--noredownload Skip pkgbuild download if in cache and up to date
--rebuild Always build target packages
--rebuildall Always build all AUR packages
--rebuildtree Always build all AUR packages even if installed
--rebuildtree Always build all AUR packages even if installed
--norebuild Skip package build if in cache and up to date
--mflags <flags> Pass arguments to makepkg
--gpgflags <flags> Pass arguments to gpg
--sudoloop Loop sudo calls in the background to avoid timeout
--nosudoloop Do not loop sudo calls in the background
@ -202,7 +204,6 @@ func initAlpm() (err error) {
alpmConf.IgnoreGroup = append(alpmConf.IgnoreGroup, strings.Split(value, ",")...)
}
//TODO
//current system does not allow duplicate arguments
//but pacman allows multiple cachdirs to be passed
@ -411,6 +412,8 @@ func handleConfig(option, value string) bool {
config.ReBuild = "tree"
case "norebuild":
config.ReBuild = "no"
case "gpgflags":
config.GpgFlags = value
case "mflags":
config.MFlags = value
case "builddir":
@ -425,6 +428,8 @@ func handleConfig(option, value string) bool {
config.TarBin = value
case "git":
config.GitBin = value
case "gpg":
config.GpgBin = value
case "requestsplitn":
n, err := strconv.Atoi(value)
if err == nil && n > 0 {

View file

@ -35,6 +35,7 @@ type Configuration struct {
ReBuild string `json:"rebuild"`
GitBin string `json:"gitbin"`
GpgBin string `json:"gpgbin"`
GpgFlags string `json:"gpgflags"`
MFlags string `json:"mflags"`
RequestSplitN int `json:"requestsplitn"`
SearchMode int `json:"-"`
@ -127,6 +128,7 @@ func defaultSettings(config *Configuration) {
config.NoConfirm = false
config.PacmanBin = "pacman"
config.PacmanConf = "/etc/pacman.conf"
config.GpgFlags = ""
config.MFlags = ""
config.SortMode = BottomUp
config.SudoLoop = false

View file

@ -214,7 +214,7 @@ func install(parser *arguments) error {
return nil
}
err = checkPgpKeys(dc.Aur, dc.Bases, nil)
err = checkPgpKeys(dc.Aur, dc.Bases)
if err != nil {
return err
}

17
keys.go
View file

@ -41,14 +41,12 @@ func (set pgpKeySet) get(key string) bool {
}
// checkPgpKeys iterates through the keys listed in the PKGBUILDs and if needed,
// asks the user whether yay should try to import them. gpgExtraArgs are extra
// parameters to pass to gpg, in order to facilitate testing, such as using a
// different keyring. It can be nil.
func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, gpgExtraArgs []string) error {
// asks the user whether yay should try to import them.
func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg) error {
// Let's check the keys individually, and then we can offer to import
// the problematic ones.
problematic := make(pgpKeySet)
args := append(gpgExtraArgs, "--list-keys")
args := append(strings.Fields(config.GpgFlags), "--list-keys")
// Mapping all the keys.
for _, pkg := range pkgs {
@ -84,16 +82,15 @@ func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, gpgExtraArgs []s
return err
}
if continueTask(question, "nN") {
return importKeys(gpgExtraArgs, problematic.toSlice())
return importKeys(problematic.toSlice())
}
return nil
}
// importKeys tries to import the list of keys specified in its argument. As
// in checkGpgKeys, gpgExtraArgs are extra parameters to pass to gpg.
func importKeys(gpgExtraArgs, keys []string) error {
args := append(gpgExtraArgs, "--recv-keys")
// importKeys tries to import the list of keys specified in its argument.
func importKeys(keys []string) error {
args := append(strings.Fields(config.GpgFlags), "--recv-keys")
cmd := exec.Command(config.GpgBin, append(args, keys...)...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr

View file

@ -143,7 +143,7 @@ func TestImportKeys(t *testing.T) {
defer os.RemoveAll(keyringDir)
config.GpgBin = "gpg"
keyringArgs := []string{"--homedir", keyringDir}
config.GpgFlags = fmt.Sprintf("--homedir %s", keyringDir)
casetests := []struct {
keys []string
@ -183,7 +183,7 @@ func TestImportKeys(t *testing.T) {
}
for _, tt := range casetests {
err := importKeys(keyringArgs, tt.keys)
err := importKeys(tt.keys)
if !tt.wantError {
if err != nil {
t.Fatalf("Got error %q, want no error", err)
@ -212,7 +212,7 @@ func TestCheckPgpKeys(t *testing.T) {
config.BuildDir = buildDir
config.GpgBin = "gpg"
keyringArgs := []string{"--homedir", keyringDir}
config.GpgFlags = fmt.Sprintf("--homedir %s", keyringDir)
// Creating the dummy package data used in the tests.
dummyData := map[string]string{
@ -292,7 +292,7 @@ func TestCheckPgpKeys(t *testing.T) {
}
for _, tt := range casetests {
err := checkPgpKeys(tt.pkgs, tt.bases, keyringArgs)
err := checkPgpKeys(tt.pkgs, tt.bases)
if !tt.wantError {
if err != nil {
t.Fatalf("Got error %q, want no error", err)

View file

@ -427,6 +427,8 @@ func hasParam(arg string) bool {
//yay params
case "mflags":
return true
case "gpgflags":
return true
case "builddir":
return true
case "editor":
@ -439,6 +441,8 @@ func hasParam(arg string) bool {
return true
case "git":
return true
case "gpg":
return true
case "requestsplitn":
return true
default:

14
yay.8
View file

@ -152,6 +152,12 @@ The command to use for \fBgit\fR calls. This can be a command in
\fBPATH\fR or an absolute path to the file\&.
.RE
.PP
\fB\-\-gpg <file>\fR
.RS 4
The command to use for \fBgpg\fR calls. This can be a command in
\fBPATH\fR or an absolute path to the file\&.
.RE
.PP
\fB\-\-config <file>\fR
.RS 4
The pacman config file to use\&.
@ -257,6 +263,14 @@ passed to makepkg. Multiple arguments may be passed by supplying a space
separated list that is quoted by the shell.
.RE
.PP
\fB\-\-gpgflags <flags>\fR
.RS 4
Passes arguments to gpg\&. These flags get passed to every instance where
gpg is called by Yay. Arguments are split on whitespace before being
passed to gpg. Multiple arguments may be passed by supplying a space
separated list that is quoted by the shell.
.RE
.PP
\fB\-\-sudoloop\fR
.RS 4
Loop sudo calls in the background to prevent sudo from timing out during long