Add automatic whiptail installation and error notices for missing software dependencies #8

This commit modifies the script to automatically install 'whiptail' on Linux, macOS, and Windows if it's not already installed. It also adds error notices instructing the user to install other software dependencies if they're missing. This makes the script more user-friendly and reduces the likelihood of script failure due to missing dependencies.
This commit is contained in:
Llewellyn van der Merwe 2024-06-01 15:15:42 +02:00
parent e627e7f4cd
commit 1a83002c9d
Signed by: Llewellyn
GPG Key ID: A9201372263741E7

View File

@ -18,6 +18,12 @@ BACK_TITLE=" Octoleo | ${USER}@${SERVER_HOSTNAME}"
#####################################################################################################################VDM #####################################################################################################################VDM
######################################## The environment preparation ######################################## The environment preparation
# make sure curl is installed
command -v curl >/dev/null 2>&1 || {
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require curl."
echo >&2 "NOTICE: Please install curl first and then re-run this script again."
exit 1
}
# Set OS number # Set OS number
OS_NUMBER=0 # Unknown OS_NUMBER=0 # Unknown
if [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then
@ -42,19 +48,60 @@ function check_bash_version() {
} }
# Check for the appropriate version of Bash # Check for the appropriate version of Bash
check_bash_version "$_bash_v" check_bash_version "$_bash_v"
# make sure whiptail is installed # Install whiptail on Ubuntu
command -v whiptail >/dev/null 2>&1 || { function install_whiptail_linux() {
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require whiptail." sudo apt-get update
exit 1 sudo apt-get install whiptail -y
} }
# make sure curl is installed # Install whiptail on macOS
command -v curl >/dev/null 2>&1 || { function install_whiptail_macos() {
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require curl." if ! command -v brew >/dev/null 2>&1; then
exit 1 echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require Homebrew to install whiptail on macOS."
echo >&2 "NOTICE: Please install Homebrew first and then re-run this script."
exit 1
fi
brew install newt
} }
# Install whiptail on Windows using Chocolatey
function install_whiptail_windows() {
if ! command -v choco >/dev/null 2>&1; then
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require Chocolatey to install whiptail on Windows."
echo >&2 "NOTICE: Please install Chocolatey first and then re-run this script."
exit 1
fi
choco install newt
}
# Main script
if ! command -v whiptail >/dev/null 2>&1; then
echo "Whiptail is not installed. Do you want to install it now? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
# If the user chooses Yes, install Docker based on the OS
case "$OS_NUMBER" in
1)
install_whiptail_linux
;;
2)
install_whiptail_macos
;;
3)
install_whiptail_windows
;;
*)
echo >&2 "ERROR: Unsupported operating system."
exit 1
;;
esac
else
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require whiptail."
echo >&2 "NOTICE: Please install whiptail first and then re-run this script again."
exit 1
fi
fi
# make sure awk is installed # make sure awk is installed
command -v awk >/dev/null 2>&1 || { command -v awk >/dev/null 2>&1 || {
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require awk." echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script require awk."
echo >&2 "NOTICE: Please install awk first and then re-run this script again."
exit 1 exit 1
} }
# make sure rsync is installed (hmmm not always) # make sure rsync is installed (hmmm not always)
@ -116,6 +163,7 @@ if ! command -v docker &>/dev/null; then
else else
# If the user chooses No, exit the script with an error message # If the user chooses No, exit the script with an error message
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script requires Docker." echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script requires Docker."
echo >&2 "NOTICE: Please install Docker first and then re-run this script again."
exit 1 exit 1
fi fi
fi fi
@ -171,6 +219,7 @@ if ! command -v docker-compose &>/dev/null; then
else else
# If the user chooses No, exit the script with an error message # If the user chooses No, exit the script with an error message
echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script requires docker-compose." echo >&2 "ERROR: ${PROGRAM_NAME} v${_VERSION} script requires docker-compose."
echo >&2 "NOTICE: Please install docker-compose first and then re-run this script again."
exit 1 exit 1
fi fi
fi fi