mc-velocity/script.sh
2024-07-26 10:16:09 +02:00

151 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
printf "Better to run as root, because of permisions handeling.\n"
sleep 2
### Firewall
printf "Do you want to set up firewall rules by iptables? [Y/n]: \n"
read ansFirewallSetup
if [[ "$ansFirewallSetup" =~ ("N"|"n") ]]; then
printf "+ Thanks, working on next bit\n"
elif [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then
printf "Do you want to block non-Tailscale ssh connections? [Y/n]: "
read sshBlockRange
if [[ "$sshBlockRange" =~ ("n"|"N") ]]; then
printf "If you want input your own IP range [N/range]\n"
read sshRange
if [[ "$sshRange" =~ ("n"|"N") || -z $sshRange ]]; then
printf "+ Making your SSH connections wide and open. Think about it. /n"
ipList="*"
else
printf "+ Accepting SSH connections only on these ip's: $sshRange\n"
ipList="$sshRange"
fi
fi
### Update
sleep 2
apt update && apt upgrade -y
apt install openjdk-17-jre-headless screen
if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then
apt install iptables -y
fi
### User managment
groupadd velocity
useradd --system --shell /usr/sbin/nologin --home /opt/velocity -g velocity velocity
### File structure
mkdir /opt/velocity
mv data/velocity*.jar start.sh /opt/velocity/
mkdir /opt/velocity/plugins
mv data/Ambassador*.jar /opt/velocity/plugins
mv data/velocity.toml /opt/velocity/
mv data/forwarding.secret /opt/velocity/
### Permisions
chown -R velocity:velocity /opt/velocity/
### SystemD service ### needs update
printf "+ Preparign systemD service\n"
mv data/mc-forge.service /etc/systemd/system/
systemctl daemon-reload
### integration of Maxopoly's instructions on firewall ### needs update
if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then
printf "+ Executing firewall setup"
iptables -P INPUT ACCEPT #Clears existing rules
iptables -A INPUT -i lo -j ACCEPT #Allow loopback
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #Allow continuing connections
iptables -A INPUT -p tcp --dport 25577 -j ACCEPT #Allow Velocity port
if [[ "$ipList" = "*" ]]; then
### Wide and open
iiptables -A INPUT -p tcp --dport 22 j ACCEPT
elif [[! "$ipList" -z ]]; then
### Manual IP range
iptables -A INPUT -p tcp --dport 22 --source $ipList -j ACCEPT
fi
iptables -L ### Good place to paste a manual check to not lock yourself out
printf "\n Does it looks right? [Y/n]: "
read ansFirewallOK
if [[ "$ansFirewallOK" =~ ("Y"|"y") || -z "$ansFirewallOK" ]]; then
iptables -P INPUT DROP #Disallow everythink else
iptables -P FORWARD DROP #Block all forwarding
iptables -P OUTPUT ACCEPT #Allow all outgouing
apt install iptables-persistent -y
else
printf "\nOK it is time for manual configuration"
printf "\nAfter you are done ramamber to run 'apt install iptables-persistent' to save your config. System will automaticly remove your work after restart"
fi
fi
### Start service ### needs update
printf "Do you want to start server right now? [Y/n]: \n"
read startServer
if [[ "$startServer" =~ ("y"|"Y") || -z $startServer ]]; then
systemctl start mc-forge.serice
fi
systemctl enable mc-forge
### needs update
printf "\nsystemctl status mc-forge"
printf "\nsu velocity -s /bin/bash"