mc-velocity/script.sh
2024-07-26 01:17:34 +02:00

158 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
printf "Better to run as root, because of permisions handeling.\n"
sleep 2
### Firewall ### needs to update
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-VPN ssh connections? [Y/n/castom]: "
read sshBlockRange
### needs update from LAN to VPN
if [[ $sshBlockRange =~ ("n"|"N") ]]; then
printf "+ OK, working on next bit\n"
ipList=""
elif [[ $sshBlockRange =~ ("y"|"Y") || -z $sshBlockRange ]]; then
#Pipes all informations about ip interfaces
ipList=$(ip -o -4 a show tailscale0)
#Founds data in pattern
ipList=$(echo $ipList | grep -Eo "([0-9]*\.){3}[0-9]*/[0-9]*")
#substitues space for coma
ipList=$(echo $ipList | tr " " ",")
printf "+ Accepting SSH connections only on these ip's: $ipList\n"
else
printf "\nHope you know what you are doing, I am not checking these :]"
printf "\nSubmit your IP range to acces SSH in format 192.168.1.1/24
\nYour IP range: "
read ipList
printf "\n+ Allowing SSH on this range: $ipList \n"
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 ### needs update
groupadd minecraft
useradd --system --shell /usr/sbin/nologin --home /opt/minecraft -g minecraft minecraft
### File structure ###
mkdir /opt/velocity
mv data/velocity*.jar start.sh /opt/velocity/
mkdir /opt/velocity/plugins
mv data/Ambassador*.jar /opt/velocity/plugins
### Nestopne se samo, mozna lepsi vytvorit strukturu za nej vlozit config a spustit az pres systemD
./start.sh
end
### Screen usige alert
rm /opt/velocity/velocity.toml
mv data/velocity.toml /opt/velocity/
### Permisions ### needs update
chown -R godot:godot /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 MC port
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 minecraft -s /bin/bash"