From 9137a8faa999070048d6ca06161da041f8c12168 Mon Sep 17 00:00:00 2001 From: godot Date: Fri, 19 Jul 2024 09:24:39 +0200 Subject: [PATCH] RAM integration --- script.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/script.sh b/script.sh index 25ddf0f..9a649e0 100755 --- a/script.sh +++ b/script.sh @@ -4,6 +4,8 @@ printf "Better to run as root, because of permisions handeling.\n" sleep 2 +### Firewall ### + printf "Do you want to set up firewall rules by iptables? [Y/n]: \n" read ansFirewallSetup @@ -48,15 +50,68 @@ else 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" + echo "-Xmx?G # in place of ? put number of RAM you want to set ass maximum" + $maxRam="Error" +elif [[ "$maxRam" =~ ("G"|"M") ]]; then + printf "\n+ Allocating $maxRam as RAM maximum." + echo "-Xmx$maxRam" >> data/user_jvm_args.txt +elif [[ -z $maxRam ]]; then + $maxRam=4G + printf "\n+ Allocating $MaxRam as RAM maximum" + echo "-Xmx$maxRam" >> data/user_jvm_args.txt +elif [[ ! "$maxRam" =~ ("G"|"MB") ]]; then + printf "\n+ Allocating ${maxRam}G as RAM maximum" + echo "-Xmx${maxRam}G" >> data/user_jvm_args.txt +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" + echo "-Xmx?G # in place of ? put number of RAM you want to set ass maximum" + +fi + + +if [[ "$minRam" > "$maxRam" ]]; then + echo "-Xms?G # in place of ? put number of RAM you want to se ass minimum" +elif [[ "$minRam" =~ ("G"|"M") ]]; then + printf "\n+ Allocating $minRam as RAM minimum." + echo "-Xms$minRam" >> data/user_jvm_args.txt +elif [[ -z $minRam ]]; then + $minRam=1G + printf "\n+ Allocating $minRam as RAM minimum" + echo "-Xms$minRam" >> data/user_jvm_args.txt +elif [[ ! "$minRam" =~ ("G"|"MB") ]]; then + printf "Allocating ${minRam}G as RAM maximum" + echo "-Xms${minRam}G" >> data/user_jvm_args.txt +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" + echo "-Xms?G # in place of ? put number of RAM you want to set ass minimum" +fi + + + + sleep 2 -# Just to be shure +### Update ### + printf "\n+ Starting to upgrade base system\n\n" sudo apt update sudo apt upgrade -y -# Installing depandencies +### Installing depandencies ### + printf "\n+ Installing depandencies \n\n" sudo apt install openjdk-17-jre-headless screen p7zip-full -y @@ -66,20 +121,20 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z $ansFirewallSetup ]]; then fi -# User and groupe managment +### 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 +### File strukture ### mkdir /opt/minecraft mv data/Forge-1.20.1.jar /opt/minecraft/ cd /opt/minecraft/ -# Installing server +### Installing server ### printf "+ Installing Forge 1.20.1 \n \n" java -Xms512M -Xmx2048M -jar Forge-1.20.1.jar --installServer @@ -98,20 +153,17 @@ cd data 7z x Mods.zip -o/opt/minecraft/mods/ cd .. -# Permision handeling +### Permisions ### printf "\n+ Permision handeling\n" chown -R minecraft:minecraft /opt/minecraft -# SystemD service +### SystemD service ### printf "+ Preparign systemD service\n" mv data/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 +### integration of Maxopoly's instructions on firewall ### if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then @@ -148,9 +200,17 @@ if [[ "$ansFirewallSetup" =~ ("Y"|"y") || -z "$ansFirewallSetup" ]]; then 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 + ### Error handeling ### +if [[ "$minRam" = "Error" || "$maxRam" = "Error" ]]; then - + printf "\n Encountred some eror in Ram settings" + pritnf "\n Manual configuration needed" + printf "\n Open /opt/minecraft/user_jvm_args.txt in your favorite editor. File contains more instructions" +else + systemctl start mc-forge.service + systemctl enable mc-forge fi printf "\n+ Done, thanks for your time. It is goode idea to chack if everythink is alright by running:"