new method for dependencies check

This commit is contained in:
b068931cc450442b63f5b3d276ea4297 2024-01-24 23:14:33 +01:00
parent 5c26c8ed4e
commit a2f03196e6

View File

@ -148,41 +148,34 @@ change_hostname() {
echo "127.0.0.1 spyguard.local" >> /etc/hosts echo "127.0.0.1 spyguard.local" >> /etc/hosts
} }
install_package() { install_packages() {
# Install associated packages by using aptitude. # Install associated packages by using aptitude.
if [[ $1 == "tshark" || $1 == "sqlite3" || $1 == "suricata" ]]; then packages=("tshark"
apt install $1 -y "sqlite3"
elif [[ $1 == "dig" ]]; then "suricata"
apt install -y dnsutils "dnsutils"
elif [[ $1 == "pip3" ]]; then "python3-pip"
apt install -y python3-pip "python3-venv"
elif [[ $1 == "venv" ]]; then "net-tools")
apt install -y python3-venv
elif [[ $1 == "arp" ]]; then
apt install -y net-tools
fi
}
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" echo -e "\e[39m[+] Checking dependencies...\e[39m"
for bin in "${bins[@]}" for package in "${packages[@]}"
do do
if [[ -f "$bin" ]]; then if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q -P '^install ok installed$'; then
echo -e "\e[92m [✔] ${bin##*/} installed\e[39m" echo -e "\e[92m [✔] $package already installed\e[39m"
else else
echo -e "\e[93m [✘] ${bin##*/} not installed, lets install it\e[39m" echo -e "\e[93m [✘] $package not installed, lets install it\e[39m"
install_package ${bin##*/} 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 fi
done done
}
create_venv() {
echo -e "\e[39m[+] Create and activate Virtual Environment for Python packages\e[39m" echo -e "\e[39m[+] Create and activate Virtual Environment for Python packages\e[39m"
python3 -m venv /usr/share/spyguard/spyguard-venv python3 -m venv /usr/share/spyguard/spyguard-venv
source /usr/share/spyguard/spyguard-venv/bin/activate source /usr/share/spyguard/spyguard-venv/bin/activate
@ -207,7 +200,7 @@ cleaning() {
systemctl disable suricata.service &> /dev/null systemctl disable suricata.service &> /dev/null
# Removing some useless dependencies. # 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" 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 get_version
set_userlang set_userlang
set_credentials set_credentials
check_dependencies install_packages
create_venv
change_hostname change_hostname
generate_certificate generate_certificate
create_database create_database