173 lines
3.7 KiB
Bash

#!/bin/bash
# TODO! check for new dependency
### Checks dependencies ###
DepNum=0
DepMissing=()
DepInstalled=()
if [[ "$iptables" == "yes" ]]; then
dependencies+=('iptables')
fi
for pkg in "${dependencies[@]}"; do
if [[ '$(dpkg-query -w --showformat="${Status}\n" $pkg | grep "install ok installed")' =~ ("install"|"ok"|"installed") ]]; then
# pkg is installed
((DepNum++))
DepInstalled+=("$pkg")
else
# pkg is NOT installed
DepMissing+=("$pkg")
fi
done
### Count dependencies ###
if [[ "$DepNum" == "${#dependencies[@]}" ]]; then
#All dependencies are installed
DepStatus="all"
elif [[ "${#DepMissing[@]}" == "${#dependencies[@]}" ]]; then
#All dependencies are missing
DepStatus="none"
else
#Something is missing
DepStatus="some"
fi
### --- ###
if [[ "$BaseDep" == ("install") && "$DepStatus" == "all" ]]; then
# everything is allright
pritnf "it is done bro \n"
elif [[ "$BaseDep" == ("install") && "$DepStatus" == ("none"|"some") ]]; then
# some or none was installed installing rest
apt install ${DepMissing[@]}
printf "it is done now bro \n"
elif [[ "$BaseDep" == "uninstall" && "$DepStatus" == "none" ]]; then
# uninstall but it is not there
elif [[ "$BaseDep" == "uninstall" && "$DepStatus" == ("some"|"all") ]]; then
# uninstall
apt remove ${DepMissing[@]}
elif [[ "$BaseDep" == "report" && "$DepStatus" == "none" ]]; then
# nothing to do
elif [[ "$BaseDep" == "report" && "$DepStatus" == ("some"|"all") ]]; then
printf "Do you want to uinstall these dependencies? [Y/n]
printf "${DepInstalled[@]}
read ansReport
if [[ "$ansReport" =~ ("y"|"Y"|"yes"|"Yes") || -z $ansReport ]]; then
apt remove ${DepMissing[@]}
else
printf "Hope you know what you are doing."
fi
else
# error handeling
fi
### ------------ Needs work ----------- ###
### --- User managment --- ###
# If no > yes install
if [[ "$oDependenciesInstalled"="no" && "$dependenciesInstalled"="yes"]]; then
printf "+ Installing depandencies \n"
apt install openjdk-17-jre-headless screen
# if yes > no uninstall
if [[ "$oDependenciesInstalled"="yes" && "$dependenciesInstalled"="no"]]; then
printf "+ UNinstalling depandencies \n"
apt remove openjdk-17-jre-headless screen
# if yes > yes update
if [[ "$oDependenciesInstalled"="yes" && "$dependenciesInstalled"="yes"]]; then
printf "+ skiping dependencies check \n"
# if no > no restr
if [[ "$oDependenciesInstalled"="no" && "$dependenciesInstalled"="no"]]; then
pritf "+ skiping installation of dependencies \n"
else
#error handeling
fi
### --- File Structure --- ###
# If no > yes install
if [[ "$oDependenciesInstalled"="no" && "$dependenciesInstalled"="yes"]]; then
printf "+ Installing depandencies \n"
apt install openjdk-17-jre-headless screen
# if yes > no uninstall
if [[ "$oDependenciesInstalled"="yes" && "$dependenciesInstalled"="no"]]; then
printf "+ UNinstalling depandencies \n"
apt remove openjdk-17-jre-headless screen
# if yes > yes update
if [[ "$oDependenciesInstalled"="yes" && "$dependenciesInstalled"="yes"]]; then
printf "+ skiping dependencies check \n"
# if no > no restr
if [[ "$oDependenciesInstalled"="no" && "$dependenciesInstalled"="no"]]; then
pritf "+ skiping installation of dependencies \n"
else
#error handeling
fi
#
#
#
#
#
#
### User managment
printf "+ creating group and user for proxy \n"
groupadd velocity
useradd --system --shell /usr/sbin/nologin --home /opt/velocity -g velocity velocity
### File structure
printf "+ creating file structure in /opt/velocity/ \n"
mkdir /opt/velocity
cp data/velocity*.jar start.sh /opt/velocity/
mkdir /opt/velocity/plugins
cp data/velocity.toml data/forwarding.secret data/start.sh data/server-icon.png $baseInstallLocation