From: Lukas Schauer Date: Tue, 28 Apr 2020 19:25:08 +0000 (+0200) Subject: reworked dependency check and moved it up a bit in code (fixes #715, resolves #717... X-Git-Tag: v0.7.0~44 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a07c8d14f62c3b32e4f9e963dabc0691f55fcde6;p=thirdparty%2Fdehydrated.git reworked dependency check and moved it up a bit in code (fixes #715, resolves #717 again...) --- diff --git a/dehydrated b/dehydrated index fe00b3e..e865e71 100755 --- a/dehydrated +++ b/dehydrated @@ -39,23 +39,20 @@ _mktemp() { # Check for script dependencies check_dependencies() { - # just execute some dummy and/or version commands to see if required tools exist and are actually usable + # look for required binaries + for binary in grep mktemp diff sed awk curl cut; do + bin_path="$(command -v "${binary}" 2>/dev/null)" || _exiterr "This script requires ${binary}." + [[ -x "${bin_path}" ]] || _exiterr "${binary} found in PATH but it's not executable" + done + + # just execute some dummy and/or version commands to see if required tools are actually usable "${OPENSSL}" version > /dev/null 2>&1 || _exiterr "This script requires an openssl binary." _sed "" < /dev/null > /dev/null 2>&1 || _exiterr "This script requires sed with support for extended (modern) regular expressions." - command -v grep > /dev/null 2>&1 || _exiterr "This script requires grep." - command -v mktemp > /dev/null 2>&1 || _exiterr "This script requires mktemp." - command -v diff > /dev/null 2>&1 || _exiterr "This script requires diff." # curl returns with an error code in some ancient versions so we have to catch that - # storing raw version output temporarily to catch curl error instead of head/awk exit codes set +e - raw_curl_version="$(curl -V 2>&1)" - retcode="$?" + CURL_VERSION="$(curl -V 2>&1 | head -n1 | awk '{print $2}')" set -e - if [[ ! "${retcode}" = "0" ]] && [[ ! "${retcode}" = "2" ]]; then - _exiterr "This script requires curl." - fi - CURL_VERSION="$(head -n1 <<< "${raw_curl_version}" | awk '{print $2}')" } store_configvars() { @@ -192,6 +189,9 @@ load_config() { [[ -n "${ZSH_VERSION:-}" ]] && set -o noglob || set -f fi + # Check for missing dependencies + check_dependencies + # Check if we are running & are allowed to run as root if [[ -n "$DEHYDRATED_USER" ]]; then command -v sudo > /dev/null 2>&1 || _exiterr "DEHYDRATED_USER set but sudo not available. Please install sudo." @@ -218,9 +218,6 @@ load_config() { _exiterr "DEHYDRATED_GROUP can only be used in combination with DEHYDRATED_USER." fi - # Check for missing dependencies - check_dependencies - # Remove slash from end of BASEDIR. Mostly for cleaner outputs, doesn't change functionality. [[ "$BASEDIR" != "/" ]] && BASEDIR="${BASEDIR%%/}"