136 lines
2.9 KiB
Bash
Executable File
136 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
echo "Better to run as root, because of permisions handeling."
|
|
|
|
sleep 2
|
|
|
|
echo "Do you want to set up firewall rules by iptables? [Y/n]: "
|
|
read ansFirewallSetup
|
|
|
|
if [[ "n" != "$ansFirewallSetup" ]]; then
|
|
echo "\n Do you want to block non-LAN ssh connections? [Y/n/ip range]: "
|
|
read -n 1 sshBlockRange
|
|
|
|
|
|
if [[ "$sshBlockRange" == "y"
|
|
||"$sshBlockRange" == "Y"
|
|
||"$sshBlockRange" == "" ]]; then
|
|
|
|
### Have to found how to locate LAN
|
|
$sshBlockRange = "y"
|
|
|
|
elif [[ "$sshBlockRange" == "n"
|
|
|| "$sshBlockRange" == "N"]]; then
|
|
|
|
$sshBlockRange = ""
|
|
|
|
elif [[ -n "$sshBlockRange" ]]; then
|
|
|
|
echo "Hope you know what you are doing, I am not checking these :]"
|
|
|
|
echo "You have 5 seconds to stope this by pressing Ctrl+C"
|
|
|
|
sleep 5
|
|
|
|
echo "OK, lets go now"
|
|
|
|
echo "Dont worry you will have time to chack if it is looking righ later."
|
|
|
|
sleep 2
|
|
fi
|
|
fi
|
|
|
|
|
|
# Just to be shure
|
|
echo "\n+ Starting to upgrade base system\n\n"
|
|
|
|
sudo apt update
|
|
sudo apt upgrade -y
|
|
|
|
# Installing depandencies
|
|
echo "\n+ Installing depandencies \n\n"
|
|
sudo apt install openjdk-17-jre-headless screen p7zip-full iptables -y
|
|
|
|
# User and groupe managment
|
|
echo "\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
|
|
echo "+ 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
|
|
|
|
echo "\n+ Unpacking mods \n \n"
|
|
|
|
7z x Mods.zip -o/opt/minecraft/mods/
|
|
|
|
# Permision handeling
|
|
echo "\n+ Permision handeling"
|
|
chown -R minecraft:minecraft /opt/minecraft
|
|
|
|
# SystemD service
|
|
echo "+ 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
|
|
|
|
echo "+ 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
|
|
|
|
echo "\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
|