use pacman-conf in scripts
Because parsing pacman.conf is so difficult that even we can't do it right. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
170bb80a1f
commit
d9eda13fc6
3 changed files with 5 additions and 22 deletions
|
@ -316,7 +316,7 @@ _pacman_completions_all_packages() {
|
||||||
typeset -U packages
|
typeset -U packages
|
||||||
${seq} _wanted packages expl "packages" compadd ${sep[@]} - "${(@)packages}"
|
${seq} _wanted packages expl "packages" compadd ${sep[@]} - "${(@)packages}"
|
||||||
|
|
||||||
repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
|
repositories=($(pacman-conf --repo-list))
|
||||||
typeset -U repositories
|
typeset -U repositories
|
||||||
_wanted repo_packages expl "repository/package" compadd -S "/" $repositories
|
_wanted repo_packages expl "repository/package" compadd -S "/" $repositories
|
||||||
fi
|
fi
|
||||||
|
@ -348,7 +348,7 @@ _pacman_all_packages() {
|
||||||
# provides completions for repository names
|
# provides completions for repository names
|
||||||
_pacman_completions_repositories() {
|
_pacman_completions_repositories() {
|
||||||
local -a cmd repositories
|
local -a cmd repositories
|
||||||
repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
|
repositories=($(pacman-conf --repo-list))
|
||||||
# Uniq the array
|
# Uniq the array
|
||||||
typeset -U repositories
|
typeset -U repositories
|
||||||
compadd "$@" -a repositories
|
compadd "$@" -a repositories
|
||||||
|
|
|
@ -70,18 +70,6 @@ die_r() {
|
||||||
die "$@"
|
die "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_opt_from_config() {
|
|
||||||
local keyname="$1" conffile="$2"
|
|
||||||
local key value
|
|
||||||
|
|
||||||
while IFS=$'= \t' read -r key value _; do
|
|
||||||
if [[ $key = $keyname ]]; then
|
|
||||||
echo "$value"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
done <"$conffile"
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve_dir() {
|
resolve_dir() {
|
||||||
local d="$(cd "$1"; pwd -P)"
|
local d="$(cd "$1"; pwd -P)"
|
||||||
[[ $d == */ ]] || d+=/
|
[[ $d == */ ]] || d+=/
|
||||||
|
@ -121,13 +109,8 @@ while true; do
|
||||||
done
|
done
|
||||||
|
|
||||||
conffile=${conffile:-@sysconfdir@/pacman.conf}
|
conffile=${conffile:-@sysconfdir@/pacman.conf}
|
||||||
[[ -z $pacroot ]] && pacroot="$(get_opt_from_config "RootDir" "$conffile")"
|
[[ -z $pacroot ]] && pacroot=$(pacman-conf --config="$conffile" rootdir)
|
||||||
[[ -z $dbroot ]] && dbroot="$(get_opt_from_config "DBPath" "$conffile")"
|
[[ -z $dbroot ]] && dbroot=$(pacman-conf --config="$conffile" --rootdir="$pacroot" dbpath)
|
||||||
|
|
||||||
[[ -z $dbroot && -n $pacroot ]] && dbroot="$pacroot/@localstatedir@/lib/pacman"
|
|
||||||
|
|
||||||
[[ -z $pacroot ]] && pacroot="@rootdir@"
|
|
||||||
[[ -z $dbroot ]] && dbroot="@localstatedir@/lib/pacman/"
|
|
||||||
|
|
||||||
m4_include(library/term_colors.sh)
|
m4_include(library/term_colors.sh)
|
||||||
|
|
||||||
|
|
|
@ -580,7 +580,7 @@ fi
|
||||||
|
|
||||||
# if PACMAN_KEYRING_DIR isn't assigned, try to get it from the config
|
# if PACMAN_KEYRING_DIR isn't assigned, try to get it from the config
|
||||||
# file, falling back on a hard default
|
# file, falling back on a hard default
|
||||||
PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(get_from "$CONFIG" "GPGDir" "@sysconfdir@/pacman.d/gnupg")}
|
PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(pacman-conf --config="$CONFIG" gpgdir)}
|
||||||
|
|
||||||
GPG_PACMAN=(gpg --homedir "${PACMAN_KEYRING_DIR}" --no-permission-warning)
|
GPG_PACMAN=(gpg --homedir "${PACMAN_KEYRING_DIR}" --no-permission-warning)
|
||||||
if [[ -n ${KEYSERVER} ]]; then
|
if [[ -n ${KEYSERVER} ]]; then
|
||||||
|
|
Loading…
Add table
Reference in a new issue