repo-add: unify checking gpg keys
Move the PGP key checking into the check_gpg function. This also results in error messages being in colour. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
cf3d5e4830
commit
3c46420367
1 changed files with 17 additions and 15 deletions
|
@ -34,6 +34,7 @@ ONLYADDNEW=0
|
||||||
RMEXISTING=0
|
RMEXISTING=0
|
||||||
WITHFILES=0
|
WITHFILES=0
|
||||||
SIGN=0
|
SIGN=0
|
||||||
|
KEY=0
|
||||||
VERIFY=0
|
VERIFY=0
|
||||||
REPO_DB_FILE=
|
REPO_DB_FILE=
|
||||||
LOCKFILE=
|
LOCKFILE=
|
||||||
|
@ -198,6 +199,17 @@ check_gpg() {
|
||||||
error "$(gettext "Cannot find the gpg binary! Is GnuPG installed?")"
|
error "$(gettext "Cannot find the gpg binary! Is GnuPG installed?")"
|
||||||
exit 1 # $E_MISSING_PROGRAM
|
exit 1 # $E_MISSING_PROGRAM
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if (( ! VERIFY )); then
|
||||||
|
if ! gpg --list-key ${GPGKEY} &>/dev/null; then
|
||||||
|
if [[ ! -z $GPGKEY ]]; then
|
||||||
|
error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
|
||||||
|
elif (( ! KEY )); then
|
||||||
|
error "$(gettext "There is no key in your keyring.")"
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# sign the package database once repackaged
|
# sign the package database once repackaged
|
||||||
|
@ -630,28 +642,14 @@ while (( $# )); do
|
||||||
-f|--files) WITHFILES=1;;
|
-f|--files) WITHFILES=1;;
|
||||||
--nocolor) USE_COLOR='n';;
|
--nocolor) USE_COLOR='n';;
|
||||||
-s|--sign)
|
-s|--sign)
|
||||||
check_gpg
|
|
||||||
SIGN=1
|
SIGN=1
|
||||||
if ! gpg --list-key ${GPGKEY} &>/dev/null; then
|
|
||||||
if [[ ! -z $GPGKEY ]]; then
|
|
||||||
error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
|
|
||||||
else
|
|
||||||
error "$(gettext "There is no key in your keyring.")"
|
|
||||||
fi
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
-k|--key)
|
-k|--key)
|
||||||
check_gpg
|
KEY=1
|
||||||
shift
|
shift
|
||||||
GPGKEY=$1
|
GPGKEY=$1
|
||||||
if ! gpg --list-key ${GPGKEY} &>/dev/null; then
|
|
||||||
error "$(gettext "The key ${GPGKEY} does not exist in your keyring.")"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
-v|--verify)
|
-v|--verify)
|
||||||
check_gpg
|
|
||||||
VERIFY=1
|
VERIFY=1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -678,6 +676,10 @@ fi
|
||||||
verify_repo_extension "$REPO_DB_FILE" >/dev/null
|
verify_repo_extension "$REPO_DB_FILE" >/dev/null
|
||||||
check_repo_db
|
check_repo_db
|
||||||
|
|
||||||
|
if (( SIGN || KEY || VERIFY )); then
|
||||||
|
check_gpg
|
||||||
|
fi
|
||||||
|
|
||||||
for arg in "${args[@]:1}"; do
|
for arg in "${args[@]:1}"; do
|
||||||
case $cmd in
|
case $cmd in
|
||||||
repo-add) add "$arg" ;;
|
repo-add) add "$arg" ;;
|
||||||
|
|
Loading…
Add table
Reference in a new issue