aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitsunyan2018-03-18 21:37:57 +0000
committerkitsunyan2018-03-18 21:37:57 +0000
commitf0f1a5cd5e0f32f464c9bbef18e0f28d7119964e (patch)
tree8cf103b2a54bb646a156103acfedf050a15b845b
parent471650128626145a3f45c543eecb6e5be4f273dd (diff)
Use keyserver from ${gpgdir}/gpg.conf by default
-rw-r--r--src/config.nim6
-rw-r--r--src/feature/syncinstall.nim10
-rw-r--r--src/pacman.nim34
-rw-r--r--src/utils.nim1
4 files changed, 40 insertions, 11 deletions
diff --git a/src/config.nim b/src/config.nim
index abcf376..42b9b70 100644
--- a/src/config.nim
+++ b/src/config.nim
@@ -14,12 +14,14 @@ type
debug*: bool
progressBar*: bool
verbosePkgList*: bool
+ pgpKeyserver*: Option[string]
ignorePkgs*: HashSet[string]
ignoreGroups*: HashSet[string]
PacmanConfig* = object of CommonConfig
rootOption*: Option[string]
dbOption*: Option[string]
+ gpgOption*: Option[string]
colorMode*: ColorMode
Config* = object of CommonConfig
@@ -118,8 +120,8 @@ proc obtainConfig*(config: PacmanConfig): Config =
let viewNoDefault = options.hasKey("ViewNoDefault")
Config(root: root, db: db, tmpRoot: tmpRoot, color: color,
- dbs: config.dbs, arch: config.arch, debug: config.debug,
- progressBar: config.progressBar, verbosePkgList: config.verbosePkgList,
+ dbs: config.dbs, arch: config.arch, debug: config.debug, progressBar: config.progressBar,
+ verbosePkgList: config.verbosePkgList, pgpKeyserver: config.pgpKeyserver,
ignorePkgs: config.ignoreGroups, ignoreGroups: config.ignoreGroups,
aurComments: aurComments, checkIgnored: checkIgnored,
printAurNotFound: printAurNotFound, viewNoDefault: viewNoDefault)
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index e0dd2a2..87b445c 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -595,8 +595,14 @@ proc handleInstall(args: seq[Argument], config: Config, upgradeCount: int,
('a', tr"abort operation"))
keysLoop(index, newSkipKeys)
elif res == 'y' or newSkipKeys:
- let importCode = forkWait(() => execResult(gpgCmd,
- "--recv-keys", pgpKeys[index]))
+ let importCode = if config.pgpKeyserver.isSome:
+ forkWait(() => execResult(gpgCmd,
+ "--keyserver", config.pgpKeyserver.unsafeGet,
+ "--recv-keys", pgpKeys[index]))
+ else:
+ forkWait(() => execResult(gpgCmd,
+ "--recv-keys", pgpKeys[index]))
+
if importCode == 0 or newSkipKeys or noconfirm:
keysLoop(index + 1, newSkipKeys)
else:
diff --git a/src/pacman.nim b/src/pacman.nim
index c457f49..37dbd57 100644
--- a/src/pacman.nim
+++ b/src/pacman.nim
@@ -304,6 +304,7 @@ proc getMachineName: Option[string] =
proc createConfigFromTable(table: Table[string, string], dbs: seq[string]): PacmanConfig =
let root = table.opt("RootDir")
let db = table.opt("DBPath")
+ let gpg = table.opt("GPGDir")
let color = if table.hasKey("Color"): ColorMode.colorAuto else: ColorMode.colorNever
let verbosePkgList = table.hasKey("VerbosePkgLists")
let arch = table.opt("Architecture").get("auto")
@@ -315,10 +316,9 @@ proc createConfigFromTable(table: Table[string, string], dbs: seq[string]): Pacm
raise commandError(tr"can not get the architecture",
colorNeeded = some(color.get))
- PacmanConfig(rootOption: root, dbOption: db, dbs: dbs,
- arch: archFinal, colorMode: color, debug: false,
- progressBar: true, verbosePkgList: verbosePkgList,
- ignorePkgs: ignorePkgs, ignoreGroups: ignoreGroups)
+ PacmanConfig(rootOption: root, dbOption: db, gpgOption: gpg, dbs: dbs, arch: archFinal,
+ colorMode: color, debug: false, progressBar: true, verbosePkgList: verbosePkgList,
+ pgpKeyserver: none(string), ignorePkgs: ignorePkgs, ignoreGroups: ignoreGroups)
proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
proc getAll(pair: OptionPair): seq[string] =
@@ -340,6 +340,7 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
let root = getAll((some("r"), "root")).optLast.orElse(defaultConfig.rootOption)
let db = getAll((some("b"), "dbpath")).optLast.orElse(defaultConfig.dbOption)
+ let gpg = getAll((none(string), "gpgdir")).optLast.orElse(defaultConfig.gpgOption)
let arch = getAll((none(string), "arch")).optLast.get(defaultConfig.arch)
let colorStr = getAll((none(string), "color")).optLast.get($defaultConfig.colorMode)
let color = getColor(colorStr)
@@ -349,10 +350,29 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
let ignorePkgs = getAll((none(string), "ignore")).toSet
let ignoreGroups = getAll((none(string), "ignoregroups")).toSet
- let config = PacmanConfig(rootOption: root, dbOption: db, dbs: defaultConfig.dbs,
- arch: arch, colorMode: color, debug: debug,
+ let hasKeyserver = runProgram(gpgConfCmd, "--list-options", "gpg")
+ .filter(s => s.len > 10 and s[0 .. 9] == "keyserver:" and not (s[^2] == ':'))
+ .len > 0
+
+ let pgpKeyserver = if hasKeyserver:
+ none(string)
+ else: (block:
+ var pgpKeyserver = none(string)
+ var file: File
+ if file.open(gpg.get(sysConfDir & "/pacman.d/gnupg") & "/gpg.conf"):
+ try:
+ while true:
+ let line = file.readLine()
+ if line.len > 10 and line[0 .. 9] == "keyserver ":
+ pgpKeyserver = some(line[9 .. ^1].strip)
+ except:
+ discard
+ pgpKeyserver)
+
+ let config = PacmanConfig(rootOption: root, dbOption: db, gpgOption: gpg,
+ dbs: defaultConfig.dbs, arch: arch, colorMode: color, debug: debug,
progressBar: progressBar, verbosePkgList: defaultConfig.verbosePkgList,
- ignorePkgs: ignorePkgs + defaultConfig.ignorePkgs,
+ pgpKeyserver: pgpKeyserver, ignorePkgs: ignorePkgs + defaultConfig.ignorePkgs,
ignoreGroups: ignoreGroups + defaultConfig.ignoreGroups)
if config.dbs.find("aur") >= 0:
diff --git a/src/utils.nim b/src/utils.nim
index afcb1a3..986a4a0 100644
--- a/src/utils.nim
+++ b/src/utils.nim
@@ -19,6 +19,7 @@ const
sudoCmd* = "/usr/bin/sudo"
gitCmd* = "/usr/bin/git"
gpgCmd* = "/usr/bin/gpg"
+ gpgConfCmd* = "/usr/bin/gpgconf"
pacmanCmd* = "/usr/bin/pacman"
makepkgCmd* = "/usr/bin/makepkg"