Check qpdf is available before starting

This commit is contained in:
Dan Church 2023-04-21 10:50:16 -05:00
parent 7da19cfaf3
commit 44308e890f
Signed by: h3xx
GPG key ID: EA2BF379CD2CDBD0

19
optipdf
View file

@ -105,6 +105,22 @@ if [[ ${#FILES[@]} -eq 0 ]]; then
exit 2 exit 2
fi fi
check_required_binaries() {
local BIN MISSING=()
for BIN; do
if ! type -t "$BIN" &>/dev/null; then
MISSING+=("$BIN")
fi
done
if [[ ${#MISSING[@]} -gt 0 ]]; then
printf 'Error: You are missing required programs:\n' >&2
for BIN in "${MISSING[@]}"; do
printf -- '- %s\n' "$BIN" >&2
done
exit 2
fi
}
file_size() { file_size() {
stat \ stat \
--format='%s' \ --format='%s' \
@ -200,6 +216,9 @@ use_smaller() {
} }
check_required_binaries \
qpdf
QPDF_ARGS=( QPDF_ARGS=(
--compression-level=9 --compression-level=9
--deterministic-id --deterministic-id