mirror of
https://github.com/moparisthebest/pacman
synced 2024-10-31 15:45:03 -04:00
pacman-db-upgrade: use pacman-style options
* convert dbpath from argument to option * add --config and --root options * read dbpath and root from config file * if root is set but not dbpath, dbpath is set relative to root Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
8bf2c753f5
commit
e4773b1b82
@ -54,6 +54,7 @@ endif
|
|||||||
|
|
||||||
#### Taken from the autoconf scripts Makefile.am ####
|
#### Taken from the autoconf scripts Makefile.am ####
|
||||||
edit = sed \
|
edit = sed \
|
||||||
|
-e 's|@rootdir[@]|$(ROOTDIR)|g' \
|
||||||
-e 's|@localedir[@]|$(localedir)|g' \
|
-e 's|@localedir[@]|$(localedir)|g' \
|
||||||
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
|
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
|
||||||
-e 's|@localstatedir[@]|$(localstatedir)|g' \
|
-e 's|@localstatedir[@]|$(localstatedir)|g' \
|
||||||
|
@ -25,19 +25,25 @@ export TEXTDOMAINDIR='@localedir@'
|
|||||||
|
|
||||||
declare -r myver='@PACKAGE_VERSION@'
|
declare -r myver='@PACKAGE_VERSION@'
|
||||||
|
|
||||||
eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
|
|
||||||
dbroot="${DBPath:-@localstatedir@/lib/pacman/}"
|
|
||||||
|
|
||||||
USE_COLOR='y'
|
|
||||||
|
|
||||||
m4_include(library/output_format.sh)
|
m4_include(library/output_format.sh)
|
||||||
|
|
||||||
|
m4_include(library/parseopts.sh)
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "pacman-db-upgrade (pacman) %s\n" "${myver}"
|
printf "pacman-db-upgrade (pacman) %s\n" "${myver}"
|
||||||
echo
|
echo
|
||||||
printf -- "$(gettext "Upgrade the local pacman database to a newer format")\n"
|
printf -- "$(gettext "Upgrade the local pacman database to a newer format")\n"
|
||||||
echo
|
echo
|
||||||
printf -- "$(gettext "Usage: %s [--nocolor] [pacman_db_root]")\n" "$0"
|
printf -- "$(gettext "Usage: %s [options]")\n" "$0"
|
||||||
|
echo
|
||||||
|
printf -- "$(gettext "options:")\n"
|
||||||
|
printf -- "$(gettext " -b, --dbpath <path> set an alternate database location")\n"
|
||||||
|
printf -- "$(gettext " -h, --help show this help message and exit")\n"
|
||||||
|
printf -- "$(gettext " -r, --root <path> set an alternate installation root")\n"
|
||||||
|
printf -- "$(gettext " -V, --version show version information and exit")\n"
|
||||||
|
printf -- "$(gettext " --config <path> set an alternate configuration file")\n"
|
||||||
|
printf -- "$(gettext " --nocolor disable colorized output messages")\n"
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
version() {
|
version() {
|
||||||
@ -58,6 +64,18 @@ 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"
|
||||||
|
}
|
||||||
|
|
||||||
# PROGRAM START
|
# PROGRAM START
|
||||||
|
|
||||||
# determine whether we have gettext; make it a no-op if we do not
|
# determine whether we have gettext; make it a no-op if we do not
|
||||||
@ -67,27 +85,40 @@ if ! type gettext &>/dev/null; then
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 = "-h" || $1 = "--help" ]]; then
|
USE_COLOR='y'
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $1 = "-V" || $1 = "--version" ]]; then
|
OPT_SHORT="d:hr:V"
|
||||||
version
|
OPT_LONG=('confg' 'dbpath:' 'help' 'nocolor' 'root:' 'version')
|
||||||
exit 0
|
if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
|
||||||
|
exit 1 # E_INVALID_OPTION
|
||||||
fi
|
fi
|
||||||
|
set -- "${OPTRET[@]}"
|
||||||
|
unset OPT_SHORT OPT_LONG OPTRET
|
||||||
|
|
||||||
if [[ $1 = "--nocolor" ]]; then
|
while true; do
|
||||||
USE_COLOR='n'
|
case "$1" in
|
||||||
|
--config) shift; conffile="$1" ;;
|
||||||
|
-d|--dbpath) shift; dbroot="$1" ;;
|
||||||
|
-r|--root) shift; pacroot="$1" ;;
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
--nocolor) USE_COLOR='n' ;;
|
||||||
|
-V|--version) version; exit 0 ;;
|
||||||
|
-- ) shift; break 2 ;;
|
||||||
|
esac
|
||||||
shift
|
shift
|
||||||
fi
|
done
|
||||||
|
|
||||||
|
conffile=${conffile:-@sysconfdir@/pacman.conf}
|
||||||
|
[[ -z $pacroot ]] && pacroot="$(get_opt_from_config "RootDir" "$conffile")"
|
||||||
|
[[ -z $dbroot ]] && dbroot="$(get_opt_from_config "DBPath" "$conffile")"
|
||||||
|
|
||||||
|
[[ -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)
|
||||||
|
|
||||||
if [[ -n $1 ]]; then
|
|
||||||
dbroot="$1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -d $dbroot ]]; then
|
if [[ ! -d $dbroot ]]; then
|
||||||
die "$(gettext "%s does not exist or is not a directory.")" "$dbroot"
|
die "$(gettext "%s does not exist or is not a directory.")" "$dbroot"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user