diff --git a/nodejs-sources.sh b/nodejs-sources.sh index c832ca5..37ca2fd 100755 --- a/nodejs-sources.sh +++ b/nodejs-sources.sh @@ -37,6 +37,7 @@ _arg_version= # THE DEFAULTS INITIALIZATION - OPTIONALS _arg_push="on" _arg_debug="off" +_arg_install_missing_tools="off" print_help() @@ -46,6 +47,7 @@ print_help() printf '\t%s\n' ": Node.js release version" printf '\t%s\n' "--push, --no-push: Whether to upload to the lookaside cache (on by default)" printf '\t%s\n' "--debug, --no-debug: Print all commands (off by default)" + printf '\t%s\n' "--install-missing-tools, --no-install-missing-tools: Automatically install missing tools that this script requires (off by default)" printf '\t%s\n' "-h, --help: Prints help" } @@ -65,6 +67,10 @@ parse_commandline() _arg_debug="on" test "${1:0:5}" = "--no-" && _arg_debug="off" ;; + --no-install-missing-tools|--install-missing-tools) + _arg_install_missing_tools="on" + test "${1:0:5}" = "--no-" && _arg_install_missing_tools="off" + ;; -h|--help) print_help exit 0 @@ -123,11 +129,23 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" alias wget='wget --quiet' -packages=("jq" "wget" "tar" "fedpkg" "grep" "sed" "python3-jinja2-cli" "nodejs") +# wget is actually provided by wget2-wget in F40 and RHEL 10 and beyond, +# so let's figure out a correct package name based on the current system +# to not try to find a package that is called differently. Otherwise we +# would try to install a package that is not necessary or available. +wget_name=$( . /etc/os-release ; if [ "${PLATFORM_ID:9:2}" = "f4" ] || [ "${PLATFORM_ID:9:3}" = el1 ] ; then echo wget2-wget ; else echo wget ; fi) + +packages=("jq" "$wget_name" "tar" "fedpkg" "grep" "sed" "python3-jinja2-cli" "nodejs") rpm -q ${packages[@]} >/dev/null if [ $? -ne 0 ]; then - sudo dnf -y install ${packages[@]} + echo "Some of the required tools missing: ${packages[@]}" >&2 + if [ $_arg_install_missing_tools = 'on' ]; then + echo "Installing them automatically" >&2 + sudo dnf -y install ${packages[@]} + else + die "Please, install them manually or specify --install-missing-tools=on argument." + fi fi set -e