From a2f03196e684428e02a7cd22324af19995e5c1b0 Mon Sep 17 00:00:00 2001 From: b068931cc450442b63f5b3d276ea4297 <77171083+b068931cc450442b63f5b3d276ea4297@users.noreply.github.com> Date: Wed, 24 Jan 2024 23:14:33 +0100 Subject: [PATCH] new method for dependencies check --- install.sh | 62 ++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/install.sh b/install.sh index 300f472..feefc3d 100644 --- a/install.sh +++ b/install.sh @@ -148,41 +148,34 @@ change_hostname() { echo "127.0.0.1 spyguard.local" >> /etc/hosts } -install_package() { - # Install associated packages by using aptitude. - if [[ $1 == "tshark" || $1 == "sqlite3" || $1 == "suricata" ]]; then - apt install $1 -y - elif [[ $1 == "dig" ]]; then - apt install -y dnsutils - elif [[ $1 == "pip3" ]]; then - apt install -y python3-pip - elif [[ $1 == "venv" ]]; then - apt install -y python3-venv - elif [[ $1 == "arp" ]]; then - apt install -y net-tools +install_packages() { +# Install associated packages by using aptitude. +packages=("tshark" + "sqlite3" + "suricata" + "dnsutils" + "python3-pip" + "python3-venv" + "net-tools") + +echo -e "\e[39m[+] Checking dependencies...\e[39m" +for package in "${packages[@]}" +do + if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q -P '^install ok installed$'; then + echo -e "\e[92m [✔] $package already installed\e[39m" + else + echo -e "\e[93m [✘] $package not installed, lets install it\e[39m" + apt-get install -y "$package" + if [ $? -eq 0 ]; then + echo -e "\e[92m [✔] $package was successfully installed\e[39m" + else + echo -e "\e[91m [✘] $package has an error during the installation\e[39m" + fi fi +done } -check_dependencies() { - # Check binary dependencies associated to the project. - # If not installed, call install_package with the package name. - bins=("/usr/bin/tshark" - "/usr/bin/dig" - "/usr/bin/suricata" - "/usr/bin/sqlite3" - "/usr/bin/pip3" - "/usr/sbin/arp") - - echo -e "\e[39m[+] Checking dependencies...\e[39m" - for bin in "${bins[@]}" - do - if [[ -f "$bin" ]]; then - echo -e "\e[92m [✔] ${bin##*/} installed\e[39m" - else - echo -e "\e[93m [✘] ${bin##*/} not installed, lets install it\e[39m" - install_package ${bin##*/} - fi - done +create_venv() { echo -e "\e[39m[+] Create and activate Virtual Environment for Python packages\e[39m" python3 -m venv /usr/share/spyguard/spyguard-venv source /usr/share/spyguard/spyguard-venv/bin/activate @@ -207,7 +200,7 @@ cleaning() { systemctl disable suricata.service &> /dev/null # Removing some useless dependencies. - sudo apt autoremove -y &> /dev/null + apt autoremove -y &> /dev/null echo -e "\e[92m[+] Installation finished! You can open https://localhost:8443 to configure network settings.\e[39m" } @@ -242,7 +235,8 @@ else get_version set_userlang set_credentials - check_dependencies + install_packages + create_venv change_hostname generate_certificate create_database