196 lines
4.2 KiB
Bash
196 lines
4.2 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
|
|
|
|
|
|
|
|
### ------------ 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
|