#!/bin/bash
# NOTE installs nginx, postgresql ,python , php , node  , quota for homes 
if ! [[ "8 9 10 11 12 13" == *"$(grep VERSION_ID /etc/os-release | cut -d '"' -f 2 | cut -d '.' -f 1)"* ]];
then
    echo "Debian $(grep VERSION_ID /etc/os-release | cut -d '"' -f 2 | cut -d '.' -f 1) is not currently supported.";
    exit;
fi


true
# shellcheck source=lib.sh
if ! source <(curl -sL https://code.hbues.net/bash/core.sh)
then
    source <(curl -sL https://code.hbues.net/bash/core.sh)
fi



printf "Install needed dependencies \n"
install_if_not lshw
install_if_not net-tools
install_if_not apt-utils

printf "Nice to have dependencies \n"
install_if_not iputils-ping

printf "We don't want automatic updates since they might fail (we use our own script) \n"
if is_this_installed unattended-upgrades
then
    sudo apt-get purge unattended-upgrades -y
    sudo apt-get autoremove -y
    sudo rm -rf /var/log/unattended-upgrades
fi

# APT over HTTPS
install_if_not apt-transport-https

# Install build-essentials to get make
install_if_not build-essential

# Install package for crontab
install_if_not cron

# Make sure add-apt-repository exists (needed in lib.sh)
install_if_not software-properties-common

printf "Install development base \n"
install_if_not build-essential 
install_if_not libssl-dev 
install_if_not zlib1g-dev 
install_if_not libncurses5-dev 
install_if_not libncursesw5-dev 
install_if_not libreadline-dev 
install_if_not libsqlite3-dev 
install_if_not libgdbm-dev 
install_if_not libdb5.3-dev 
install_if_not libbz2-dev 
install_if_not autoconf 
install_if_not automake 
install_if_not libtool 
install_if_not cmake 
install_if_not python3 
install_if_not python3-dev 
install_if_not python3-pip 
install_if_not python3-venv 
install_if_not git 
install_if_not vim-nox 
install_if_not libssl-dev 
install_if_not libcurl4-openssl-dev 
install_if_not libxml2-dev 
install_if_not libsqlite3-dev 
install_if_not gdb 
install_if_not curl 
install_if_not valgrind 
install_if_not libc6-dev 
install_if_not linux-libc-dev 
install_if_not bat 
install_if_not kitty 
install_if_not alacritty 
install_if_not nfs-kernel-server 
install_if_not quota

printf "Install NGINX \n"
install_if_not nginx-extras


printf "Install PHP "$PHPVER" \n "

install_if_not php"$PHPVER"-fpm
install_if_not php"$PHPVER"-intl
install_if_not php"$PHPVER"-ldap
install_if_not php"$PHPVER"-imap
install_if_not php"$PHPVER"-gd
install_if_not php"$PHPVER"-pgsql
install_if_not php"$PHPVER"-curl
install_if_not php"$PHPVER"-xml
install_if_not php"$PHPVER"-zip
install_if_not php"$PHPVER"-mbstring
install_if_not php"$PHPVER"-soap
install_if_not php"$PHPVER"-gmp
install_if_not php"$PHPVER"-bz2
install_if_not php"$PHPVER"-bcmath
install_if_not php-pear



printf "Install PostgreSQL client  \n "

install_if_not postgresql-client

# Calculate the values of PHP-FPM based on the amount of RAM available (it's done in the startup script as well)
#calculate_php_fpm

#sudo mkdir -p "/etc/pip"
#pipconf="/etc/pip/pip.conf"

#sudo printf "[global]\nbreak-system-packages = true\n" | sudo tee --append ${pipconf}
# OR
#sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED


# Install VM-tools
if [ "$SYSVENDOR" == "VMware, Inc." ];
then
    install_if_not open-vm-tools
elif [[ "$SYSVENDOR" == "QEMU" || "$SYSVENDOR" == "Red Hat" ]];
then
    install_if_not qemu-guest-agent
    sudo systemctl enable qemu-guest-agent
    sudo systemctl start qemu-guest-agent
fi


#prepare th user skeletons
#
sudo mkdir -p /etc/skel/public_html
sudo printf "ambagasdowa ALL=(ALL:ALL) NOPASSWD: ALL\n" | sudo tee --append /etc/sudoers.d/ambagasdowa
















