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