From 6d37ad3af0fd12f9b2ea993042c210972b6a3bdd Mon Sep 17 00:00:00 2001 From: Fr4nzD13trich Date: Sat, 11 Oct 2025 17:16:38 +0200 Subject: [PATCH] Dependencie Check updated --- assets/config/deps/dependencies | 3 +- assets/test/test.sh | 102 +++++++++----------------------- dev_env_setup.sh | 69 ++++++++++++++++----- 3 files changed, 83 insertions(+), 91 deletions(-) diff --git a/assets/config/deps/dependencies b/assets/config/deps/dependencies index 052385f..3ccf2d8 100644 --- a/assets/config/deps/dependencies +++ b/assets/config/deps/dependencies @@ -1 +1,2 @@ -deps="openssl nginx nginx-common python3-meshtastic python3-flask python3-requests" \ No newline at end of file +#deps="openssl nginx nginx-common python3-meshtastic python3-flask python3-requests" +deps=("openssl" "nginx" "python3-meshtastic" "python3-flask" "python3-requests") \ No newline at end of file diff --git a/assets/test/test.sh b/assets/test/test.sh index 8327725..209beee 100755 --- a/assets/test/test.sh +++ b/assets/test/test.sh @@ -18,91 +18,43 @@ else fi ### DEPENDENCIES + +dep_check() { + local pkg="$1" -check_for_package() { - if dpkg-query -s "$1" 1>/dev/null 2>&1; then - return 0 - elif apt-cache show "$1" 1>/dev/null 2>&1; then - return 1 + if dpkg -s "$pkg" >/dev/null 2>&1; then + echo "$pkg" >>/tmp/installed_dev else - return 2 + echo "$pkg" >>/tmp/missing_dev fi } -for package in $deps; do - if check_for_package "$package"; then - printf "%-20s - %s\n" "$package" "package is installed" - elif [ $? -eq 1 ]; then - printf "%-20s - %s\n" "$package" "package is not installed, it is available in package repository" - else - printf "%-20s - %s\n" "$package" "package is not installed, it is not available in package repository" - fi -done - +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" +else + 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 ${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" - break - - elif [[ "$install" == "n" || "$install" = "N" ]]; then + 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" + sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null exit 1 - 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 " fi done -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 \ No newline at end of file +fi \ No newline at end of file diff --git a/dev_env_setup.sh b/dev_env_setup.sh index acfbe5d..c1be918 100755 --- a/dev_env_setup.sh +++ b/dev_env_setup.sh @@ -15,31 +15,53 @@ if (( $(id -u) == 0 )); then else echo -e " ${RED}Privilege check failed... Please run script with sudo or as root!${CRS}\n" exit 1 + fi ### 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 - echo -e " ${RED}Dependencies not met.${CRS}\n" - - 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 + echo -e "\n ${RED}Following dependencies are missing :${CRS}\n\n$missing" - 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" + sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null exit 1 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 " + fi done fi @@ -53,13 +75,17 @@ onif=$(/sbin/ip route get 162.249.72.1 | awk '{print $5}' | cut -d/ -f1) while true; do echo -e " ${YEL}What network interface will nginx be using?${CRS}" read -p " current = "$onif" --> " nif + if ! [ "$nif" ]; then nif="$onif" break + elif [ -d "/sys/class/net/$nif" ]; then break + else echo -e "\n ${LRD}Interface not found... Try again!${CRS}\n" + fi done @@ -70,9 +96,11 @@ echo -e "\n ${YEL}This information will be used to configure ${LCY}nginx.conf $ while true; do read -p " Would you like to change the hostname? (y/N) --> " conf_hostname + if [[ "$conf_hostname" = "" || "$conf_hostname" = "n" || "$conf_hostname" = "N" ]]; then new_hostname=$(hostname) break + elif [[ "$conf_hostname" = "y" || "$conf_hostname" = "Y" ]]; then read -p " Enter new hostname --> " new_hostname sudo sed -i.backup "s/$(hostname)/$new_hostname/g" /etc/hosts @@ -81,8 +109,10 @@ while true; do hostname -F /etc/hostname echo -e "\n ${GRN}Host name changed to ${LCY}$(hostname)${CRS}" break + else echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, set new hostname)\n N = (No, leave as is)${CRS}\n " + fi done @@ -95,19 +125,26 @@ while true; do if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then echo -e " ${YEL}Enter path to certificates folder${CRS}" read -p " default = /etc/nginx/ssl --> " cert_path + if ! [ "$cert_path" ]; then cert_path=/etc/nginx/ssl + elif [[ "$cert_path" = "." ]]; then cert_path=$PWD + else : + fi echo -e " ${YEL}Enter file name for certificate and key${CRS}" read -p " default = $(hostname) --> " cert_name + if ! [ "$cert_name" ]; then cert_name=$(hostname) + else : + fi echo "" 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|KEYPATH|$cert_path/$cert_name|" /etc/nginx/sites-enabled/$(hostname).conf break + elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then echo -e "\n ${RED}Encryption disabled${CRS}\n" break + 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 " - fi + fi done ###### MAINTENANCE