diff options
-rw-r--r-- | doc/pakku.conf.5.txt | 4 | ||||
-rw-r--r-- | pakku.conf | 1 | ||||
-rw-r--r-- | src/config.nim | 4 | ||||
-rw-r--r-- | src/main.nim | 81 |
4 files changed, 51 insertions, 39 deletions
diff --git a/doc/pakku.conf.5.txt b/doc/pakku.conf.5.txt index 5eda994..9b03b13 100644 --- a/doc/pakku.conf.5.txt +++ b/doc/pakku.conf.5.txt @@ -31,6 +31,10 @@ Options Print warnings during upgrade operation when foreign packages were not found in AUR. +*SudoExec*:: + Automatically exec the program from root via sudo if it is necessary, + allowing you to enter password for sudo only once. + *ViewNoDefault*:: When building from AUR, pakku will ask whether you want to view the content of PKGBUILD and other files. Pressing enter key will give the @@ -6,6 +6,7 @@ AurComments CheckIgnored PrintAurNotFound +#SudoExec #ViewNoDefault #PreBuildCommand = diff --git a/src/config.nim b/src/config.nim index 8b0e0f5..a6f65b9 100644 --- a/src/config.nim +++ b/src/config.nim @@ -32,6 +32,7 @@ type aurComments*: bool checkIgnored*: bool printAurNotFound*: bool + sudoExec*: bool viewNoDefault*: bool preBuildCommand*: Option[string] @@ -118,6 +119,7 @@ proc obtainConfig*(config: PacmanConfig): Config = let aurComments = options.hasKey("AurComments") let checkIgnored = options.hasKey("CheckIgnored") let printAurNotFound = options.hasKey("PrintAurNotFound") + let sudoExec = options.hasKey("SudoExec") let viewNoDefault = options.hasKey("ViewNoDefault") let preBuildCommand = options.opt("PreBuildCommand") @@ -126,4 +128,4 @@ proc obtainConfig*(config: PacmanConfig): Config = verbosePkgList: config.verbosePkgList, pgpKeyserver: config.pgpKeyserver, ignorePkgs: config.ignorePkgs, ignoreGroups: config.ignoreGroups, aurComments: aurComments, checkIgnored: checkIgnored, printAurNotFound: printAurNotFound, - viewNoDefault: viewNoDefault, preBuildCommand: preBuildCommand) + sudoExec: sudoExec, viewNoDefault: viewNoDefault, preBuildCommand: preBuildCommand) diff --git a/src/main.nim b/src/main.nim index 26e2908..be45329 100644 --- a/src/main.nim +++ b/src/main.nim @@ -84,51 +84,56 @@ proc handleSync(args: seq[Argument], config: Config): int = handleSyncSearch(args, config) elif syncArgs.checkOpGroup(OpGroup.syncInstall) and (args.check((some("u"), "sysupgrade")) or args.targets.len > 0): - let isNonDefaultRoot = not config.isRootDefault - let isDowngrade = args.count((some("u"), "sysupgrade")) >= 2 - let isSkipDeps = args.check((some("d"), "nodeps")) - let isRootNoDrop = currentUser.uid == 0 and not canDropPrivileges() - - let build = args.check((none(string), "build")) - let noaur = args.check((none(string), "noaur")) - - let noBuild = isNonDefaultRoot or isDowngrade or isSkipDeps or isRootNoDrop - - if build and noBuild: - if isNonDefaultRoot: - printError(config.color, tr"non-default root path is specified" & " -- " & - tr"building is not allowed") - elif isDowngrade: - printError(config.color, tr"downgrades are enabled" & " -- " & - tr"building is not allowed") - elif isSkipDeps: - printError(config.color, tr"dependency check is skipped" & " -- " & - tr"building is not allowed") - elif isRootNoDrop: - printError(config.color, tr"running as root" & " -- " & - tr"building is not allowed") - 1 + if currentUser.uid != 0 and config.sudoExec: + let collectedArgs = @[sudoCmd, getAppFilename()] & + lc[x | (y <- args, x <- y.collectArg), string] + execResult(collectedArgs) else: - let noaurAdd = noBuild and not noaur + let isNonDefaultRoot = not config.isRootDefault + let isDowngrade = args.count((some("u"), "sysupgrade")) >= 2 + let isSkipDeps = args.check((some("d"), "nodeps")) + let isRootNoDrop = currentUser.uid == 0 and not canDropPrivileges() - if noaurAdd: + let build = args.check((none(string), "build")) + let noaur = args.check((none(string), "noaur")) + + let noBuild = isNonDefaultRoot or isDowngrade or isSkipDeps or isRootNoDrop + + if build and noBuild: if isNonDefaultRoot: - printWarning(config.color, tr"non-default root path is specified" & " -- " & - tr"'$#' is assumed" % ["--noaur"]) + printError(config.color, tr"non-default root path is specified" & " -- " & + tr"building is not allowed") elif isDowngrade: - printWarning(config.color, tr"downgrades are enabled" & " -- " & - tr"'$#' is assumed" % ["--noaur"]) + printError(config.color, tr"downgrades are enabled" & " -- " & + tr"building is not allowed") elif isSkipDeps: - printWarning(config.color, tr"dependency check is skipped" & " -- " & - tr"'$#' is assumed" % ["--noaur"]) + printError(config.color, tr"dependency check is skipped" & " -- " & + tr"building is not allowed") elif isRootNoDrop: - printWarning(config.color, tr"running as root" & " -- " & - tr"'$#' is assumed" % ["--noaur"]) - - if noaurAdd: - handleSyncInstall(args & ("noaur", none(string), ArgumentType.long), config) + printError(config.color, tr"running as root" & " -- " & + tr"building is not allowed") + 1 else: - handleSyncInstall(args, config) + let noaurAdd = noBuild and not noaur + + if noaurAdd: + if isNonDefaultRoot: + printWarning(config.color, tr"non-default root path is specified" & " -- " & + tr"'$#' is assumed" % ["--noaur"]) + elif isDowngrade: + printWarning(config.color, tr"downgrades are enabled" & " -- " & + tr"'$#' is assumed" % ["--noaur"]) + elif isSkipDeps: + printWarning(config.color, tr"dependency check is skipped" & " -- " & + tr"'$#' is assumed" % ["--noaur"]) + elif isRootNoDrop: + printWarning(config.color, tr"running as root" & " -- " & + tr"'$#' is assumed" % ["--noaur"]) + + if noaurAdd: + handleSyncInstall(args & ("noaur", none(string), ArgumentType.long), config) + else: + handleSyncInstall(args, config) else: let nonRootArgs = [ (some("p"), "print"), |