§2024-10-31
#! /bin/bash
OURNAME=02_install_prerequisites.sh
# AUT_SAFETY=true was defined in 00_install_global_functions_variables.sh
# 00_install_global_functions_variables.sh:export AUT_SAFETY=true
# No $AUT_SAFETY variable present, so we have not sourced install_variables.sh yet
# The use of +x in ${AUT_SAFETY+x} is a technique in Bash for checking whether a variable is set,
# The if [ -z ... ] construct in a Bash script is used to check if a variable is empty
if [ -z ${AUT_SAFETY+x} ]
then
echo "this script ${RED}called directly${NC}, and not from the main ./install.sh script"
echo "initializing common variables ('install_variables.sh')"
source "$INSTALLDIR/install_variables.sh"
fi
echo -e "\n-- Executing ${ORANGE}${OURNAME}${NC} subscript --"
echo -e "Checking ${YELLOW}lsof${NC}"
# Using command -v is a reliable way to check for the existence of a command in a script,
# and it’s commonly used in scripts to ensure dependencies are met before proceeding with execution.
# lsof (short for "list open files")
# https://phoenixnap.com/kb/lsof-command
PROGRAM_LSOF=`command -v lsof`
if ! [ -x "$PROGRAM_LSOF" ]; then
echo -e "${RED}ERROR:${NC} lsof is not installed."
echo "to know which package contains the particular executable, launch:"
echo "dpkg -S lsof |grep lsof$ # on ubuntu/debian variants"
echo -e "Launching for you:\n"
echo -e "`dpkg -S lsof | grep /lsof$`"
echo -e "\nOn ubuntu 16.04 it is: ${GREEN}apt install lsof${NC}"
fi
# dpkg -S /usr/bin/ls
# The command dpkg -S is used in Debian-based Linux distributions (like Ubuntu) to search for
# the package that owns a specific file.
# dpkg -S /usr/bin/ls: Searches for a specific file using its full path, returning a precise package.
# dpkg -S ls: Searches for files by name, potentially returning multiple packages if there are any matches.
echo -e "Checking ${YELLOW}ps${NC}"
PROGRAM_PS=`command -v ps`
if ! [ -x "$PROGRAM_PS" ]; then
echo -e "${RED}ERROR:${NC} ps is not installed."
echo "to know which package contains the particular executable, launch:"
echo "dpkg -S ps |grep ps$ # on ubuntu/debian variants"
echo -e "Launching for you:\n"
echo -e "`dpkg -S ps | grep /ps$`"
echo -e "\nOn ubuntu 16.04 it is: ${GREEN}apt install procps${NC}"
fi