Dependencie Check updated

This commit is contained in:
Fr4nz D13trich 2025-10-11 17:16:38 +02:00
parent cffdc504ca
commit 6d37ad3af0
3 changed files with 83 additions and 91 deletions

View file

@ -1 +1,2 @@
deps="openssl nginx nginx-common python3-meshtastic python3-flask python3-requests" #deps="openssl nginx nginx-common python3-meshtastic python3-flask python3-requests"
deps=("openssl" "nginx" "python3-meshtastic" "python3-flask" "python3-requests")

View file

@ -18,91 +18,43 @@ else
fi fi
### DEPENDENCIES ### DEPENDENCIES
dep_check() {
local pkg="$1"
check_for_package() { if dpkg -s "$pkg" >/dev/null 2>&1; then
if dpkg-query -s "$1" 1>/dev/null 2>&1; then echo "$pkg" >>/tmp/installed_dev
return 0
elif apt-cache show "$1" 1>/dev/null 2>&1; then
return 1
else else
return 2 echo "$pkg" >>/tmp/missing_dev
fi fi
} }
for package in $deps; do for pkg in "${deps[@]}"; do
if check_for_package "$package"; then dep_check "$pkg"
printf "%-20s - %s\n" "$package" "package is installed" done
elif [ $? -eq 1 ]; then
printf "%-20s - %s\n" "$package" "package is not installed, it is available in package repository" installed="$(cat /tmp/installed_dev 2>/dev/null)"
else missing="$(cat /tmp/missing_dev 2>/dev/null)"
printf "%-20s - %s\n" "$package" "package is not installed, it is not available in package repository"
fi if ! [ "$missing" ]; then
done echo -e "\n ${GRN}Dependencies met. Proceeding...${CRS}\n"
else
echo -e "\n ${RED}Following dependencies are missing :${CRS}\n\n$missing"
while true; do while true; do
echo -e " ${YEL}Do you wish to install via APT?" echo -e "\n ${YEL}Do you wish to install via APT?"
read -p " (Y/n) --> " install read -p " (Y/n) --> " install_dep
echo "" echo -e "${CRS}"
if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then if [[ "$install_dep" = "" || "$install_dep" = "y" || "$install_dep" = "Y" ]]; then
sudo apt update && sudo apt install -y $pkgs_apt sudo apt update && sudo apt install -y $missing --simulate
echo -e "\n ${GRN}Dependencies installed. Proceeding...${CRS}\n" echo -e "\n ${GRN}Dependencies installed. Proceeding...${CRS}\n"
break sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null
break
elif [[ "$install" == "n" || "$install" = "N" ]]; then elif [[ "$install_dep" == "n" || "$install_dep" = "N" ]]; then
echo -e "\n ${RED}Missing dependencies... Exiting!${CRS}\n" echo -e "\n ${RED}Missing dependencies... Exiting!${CRS}\n"
sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null
exit 1 exit 1
else else
echo -e "\n ${YEL}Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " echo -e "\n ${YEL}Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n "
fi fi
done done
fi fi
# List of packages to check
packages=("git" "gcc" "python3" "vim")
# Function to check if a package is installed and install if not
check_and_install() {
local pkg="$1"
local package_manager=""
# Determine the package manager based on the system
if command -v apt-get >/dev/null 2>&1; then
package_manager="apt-get"
elif command -v yum >/dev/null 2>&1; then
package_manager="yum"
elif command -v dnf >/dev/null 2>&1; then
package_manager="dnf"
else
echo "Unsupported package manager. Cannot proceed."
exit 1
fi
# Check if package is installed
if dpkg -s "$pkg" >/dev/null 2>&1; then
echo "$pkg is already installed."
else
echo "$pkg is not installed."
read -p "Would you like to install $pkg? (Y/N): " answer
case $answer in
[Yy]*)
if [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install -y "$pkg"
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install -y "$pkg"
elif [[ "$package_manager" == "dnf" ]]; then
sudo dnf install -y "$pkg"
fi
;;
*)
echo "Skipping installation of $pkg."
;;
esac
fi
}
# Loop through each package and check/install
for pkg in "${packages[@]}"; do
check_and_install "$pkg"
done

View file

