Compare commits

...

2 Commits

Author SHA1 Message Date
f19452ddd3 systemD service 2024-07-26 12:57:06 +02:00
3db62e5346 firewalling done 2024-07-26 10:16:09 +02:00
3 changed files with 94 additions and 48 deletions

View File

@ -6,18 +6,19 @@
- [x] addons for Forge - [x] addons for Forge
## To DO! ## To DO!
- [ ] Firewall shinanigns - [*] Firewall shinanigns
- [ ] Proxmox admin acces in firewall - [*] Proxmox admin acces in firewall
- [x] Auto add plugins - [x] Auto add plugins
- [*] SystemD service
- [ ] Config of velocity.toml - [ ] Config of velocity.toml
- [ ] IP - [ ] IP
- [*] Tailscale
- [ ] Comments of what is doing what - [ ] Comments of what is doing what
- [ ] Tailscale
## To learn ## To learn
- [x] What content of start.sh means - [x] What content of start.sh means
- [ ] Requred resources
- [ ] Different types of forwarding - [ ] Different types of forwarding
- [ ] SkinRestorer??? - [ ] SkinRestorer???
- [ ] DinMap - [ ] DinMap
- [ ] Requred resources - [ ] In their docs they have pages
- [ ] In their docs they have Configuration pages

31
data/mc-velocity.service Normal file
View File

@ -0,0 +1,31 @@
[Unit]
Description=Proxy for Minecraft server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
ExecReload=/usr/bin/screen -S velocity -X stuff \"reload^M\"
ExecStart=/usr/bin/screen -DmS velocity ./start.sh
ExecStop=/usr/bin/screen -p 0 -S velocity -X eval 'stuff "end"\\015'
ExecStop=/bin/sh -c '/bin/sleep 10'
Restart=on-failure
RestartSec=60s
ProtectControlGroups=true
ProtectHome=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectSystem=full
PrivateDevices=true
PrivateUsers=true
User=velocity
Group=velocity
WorkingDirectory=/opt/velocity/

100
script.sh
View File

@ -5,7 +5,7 @@ printf "Better to run as root, because of permisions handeling.\n"
sleep 2 sleep 2
### Firewall ### needs to update ### Firewall
printf "Do you want to set up firewall rules by iptables? [Y/n]: \n" printf "Do you want to set up firewall rules by iptables? [Y/n]: \n"
read ansFirewallSetup read ansFirewallSetup
@ -18,42 +18,27 @@ if [[ "$ansFirewallSetup" =~ ("N"|"n") ]]; then
elif [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then elif [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then
printf "Do you want to block non-VPN ssh connections? [Y/n/castom]: " printf "Do you want to block non-Tailscale ssh connections? [Y/n]: "
read sshBlockRange read sshBlockRange
### needs update from LAN to VPN if [[ "$sshBlockRange" =~ ("n"|"N") ]]; then
if [[ $sshBlockRange =~ ("n"|"N") ]]; then
printf "+ OK, working on next bit\n" printf "If you want input your own IP range [N/range]\n"
ipList="" read sshRange
elif [[ $sshBlockRange =~ ("y"|"Y") || -z $sshBlockRange ]]; then if [[ "$sshRange" =~ ("n"|"N") || -z $sshRange ]]; then
printf "+ Making your SSH connections wide and open. Think about it. /n"
#Pipes all informations about ip interfaces ipList="*"
ipList=$(ip -o -4 a show tailscale0) else
printf "+ Accepting SSH connections only on these ip's: $sshRange\n"
ipList="$sshRange"
fi
#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 fi
### Update ### ### Update
sleep 2 sleep 2
@ -66,14 +51,14 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then
apt install iptables -y apt install iptables -y
fi fi
### User managment ### needs update ### User managment
groupadd minecraft groupadd velocity
useradd --system --shell /usr/sbin/nologin --home /opt/minecraft -g minecraft minecraft useradd --system --shell /usr/sbin/nologin --home /opt/velocity -g velocity velocity
### File structure ### ### File structure
mkdir /opt/velocity mkdir /opt/velocity
@ -82,19 +67,14 @@ mv data/velocity*.jar start.sh /opt/velocity/
mkdir /opt/velocity/plugins mkdir /opt/velocity/plugins
mv data/Ambassador*.jar /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/ mv data/velocity.toml /opt/velocity/
mv data/forwarding.secret /opt/velocity/
### Permisions ### needs update ### Permisions
chown -R godot:godot /opt/velocity/ chown -R velocity:velocity /opt/velocity/
@ -116,7 +96,20 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #Allow continuing connections 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 -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 iptables -L ### Good place to paste a manual check to not lock yourself out
@ -141,6 +134,27 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then
fi fi
fi fi
### tailsclae install ###
printf "Do you want to install Tailscale now? [Y/n]: \n"
read ansTail
if [[ "$ansTail" =~ ("y"|"Y") || -z $ansTail ]]; then
curl -fsSL https://tailscale.com/install.sh | sh
if [[ "$sshBlockRange" =~ ("y"|"Y") || -z $sshBlockRange ]]; then
tailscale up --ssh
else
tailscale up
fi
fi
### Start service ### needs update ### Start service ### needs update
printf "Do you want to start server right now? [Y/n]: \n" printf "Do you want to start server right now? [Y/n]: \n"
@ -154,4 +168,4 @@ systemctl enable mc-forge
### needs update ### needs update
printf "\nsystemctl status mc-forge" printf "\nsystemctl status mc-forge"
printf "\nsu minecraft -s /bin/bash" printf "\nsu velocity -s /bin/bash"