aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkitsunyan2018-04-08 21:37:38 +0000
committerkitsunyan2018-04-08 21:37:38 +0000
commite1064498261c6a95d18ab79579ecdacdbbf44d55 (patch)
tree49c09a6faca895255d334f6d6baa06365e52d514 /src
parent72b8161f2f37a0a6b091e300810a40e9a775c64b (diff)
Allow to automatically exec pakku via sudo
Diffstat (limited to 'src')
-rw-r--r--src/config.nim4
-rw-r--r--src/main.nim81
2 files changed, 46 insertions, 39 deletions
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"),