Add --install-missing-tools argument and do not install missing deps automatically

The script previously attempted to install missing deps using sudo
automatically, which does not seem to be a good practice, as installing
sw should be a deliberate action of a human. If it is necessary to do it
automatically in some CI, there is a new argument --install-missing-tools=on
for that.

This change also determines expected wget package name, as it is actually
called wget2-wget starting Fedora 40 and RHEL 10, which means the detection
using rpm -q might not work when asking for wget only, and it ran dnf
unnecessarily.
This commit is contained in:
Honza Horak 2024-07-24 10:47:40 +02:00
parent 0153cd57e3
commit a0d8469788

View File

@ -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' "<version>: 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