@ -15,31 +15,53 @@ if (( $(id -u) == 0 )); then
else else
echo -e " ${RED}Privilege check failed... Please run script with sudo or as root!${CRS}\n" echo -e " ${RED}Privilege check failed... Please run script with sudo or as root!${CRS}\n"
exit 1 exit 1
fi fi
### DEPENDENCIES ### DEPENDENCIES
dep_check() {
local pkg="$1"
if dpkg -s "$pkg" >/dev/null 2>&1; then
echo "$pkg" >>/tmp/installed_dev
else
echo "$pkg" >>/tmp/missing_dev
fi
}
for pkg in "${deps[@]}"; do
dep_check "$pkg"
done
installed="$(cat /tmp/installed_dev 2>/dev/null)"
missing="$(cat /tmp/missing_dev 2>/dev/null)"
if ! [ "$missing" ]; then
echo -e "\n ${GRN}Dependencies met. Proceeding...${CRS}\n"
if command -v "$pkgs_check" >/dev/null 2>&1; then ### create a FOR loop for pkg check?!
echo -e " ${GRN}Dependency check passed...${CRS}\n"
else else
echo -e " ${RED}Dependencies not met.${CRS}\n" echo -e "\n ${RED}Following dependencies are missing :${CRS}\n\n$missing"
while true; do
echo -e " ${YEL}Do you wish to install via APT?"
read -p " (Y/n) --> " install
echo ""
if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then
sudo apt update && sudo apt install -y $pkgs_apt
echo -e "\n ${GRN}Dependencies installed. Proceeding...${CRS}\n"
break
elif [[ "$install" == "n" || "$install" = "N" ]]; then while true; do
echo -e "\n ${YEL}Do you wish to install via APT?"
read -p " (Y/n) --> " install_dep
echo -e "${CRS}"
if [[ "$install_dep" = "" || "$install_dep" = "y" || "$install_dep" = "Y" ]]; then
sudo apt update && sudo apt install -y $missing --simulate
echo -e "\n ${GRN}Dependencies installed. Proceeding...${CRS}\n"
sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null
break
elif [[ "$install_dep" == "n" || "$install_dep" = "N" ]]; then
echo -e "\n ${RED}Missing dependencies... Exiting!${CRS}\n" echo -e "\n ${RED}Missing dependencies... Exiting!${CRS}\n"
sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null
exit 1 exit 1
else else
echo -e "\n ${YEL}Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " echo -e "\n ${YEL}Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n "
fi fi
done done
fi fi
@ -53,13 +75,17 @@ onif=$(/sbin/ip route get 162.249.72.1 | awk '{print $5}' | cut -d/ -f1)
while true; do while true; do
echo -e " ${YEL}What network interface will nginx be using?${CRS}" echo -e " ${YEL}What network interface will nginx be using?${CRS}"
read -p " current = "$onif" --> " nif read -p " current = "$onif" --> " nif
if ! [ "$nif" ]; then if ! [ "$nif" ]; then
nif="$onif" nif="$onif"
break break
elif [ -d "/sys/class/net/$nif" ]; then elif [ -d "/sys/class/net/$nif" ]; then
break break
else else
echo -e "\n ${LRD}Interface not found... Try again!${CRS}\n" echo -e "\n ${LRD}Interface not found... Try again!${CRS}\n"
fi fi
done done
@ -70,9 +96,11 @@ echo -e "\n ${YEL}This information will be used to configure ${LCY}nginx.conf $
while true; do while true; do
read -p " Would you like to change the hostname? (y/N) --> " conf_hostname read -p " Would you like to change the hostname? (y/N) --> " conf_hostname
if [[ "$conf_hostname" = "" || "$conf_hostname" = "n" || "$conf_hostname" = "N" ]]; then if [[ "$conf_hostname" = "" || "$conf_hostname" = "n" || "$conf_hostname" = "N" ]]; then
new_hostname=$(hostname) new_hostname=$(hostname)
break break
elif [[ "$conf_hostname" = "y" || "$conf_hostname" = "Y" ]]; then elif [[ "$conf_hostname" = "y" || "$conf_hostname" = "Y" ]]; then
read -p " Enter new hostname --> " new_hostname read -p " Enter new hostname --> " new_hostname
sudo sed -i.backup "s/$(hostname)/$new_hostname/g" /etc/hosts sudo sed -i.backup "s/$(hostname)/$new_hostname/g" /etc/hosts
@ -81,8 +109,10 @@ while true; do
hostname -F /etc/hostname hostname -F /etc/hostname
echo -e "\n ${GRN}Host name changed to ${LCY}$(hostname)${CRS}" echo -e "\n ${GRN}Host name changed to ${LCY}$(hostname)${CRS}"
break break
else else
echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, set new hostname)\n N = (No, leave as is)${CRS}\n " echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, set new hostname)\n N = (No, leave as is)${CRS}\n "
fi fi
done done
@ -95,19 +125,26 @@ while true; do
if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then
echo -e " ${YEL}Enter path to certificates folder${CRS}" echo -e " ${YEL}Enter path to certificates folder${CRS}"
read -p " default = /etc/nginx/ssl --> " cert_path read -p " default = /etc/nginx/ssl --> " cert_path
if ! [ "$cert_path" ]; then if ! [ "$cert_path" ]; then
cert_path=/etc/nginx/ssl cert_path=/etc/nginx/ssl
elif [[ "$cert_path" = "." ]]; then elif [[ "$cert_path" = "." ]]; then
cert_path=$PWD cert_path=$PWD
else else
: :
fi fi
echo -e " ${YEL}Enter file name for certificate and key${CRS}" echo -e " ${YEL}Enter file name for certificate and key${CRS}"
read -p " default = $(hostname) --> " cert_name read -p " default = $(hostname) --> " cert_name
if ! [ "$cert_name" ]; then if ! [ "$cert_name" ]; then
cert_name=$(hostname) cert_name=$(hostname)
else else
: :
fi fi
echo "" echo ""
sudo mkdir -p "$cert_path" sudo mkdir -p "$cert_path"
@ -121,13 +158,15 @@ while true; do
sudo sed -i "s|CERTPATH|$cert_path/$cert_name|" /etc/nginx/sites-enabled/$(hostname).conf sudo sed -i "s|CERTPATH|$cert_path/$cert_name|" /etc/nginx/sites-enabled/$(hostname).conf
sudo sed -i "s|KEYPATH|$cert_path/$cert_name|" /etc/nginx/sites-enabled/$(hostname).conf sudo sed -i "s|KEYPATH|$cert_path/$cert_name|" /etc/nginx/sites-enabled/$(hostname).conf
break break
elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then
echo -e "\n ${RED}Encryption disabled${CRS}\n" echo -e "\n ${RED}Encryption disabled${CRS}\n"
break break
else else
echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, configure SSL certificate and continue)\n N = (No, leave unencrypted and continue)${CRS}\n " echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, configure SSL certificate and continue)\n N = (No, leave unencrypted and continue)${CRS}\n "
fi
fi
done done
###### MAINTENANCE ###### MAINTENANCE