Introduced staged dependency checks.

This commit is contained in:
Rohan Barar 2024-07-23 17:14:43 +10:00
parent 25a5a1152b
commit 7416c0a750

View File

@ -460,14 +460,11 @@ function waLoadConfig() {
echo -e "${DONE_TEXT}Done!${CLEAR_TEXT}" echo -e "${DONE_TEXT}Done!${CLEAR_TEXT}"
} }
# Name: 'waCheckDependencies' # Name: 'waCheckScriptDependencies'
# Role: Terminate script if dependencies are missing. # Role: Terminate script if dependencies are missing.
function waCheckDependencies() { function waCheckScriptDependencies() {
# Declare variables.
local FREERDP_MAJOR_VERSION="" # Stores the major version of the installed copy of FreeRDP.
# Print feedback. # Print feedback.
echo -n "Checking whether all dependencies are installed... " echo -n "Checking whether installation script dependencies are installed... "
# 'Dialog'. # 'Dialog'.
if ! command -v dialog &>/dev/null; then if ! command -v dialog &>/dev/null; then
@ -495,33 +492,16 @@ function waCheckDependencies() {
# Terminate the script. # Terminate the script.
return "$EC_MISSING_DEPS" return "$EC_MISSING_DEPS"
fi fi
}
# 'Address Resolution Protocol' # Name: 'waCheckInstallDependencies'
if ! command -v arp &>/dev/null; then # Role: Terminate script if dependencies required to install WinApps are missing.
# Complete the previous line. function waCheckInstallDependencies() {
echo -e "${FAIL_TEXT}Failed!${CLEAR_TEXT}\n" # Declare variables.
local FREERDP_MAJOR_VERSION="" # Stores the major version of the installed copy of FreeRDP.
# Display the error type. # Print feedback.
echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}MISSING DEPENDENCIES.${CLEAR_TEXT}" echo -n "Checking whether dependencies are installed... "
# Display the error details.
echo -e "${INFO_TEXT}Please install 'net-tools' to proceed.${CLEAR_TEXT}"
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${COMMAND_TEXT}sudo apt install net-tools${CLEAR_TEXT}"
echo "Red Hat/Fedora-based systems:"
echo -e " ${COMMAND_TEXT}sudo dnf install net-tools${CLEAR_TEXT}"
echo "Arch Linux systems:"
echo -e " ${COMMAND_TEXT}sudo pacman -S net-tools${CLEAR_TEXT}"
echo "Gentoo Linux systems:"
echo -e " ${COMMAND_TEXT}sudo emerge --ask sys-apps/net-tools${CLEAR_TEXT}"
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return "$EC_MISSING_DEPS"
fi
# 'Netcat' # 'Netcat'
if ! command -v nc &>/dev/null; then if ! command -v nc &>/dev/null; then
@ -613,7 +593,7 @@ function waCheckDependencies() {
return "$EC_MISSING_DEPS" return "$EC_MISSING_DEPS"
fi fi
# 'libvirt' / 'virt-manager'. # 'libvirt'/'virt-manager' + 'Address Resolution Protocol'.
if [ "$WAFLAVOR" = "libvirt" ]; then if [ "$WAFLAVOR" = "libvirt" ]; then
if ! command -v virsh &>/dev/null; then if ! command -v virsh &>/dev/null; then
# Complete the previous line. # Complete the previous line.
@ -640,6 +620,32 @@ function waCheckDependencies() {
# Terminate the script. # Terminate the script.
return "$EC_MISSING_DEPS" return "$EC_MISSING_DEPS"
fi fi
if ! command -v arp &>/dev/null; then
# Complete the previous line.
echo -e "${FAIL_TEXT}Failed!${CLEAR_TEXT}\n"
# Display the error type.
echo -e "${ERROR_TEXT}ERROR:${CLEAR_TEXT} ${BOLD_TEXT}MISSING DEPENDENCIES.${CLEAR_TEXT}"
# Display the error details.
echo -e "${INFO_TEXT}Please install 'net-tools' to proceed.${CLEAR_TEXT}"
# Display the suggested action(s).
echo "--------------------------------------------------------------------------------"
echo "Debian/Ubuntu-based systems:"
echo -e " ${COMMAND_TEXT}sudo apt install net-tools${CLEAR_TEXT}"
echo "Red Hat/Fedora-based systems:"
echo -e " ${COMMAND_TEXT}sudo dnf install net-tools${CLEAR_TEXT}"
echo "Arch Linux systems:"
echo -e " ${COMMAND_TEXT}sudo pacman -S net-tools${CLEAR_TEXT}"
echo "Gentoo Linux systems:"
echo -e " ${COMMAND_TEXT}sudo emerge --ask sys-apps/net-tools${CLEAR_TEXT}"
echo "--------------------------------------------------------------------------------"
# Terminate the script.
return "$EC_MISSING_DEPS"
fi
elif [ "$WAFLAVOR" = "docker" ]; then elif [ "$WAFLAVOR" = "docker" ]; then
if ! command -v docker &>/dev/null; then if ! command -v docker &>/dev/null; then
# Complete the previous line. # Complete the previous line.
@ -1444,7 +1450,7 @@ function waInstall() {
waLoadConfig waLoadConfig
# Check for missing dependencies. # Check for missing dependencies.
waCheckDependencies waCheckInstallDependencies
# Update $MULTI_FLAG. # Update $MULTI_FLAG.
if [[ $MULTIMON == "true" ]]; then if [[ $MULTIMON == "true" ]]; then
@ -1476,7 +1482,7 @@ function waInstall() {
waCheckContainerRunning waCheckContainerRunning
elif [ "$WAFLAVOR" = "libvirt" ]; then elif [ "$WAFLAVOR" = "libvirt" ]; then
# Verify the current user's group membership. # Verify the current user's group membership.
waCheckGroupMembership # Check membership waCheckGroupMembership
# Check if the Windows VM is powered on. # Check if the Windows VM is powered on.
waCheckVMRunning waCheckVMRunning
@ -1615,6 +1621,9 @@ echo -e "${BOLD_TEXT}\
################################################################################ ################################################################################
${CLEAR_TEXT}" ${CLEAR_TEXT}"
# Check dependencies for the script.
waCheckScriptDependencies
# Source the contents of 'inquirer.sh'. # Source the contents of 'inquirer.sh'.
# shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck. # shellcheck source=/dev/null # Exclude this file from being checked by ShellCheck.
source "$INQUIRER_PATH" source "$INQUIRER_PATH"