From c9ddec47035076a6b1fa952546b90518f8196b3a Mon Sep 17 00:00:00 2001 From: godot Date: Sat, 20 Jul 2024 08:53:56 +0200 Subject: [PATCH] updat to paper --- README.md | 3 +- data/mc-paper.service | 2 +- data/run.sh | 2 + script.sh | 99 ++++++++++++++++++++++++++++++++++++++----- 4 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 data/run.sh diff --git a/README.md b/README.md index b28da50..d35b51a 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ To switch user use: `su minecraft -s /bin/bash` # To DO -- [ ] Update mc-perfect to mc-paper needs +- [x] Update mc-perfect to mc-paper needs - [ ] test it +- [ ] Addons support??? - [ ] move to Velocity proxy - [ ] manual set up of min/max RAM diff --git a/data/mc-paper.service b/data/mc-paper.service index 1cb4f00..8d9d0ca 100644 --- a/data/mc-paper.service +++ b/data/mc-paper.service @@ -8,7 +8,7 @@ WantedBy=multi-user.target [Service] ExecReload=/usr/bin/screen -S minecraft -X stuff \"reload^M\" -ExecStart=/usr/bin/screen -DmS minecraft ./start.sh +ExecStart=/usr/bin/screen -DmS minecraft ./run.sh ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015' ExecStop=/bin/sh -c '/bin/sleep 5' diff --git a/data/run.sh b/data/run.sh new file mode 100644 index 0000000..05a7907 --- /dev/null +++ b/data/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash + diff --git a/script.sh b/script.sh index a6a8e4b..db066f8 100755 --- a/script.sh +++ b/script.sh @@ -48,21 +48,73 @@ elif [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then fi fi + +### RAM ### + +printf "How much of RAM are you willing to allocate in GB (Max) [4G/?G]: \n" +read maxRam + +printf "How little you want to let RAM go down to in GB (Min) [1G/?G]: \n" +read minRam + +if [[ "$minRam" > "$maxRam" ]]; then + pritf "\n You allocated too low max ram or too much min ram. Manual intervention at the end will be needed\n" + $xmx=$(echo "-Xmx?G") + $maxRam="Error" +elif [[ "$maxRam" =~ ("G"|"M") ]]; then + printf "\n+ Allocating $maxRam as RAM maximum." + $xmx=$(echo "-Xmx$maxRam") +elif [[ -z $maxRam ]]; then + $maxRam=4G + printf "\n+ Allocating $MaxRam as RAM maximum" + $xmx=$(echo "-Xmx$maxRam") +elif [[ ! "$maxRam" =~ ("G"|"MB") ]]; then + printf "\n+ Allocating ${maxRam}G as RAM maximum" + $xmx=$(echo "-Xmx${maxRam}G") +else + pritnf "\n \n!!! Sorry I have no idea what are you trying to do :/ Manual intervention will be needed at the end \n" + $maxRam="Error" + $xmx=$(echo "-Xmx?G") + +fi + + +if [[ "$minRam" > "$maxRam" ]]; then + $xms=$(echo "-Xms?G") +elif [[ "$minRam" =~ ("G"|"M") ]]; then + printf "\n+ Allocating $minRam as RAM minimum." + $xms=$(echo "-Xms$minRam") +elif [[ -z $minRam ]]; then + $minRam=1G + printf "\n+ Allocating $minRam as RAM minimum" + $xms=$(echo "-Xms$minRam") +elif [[ ! "$minRam" =~ ("G"|"MB") ]]; then + printf "Allocating ${minRam}G as RAM maximum" + $xms=$(echo "-Xms${minRam}G") +else + pritnf "\n!!! Sorry I have no idea what are you trying to do :/ Manual intervention will be needed at the end \n" + $minRam="Error" + $xms=$(echo "-Xms?G") +fi + +echo "java ${xmx} ${xms} -jar paper-1.20.6-148.jar --nogui" >> data/run.sh + + sleep 2 # Just to be shure printf "\n+ Starting to upgrade base system\n\n" -sudo apt update -sudo apt upgrade -y +apt update +apt upgrade -y # Installing depandencies printf "\n+ Installing depandencies \n\n" -sudo apt install openjdk-21-jre-headless screen -y +apt install openjdk-21-jre-headless screen -y if [[ "$ansFirewallSetup" =~ ("y"|"Y") || -z $ansFirewallSetup ]]; then - sudo apt install iptables -y + apt install iptables -y fi @@ -85,10 +137,14 @@ printf "+ Installing Paper 1.20.6 \n \n" java -Xms512M -Xmx2048M -jar paper-1.20.6-148.jar --nogui +rm eula.txt server.properties + cd - cd data/ -mv eula.txt server-icon.png server.properties user_jvm_args.txt /opt/minecraft/ + +mv eula.txt server-icon.png server.properties run.sh /opt/minecraft/ + cd .. ### Addons support??? @@ -110,8 +166,6 @@ printf "+ Preparign systemD service\n" mv data/mc-paper.service /etc/systemd/system/ systemctl daemon-reload -systemctl start mc-paper -systemctl enable mc-paper # integration of Maxopoly's instructions on firewall @@ -133,7 +187,7 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then iptables -L ### Good place to paste a manual check to not lock yourself out printf "\n Does it looks right? [Y/n]: " - read ansFirewallOK + read ansFirew`allOK if [[ "$ansFirewallOK" =~ ("Y"|"y") || -z "$ansFirewallOK" ]]; then @@ -143,7 +197,7 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then iptables -P OUTPUT ACCEPT #Allow all outgouing - sudo apt install iptables-persistent -y + apt install iptables-persistent -y else @@ -155,7 +209,32 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then fi + ### Error handeling ### +if [[ "$minRam" = "Error" || "$maxRam" = "Error" ]]; then + + printf "\n Encountred some eror in Ram settings. Manual configuration needed" + printf "\n Open /opt/minecraft/run.sh in your favorite editor. File contains more instructions" + printf "\n After manual interventing all erorrs start server with: systemctl start mc-paper" + printf "\n Automatic start of server you can enable by: systemctl enable mc-paper" + + echo "# In place of ? write number of RAM you want to allocate" >> /opt/minecraft/run.sh + echo "# You can always change this number. Remamber to restart server after it" >> /opt/minecraft/run.sh + +else + + printf "Do you want to start server right now? [Y/n]: \n" + read startServer + + if [[ "$startServer" =~ ("y"|"Y") || -z $startServer ]]; then + systemctl start mc-paper.serice + fi + + systemctl enable mc-paper + +fi + + printf "\n+ Done, thanks for your time. It is goode idea to chack if everythink is alright by running:" -printf "\nsystemctl status mc-forge" +printf "\nsystemctl status mc-paper" printf "\nsu minecraft -s /bin/bash" printf "\n+ it is good idea to have some fun with screen before trying to open minecraft conesole 'screen -r' while loged wia minecraft user"