#!/bin/bash printf "Better to run as root, because of permisions handeling.\n" sleep 2 ### 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 ### Proxy ### printf "Are you planing to use Velocity proxy to acces this server? [Y/n]: \n" read ansVeloProxy if [[ "$ansVeloProxy" =~ ("y"|"Y") || -z $ansVeloProxy ]]; then printf "Do you wish to set up moder forwarding? [Y/n]: \n" read ansModernFarward fi printf "Do you want to set up SkinRestorer [Y/n]: \n" read ansSkinRestorer printf "Do you want to set up PlayerSync [Y/n]: \n" read ansPlayerSync sleep 2 ### Update ### printf "\n+ Starting to upgrade base system\n\n" apt update apt upgrade -y apt autoremove --purge -y ### Installing depandencies ### #TODO Tailscale tunel? printf "\n+ Installing depandencies \n\n" apt install openjdk-21-jre-headless screen p7zip-full -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 ### mkdir /opt/minecraft cd /opt/minecraft/ ### Download forge server ### printf "+ Downloading and installing Forge 1.21.1 \n \n" wget https://maven.neoforged.net/releases/net/neoforged/neoforge/21.1.217/neoforge-21.1.217-installer.jar mv *neoforge*. NeoForge.jar ### Installing server ### java -Xms512M -Xmx2048M -jar NeoForge.jar --installServer ### RAM configuration ### 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" >> user_jvm_args.txt elif [[ -z $maxRam ]]; then $maxRam=4G printf "\n+ Allocating $MaxRam as RAM maximum" echo "-Xmx$maxRam" >> user_jvm_args.txt elif [[ ! "$maxRam" =~ ("G"|"MB") ]]; then printf "\n+ Allocating ${maxRam}G as RAM maximum" echo "-Xmx${maxRam}G" >> 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" >> user_jvm_args.txt elif [[ -z $minRam ]]; then $minRam=1G printf "\n+ Allocating $minRam as RAM minimum" echo "-Xms$minRam" >> user_jvm_args.txt elif [[ ! "$minRam" =~ ("G"|"MB") ]]; then printf "Allocating ${minRam}G as RAM maximum" echo "-Xms${minRam}G" >> 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 ### Other configuraton ### echo eula=true > eula.txt cd - cd data/ mv server-icon.png server.properties /opt/minecraft/ cd /opt/minecraft/ ### Mods handling ### mkdir /opt/minecraft/mods printf "\n+ Unpacking mods \n \n" #TODO Not like this, what about to downlad them cd - cd data 7z x Mods.zip -o/opt/minecraft/mods/ cd /opt/minecraft/ # TODO neoforge now ## adds mode to help comunicate with VeloProxy #if [[ "$ansVeloProxy" =~ ["y"|"Y"] || -z $ansVeloProxy ]]; then # wget https://cdn.modrinth.com/data/vDyrHl8l/versions/jfiEc2mQ/proxy-compatible-forge-1.1.7.jar # mv proxy-compatible-forge*.jar /opt/minecraft/mods/ # # if [[ "$ansModernFarward" =~ ["y"|"Y"] || -z $ansModernFarward ]]; then # mkdir /opt/minecraft/config # mv data/pcf-common.toml /opt/minecraft/config/ #TODO Research this shit # fi #fi # ## adds aditional mods #if [[ "$ansSkinRestorer" =~ ["y"|"Y"] || -z $ansSkinRestorer ]]; then # wget https://mediafilez.forgecdn.net/files/6897/64/skinrestorer-2.4.3%2B1.21-forge.jar # mv skinrestorer*.jar /opt/minecraft/mods/ #fi # #if [[ "$ansPlayerSync" =~ ["y"|"Y"] || -z $ansPlayerSync ]]; then # cd - # # Not using wget because of castom modification to this mod # mv data/playersync-1.21.1.jar /opt/minecraft/mods # cd /opt/minecarft/ # # TODO what abou configuration of this? #fi # ### Permisions ### printf "\n+ Permision handeling\n" chown -R minecraft:minecraft /opt/minecraft ### SystemD service ### printf "+ Preparign systemD service\n" mv data/mc-forge.service /etc/systemd/system/ systemctl daemon-reload ### Error handeling ### if [[ "$minRam" = "Error" || "$maxRam" = "Error" ]]; then printf "\n Encountred some eror in Ram settings" printf "\n Manual configuration needed" printf "\n Open /opt/minecraft/user_jvm_args.txt in your favorite editor. File contains more instructions" 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-forge.serice fi systemctl enable mc-forge 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 "\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"