better missing package handling
This commit is contained in:
parent
993934ea2e
commit
427a13fd32
|
@ -1,16 +1,16 @@
|
|||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iQIzBAABCgAdFiEEZ1U/vaRrtxq9LgsLjkeh7DWhVR0FAl+vC2EACgkQjkeh7DWh
|
||||
VR3B2BAAsJ8v5t+9jzTljECYmpkvepZB2zquAX+U9e9OhPOTuSueI8vOI/1Ywu6I
|
||||
Vsix5eXWUozEU4Dc4KldX1Eryqbb5euI/JHrLYpiQrtfoudnbQNZLP+vWadiepBG
|
||||
Q9VFBWlZRVvcJ5elJk/1Qk1+Ufxu2grp7pWCU9616ii79f3f0lHknMexcvnbGr/s
|
||||
WSCtdhFDApRqcFfwpBX1wvpamClOAwAj+6MoG7CqCxHeMLmOVeKlMGiCLiwor9K9
|
||||
eAj1D2tovdMBBYT8gvwLVSnRZS5Yl1cEE6ewVxA2Pqnhc4M71SRKa2gEaKVT+LyL
|
||||
hJ8JOYiKrX+sxdvf9N3IewgxgDgAViMSBitQ+EguEiJTCwtGZKmAp1LRMqzC16pW
|
||||
Ike+uMTj1LWhe7zGWlsqG1kLR7mDrqXWYraj70A/siAghkPB1Bj7MINI4v8K8dN/
|
||||
z3oPJYYme2qno5vWtoPFVBY+P/n/MbQRJl3Va9VVU6vkHn3xz32F2Td60TA4Fkqg
|
||||
irmK+WNWDwtksAcI9pAlegCi60k2fH1AJppC2vPGSS9fqw6lm/+zBKkBJpOiOxAj
|
||||
nb1jq16lIugVus7eMmoJ/DNpSlSBCcUwKou9Ns4EuXTdXWKfklLKzcfD3y+UMAm7
|
||||
I84Ns0GkCmdQQg4uqoBIRX8Q7Wi6tx3hL9y4q3GFvOSJBPd8jzs=
|
||||
=3lXa
|
||||
iQIzBAABCgAdFiEEZ1U/vaRrtxq9LgsLjkeh7DWhVR0FAl+vL3cACgkQjkeh7DWh
|
||||
VR3pXg//edF6tpvIaIcVhe72Wg/NOnz277brPdFnpnZTi9kZOanrPilyMJ5ahTVP
|
||||
Au+Z/3LX470ewUTpN9DP1ou5yEMyHYE6nq2UDVhmrmxz5WnydqfibuTX1gmIj1RP
|
||||
xctTus0Q9KIA2YOyEa5LQ30DyKzNb3uMbhEbu/Px1FciuvQTP2kzusUEgLI2HBPJ
|
||||
fH05M6W2ppYslHZDRf3lc1D6z72f4IpwedkHHq/8ilbIWwmasayYDqr1Smddnz7i
|
||||
e/ysFhDq3C3/tljS0IxS1U7r3O7NqL49bBixTg/fPo2iTH/3GgnBuYQoDxxMXlRV
|
||||
fTT7xhlAfK3PewYwIjPBx14TCe+omU95okhbwBWVw5Zh8KxRlWdjS0X0zrZW21JQ
|
||||
RJeCEmH0QJKur9CzD86AXkDj9GSIQDdaVaD4w5f+BRaboroxRF+n3yhRaDYdVbYf
|
||||
Uqwn09NyNV8GrGjQMTBaDaMiXvdrvScPRQcJkL54gwzCsrzpl8Bvj8eX9ESH5tw6
|
||||
b8xCY6YMn8SwivC2DlDXB6q9DU7i41xinupMoivyBLkR7G69tZL/n7pc0syjj9UH
|
||||
v1HyyGG6sski1/8cTvi3Q+Oo6kx7OGLZ8K3rpmORYkT+m3SxTYQgFwLHoubO4c7Q
|
||||
J5rlMmWM3n8E1fcx4Cri0jI+1IZGS7FSFQxzo7x4U3s3yGbLmPI=
|
||||
=n932
|
||||
-----END PGP SIGNATURE-----
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
64263feac7b00952e9ec3b6c1fd11316faa58ff673c6bd085fac9f6f8d8389f6 .gitignore
|
||||
e659c0fc9b60694b31b13939d2dd36b97be56dc1d781ba8b352c466456e57a21 sig
|
||||
e008111dff82be23ab7999b0938e9fffb2fd4826d99f87ed5d0a70256fd43908 sig
|
||||
|
|
80
sig
80
sig
|
@ -4,24 +4,52 @@ set -e
|
|||
MIN_BASH_VERSION=4
|
||||
MIN_GPG_VERSION=2.2
|
||||
MIN_OPENSSL_VERSION=1.1
|
||||
MIN_GETOPT_VERSION=2.33
|
||||
|
||||
die() {
|
||||
echo "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
die_pkg() {
|
||||
local package=${1?}
|
||||
local version=${2?}
|
||||
local install_cmd
|
||||
case "$OSTYPE" in
|
||||
linux*)
|
||||
if command -v "apt" >/dev/null; then
|
||||
install_cmd="apt install ${package}"
|
||||
elif command -v "yum" >/dev/null; then
|
||||
install_cmd="yum install ${package}"
|
||||
elif command -v "pacman" >/dev/null; then
|
||||
install_cmd="pacman -Ss ${package}"
|
||||
elif command -v "nix-env" >/dev/null; then
|
||||
install_cmd="nix-env -i ${package}"
|
||||
fi
|
||||
;;
|
||||
bsd*) install_cmd="pkg install ${package}" ;;
|
||||
darwin*) install_cmd="port install ${package}" ;;
|
||||
*) die "Error: Your operating system is not supported" ;;
|
||||
esac
|
||||
echo "Error: ${package} ${version}+ does not appear to be installed." >&2
|
||||
[ ! -z "$install_cmd" ] && printf "Try: \`${install_cmd}\`" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_version(){
|
||||
[[ $2 == $3 ]] && return 0
|
||||
local pkg="${1?}"
|
||||
local have="${2?}"
|
||||
local need="${3?}"
|
||||
[[ "$have" == "$need" ]] && return 0
|
||||
local IFS=.
|
||||
local i ver1=($2) ver2=($3)
|
||||
local i ver1=($have) ver2=($need)
|
||||
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++));
|
||||
do ver1[i]=0;
|
||||
done
|
||||
for ((i=0; i<${#ver1[@]}; i++)); do
|
||||
[[ -z ${ver2[i]} ]] && ver2[i]=0
|
||||
((10#${ver1[i]} > 10#${ver2[i]})) && return 0
|
||||
((10#${ver1[i]} < 10#${ver2[i]})) && die \
|
||||
"Error: ${1} ${3}+ not found"
|
||||
((10#${ver1[i]} < 10#${ver2[i]})) && die_pkg "${pkg}" "${need}"
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -29,19 +57,23 @@ check_tools(){
|
|||
if [ -z "${BASH_VERSINFO}" ] \
|
||||
|| [ -z "${BASH_VERSINFO[0]}" ] \
|
||||
|| [ ${BASH_VERSINFO[0]} -lt ${MIN_BASH_VERSION} ]; then
|
||||
die "Error: bash ${MIN_BASH_VERSION}+ not found";
|
||||
die_pkg "bash" "${MIN_BASH_VERSION}"
|
||||
fi
|
||||
for cmd in "$@"; do
|
||||
command -v "$1" >/dev/null || die "Error: $cmd not found"
|
||||
case $cmd in
|
||||
gpg)
|
||||
version=$(gpg --version | head -n1 | cut -d" " -f3)
|
||||
check_version "gpg" "${version}" "${MIN_GPG_VERSION}"
|
||||
check_version "gnupg" "${version}" "${MIN_GPG_VERSION}"
|
||||
;;
|
||||
openssl)
|
||||
version=$(openssl version | cut -d" " -f2 | sed 's/[a-z]//g')
|
||||
check_version "openssl" "${version}" "${MIN_OPENSSL_VERSION}"
|
||||
;;
|
||||
getopt)
|
||||
version=$(getopt --version | cut -d" " -f4 | sed 's/[a-z]//g')
|
||||
check_version "getopt" "${version}" "${MIN_GETOPT_VERSION}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
@ -69,17 +101,8 @@ get_files(){
|
|||
fi
|
||||
}
|
||||
|
||||
cmd_manifest() {
|
||||
mkdir -p ".${PROGRAM}"
|
||||
printf "$(get_files | xargs openssl sha256 -r)" \
|
||||
| sed -e 's/ \*/ /g' -e 's/ \.\// /g' \
|
||||
| LC_ALL=C sort -k2 \
|
||||
> ".${PROGRAM}/manifest.txt"
|
||||
}
|
||||
|
||||
verify_file() {
|
||||
[ $# -eq 3 ] || die \
|
||||
"Usage: verify_file <threshold> <group> <file>"
|
||||
[ $# -eq 3 ] || die "Usage: verify_file <threshold> <group> <file>"
|
||||
local threshold="${1}"
|
||||
local group="${2}"
|
||||
local filename="${3}"
|
||||
|
@ -130,6 +153,14 @@ verify_file() {
|
|||
}
|
||||
}
|
||||
|
||||
cmd_manifest() {
|
||||
mkdir -p ".${PROGRAM}"
|
||||
printf "$(get_files | xargs openssl sha256 -r)" \
|
||||
| sed -e 's/ \*/ /g' -e 's/ \.\// /g' \
|
||||
| LC_ALL=C sort -k2 \
|
||||
> ".${PROGRAM}/manifest.txt"
|
||||
}
|
||||
|
||||
cmd_verify() {
|
||||
local opts selected_line min=1 group=""
|
||||
opts="$(getopt -o m:g: -l min:,group: -n "$PROGRAM" -- "$@")"
|
||||
|
@ -189,17 +220,14 @@ cmd_usage() {
|
|||
_EOF
|
||||
}
|
||||
|
||||
check_tools head cut find sort sed gpg openssl getopt
|
||||
check_tools head cut find sort sed getopt gpg openssl
|
||||
|
||||
PROGRAM="${0##*/}"
|
||||
COMMAND="$1"
|
||||
|
||||
case "$1" in
|
||||
verify) shift; cmd_verify "$@" ;;
|
||||
add) shift; cmd_add "$@" ;;
|
||||
manifest) shift; cmd_manifest "$@" ;;
|
||||
version|--version) shift; cmd_version "$@" ;;
|
||||
help|--help) shift; cmd_usage "$@" ;;
|
||||
*) cmd_usage "$@" ;;
|
||||
verify) shift; cmd_verify "$@" ;;
|
||||
add) shift; cmd_add "$@" ;;
|
||||
manifest) shift; cmd_manifest "$@" ;;
|
||||
version|--version) shift; cmd_version "$@" ;;
|
||||
help|--help) shift; cmd_usage "$@" ;;
|
||||
*) cmd_usage "$@" ;;
|
||||
esac
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue