134 lines
2.8 KiB
Bash
Executable File
134 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
printf "Better to run as root, because of permisions handeling."
|
|
|
|
sleep 2
|
|
|
|
printf "Do you want to set up firewall rules by iptables? [Y/n]: "
|
|
read ansFirewallSetup
|
|
|
|
|
|
if [[ "$ansFirewallSetup" =~ ("N"|"n") ]]; then
|
|
|
|
printf "+ Thanks, working on next bit\n"
|
|
|
|
else
|
|
|
|
printf "Do you want to block non-LAN ssh connections? [Y/n/ip range]: "
|
|
read sshBlockRange
|
|
|
|
|
|
if [[ $sshBlockRange =~ ("n"|"N") ]]; then
|
|
|
|
#$sshBlockRange = ""
|
|
printf 'N\n'
|
|
|
|
elif [[ $sshBlockRange =~ ("y"|"Y") || -z $sshBlockRange ]]; then
|
|
|
|
### Have to found how to locate LAN
|
|
#$sshBlockRange = "y"
|
|
printf 'Y\n'
|
|
|
|
else
|
|
printf "\nHope you know what you are doing, I am not checking these :]"
|
|
printf "\nyou typed $sshBlockRange"
|
|
sleep 2
|
|
printf "\nDont worry you will have time to chack if it is looking righ later.\n"
|
|
|
|
fi
|
|
fi
|
|
|
|
|
|
# Just to be shure
|
|
printf "\n+ Starting to upgrade base system\n\n"
|
|
|
|
sudo apt update
|
|
sudo apt upgrade -y
|
|
|
|
# Installing depandencies
|
|
printf "\n+ Installing depandencies \n\n"
|
|
sudo apt install openjdk-17-jre-headless screen p7zip-full iptables -y
|
|
|
|
# User and groupe managment
|
|
printf "\n+ Creating user minecraft and basic file structure"
|
|
groupadd minecraft
|
|
|
|
useradd --system --shell /usr/sbin/nologin --home /opt/minecraft -g minecraft minecraft
|
|
|
|
# File strukture and basic install
|
|
mkdir /opt/minecraft
|
|
|
|
mv Forge-1.20.1.jar /opt/minecraft/
|
|
|
|
cd /opt/minecraft/
|
|
|
|
# Installing server
|
|
printf "+ Installing Forge 1.20.1 \n \n"
|
|
|
|
java -Xms512M -Xmx2048M -jar Forge-1.20.1.jar --installServer
|
|
|
|
cd -
|
|
|
|
mv eula.txt /opt/minecraft/
|
|
mv server-icon.png /opt/minecraft/
|
|
mv server.properties /opt/minecraft/
|
|
|
|
mv run.sh /opt/minecraft
|
|
|
|
mkdir /opt/minecraft/mods
|
|
|
|
printf "\n+ Unpacking mods \n \n"
|
|
|
|
7z x Mods.zip -o/opt/minecraft/mods/
|
|
|
|
# Permision handeling
|
|
printf "\n+ Permision handeling"
|
|
chown -R minecraft:minecraft /opt/minecraft
|
|
|
|
# SystemD service
|
|
printf "+ Preparign systemD service"
|
|
cp mc-forge.service /etc/systemd/system/
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start mc-forge.service
|
|
|
|
systemctl enable mc-forge
|
|
|
|
|
|
# integration of Maxopoly's instructions on firewall
|
|
|
|
if [[ "n" != "$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 22 --source 172.18.42.0/24 -j ACCEPT #Allow ssh from set network
|
|
|
|
iptables -A INPUT -p tcp --dport 25565 -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 [[ "n" != "$ansFirewallOK" ]]; then
|
|
|
|
iptables -P INPUT DROP #Disallow everythink else
|
|
|
|
iptables -P FORWARD DROP #Block all forwarding
|
|
|
|
iptables -P OUTPUT ACCEPT #Allow all outgouing
|
|
fi
|
|
|
|
apt install iptables-persistent -y
|
|
|
|
fi
|