2024-08-11 12:25:49 +02:00

122 lines
2.8 KiB
Bash

#!/bin/bash
### Checks dependencies arrays ###
depDiff=()
for oPkg in "${oDependencies[@]}"; do
skip=
for pkg in "${dependencies[@]}"; do
[[ $oPkg == $pkg ]] && { skip=1; break; }
done
[[ -n $skip ]] || depDiff+=("$oPkg")
done
declare -p depDiff
if [[ ! "${#depDiff[@]}" == 0 ]]; then
printf "These dependencies are newly not requred: ${depDiff[@]} \n"
printf "Do you wish to uninstall them? [Y/n]: \n"
read ansDiff -n 1
if [[ "$ansDiff" =~ ("y"|"Y") || -z $ansDiff ]]; then
apt remove ${depDiff[@]}
fi
fi
### 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 ${DepInstalled[@]}
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 -n 1
if [[ "$ansReport" =~ ("y"|"Y"|"yes"|"Yes") || -z $ansReport ]]; then
apt remove ${DepInstalled[@]}
else
printf "Hope you know what you are doing."
fi
else
# error handeling
fi
### --- User managment --- ###
### --- File Structure --- ###
### ------------ Needs work ----------- ###
### 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