Skip to content

Commit

Permalink
Add SudoBin and SudoFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
daftaupe committed Mar 27, 2019
1 parent ec5746f commit 877c794
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Permanent configuration options:
--combinedupgrade Refresh then perform the repo and AUR upgrade together
--nocombinedupgrade Perform the repo upgrade and AUR upgrade separately
--sudo <file> sudo command to use
--sudoflags <flags> Pass arguments to sudo
--sudoloop Loop sudo calls in the background to avoid timeout
--nosudoloop Do not loop sudo calls in the background
Expand Down
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Configuration struct {
SortBy string `json:"sortby"`
GitFlags string `json:"gitflags"`
RemoveMake string `json:"removemake"`
SudoBin string `json:"sudobin"`
SudoFlags string `json:"sudoflags"`
RequestSplitN int `json:"requestsplitn"`
SearchMode int `json:"-"`
SortMode int `json:"sortmode"`
Expand Down Expand Up @@ -161,6 +163,8 @@ func defaultSettings() *Configuration {
TarBin: "bsdtar",
GitBin: "git",
GpgBin: "gpg",
SudoBin: "sudo",
SudoFlags: "",
TimeUpdate: false,
RequestSplitN: 150,
ReDownload: "no",
Expand Down Expand Up @@ -203,6 +207,8 @@ func (config *Configuration) expandEnv() {
config.TarBin = os.ExpandEnv(config.TarBin)
config.GitBin = os.ExpandEnv(config.GitBin)
config.GpgBin = os.ExpandEnv(config.GpgBin)
config.SudoBin = os.ExpandEnv(config.SudoBin)
config.SudoFlags = os.ExpandEnv(config.SudoFlags)
config.ReDownload = os.ExpandEnv(config.ReDownload)
config.ReBuild = os.ExpandEnv(config.ReBuild)
config.AnswerClean = os.ExpandEnv(config.AnswerClean)
Expand Down
13 changes: 13 additions & 0 deletions doc/yay.8
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@ 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.

.TP
.B \-\-sudo <command>
The command to use for \fBsudo\fR calls. This can be a command in
\fBPATH\fR or an absolute path to the file.
The sudoloop is not guarantee to work with a custom \fBsudo\fR command.

.TP
.B \-\-sudoflags <flags>
Passes arguments to sudo. These flags get passed to every instance where
sudo is called by Yay. Arguments are split on whitespace before being
passed to sudo. Multiple arguments may be passed by supplying a space
separated list that is quoted by the shell.

.TP
.B \-\-sudoloop
Loop sudo calls in the background to prevent sudo from timing out during long
Expand Down
4 changes: 2 additions & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func sudoLoop() {

func updateSudo() {
for {
err := show(exec.Command("sudo", "-v"))
err := show(exec.Command(config.SudoBin, "-v"))
if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
Expand Down Expand Up @@ -77,7 +77,7 @@ func passToPacman(args *arguments) *exec.Cmd {
argArr := make([]string, 0)

if args.needRoot() {
argArr = append(argArr, "sudo")
argArr = append(argArr, config.SudoBin, config.SudoFlags)
}

argArr = append(argArr, config.PacmanBin)
Expand Down
8 changes: 8 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ func isArg(arg string) bool {
case "tar":
case "git":
case "gpg":
case "sudo":
case "sudoflags":
case "requestsplitn":
case "sudoloop":
case "nosudoloop":
Expand Down Expand Up @@ -589,6 +591,10 @@ func handleConfig(option, value string) bool {
config.GitBin = value
case "gpg":
config.GpgBin = value
case "sudo":
config.SudoBin = value
case "sudoflags":
config.SudoFlags = value
case "requestsplitn":
n, err := strconv.Atoi(value)
if err == nil && n > 0 {
Expand Down Expand Up @@ -722,6 +728,8 @@ func hasParam(arg string) bool {
case "tar":
case "git":
case "gpg":
case "sudo":
case "sudoflags":
case "requestsplitn":
case "answerclean":
case "answerdiff":
Expand Down

0 comments on commit 877c794

Please sign in to comment.