2024-10-12 18:20:25 +02:00
#!/bin/bash
# Script in strict mode
2024-10-14 18:44:33 +02:00
set -eu
2024-10-12 18:20:25 +02:00
# --------------------------------------------------------------------------
# Imports
# --------------------------------------------------------------------------
2024-10-13 12:31:41 +02:00
# Beginning Of the Script by cerberus
2024-10-14 18:44:33 +02:00
#cat <<EOF
# __ __ _
#| \/ | __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_
#| |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '_ ` _ \ / _ \ '_ \| __|
#| | | | (_| | | | | (_| | (_| | __/ | | | | | __/ | | | |_
#|_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__|
# |___/
#EOF
2024-10-13 12:31:41 +02:00
source .env
2024-10-14 18:44:33 +02:00
# cat .env
# Set empty promt
PS3 = ""
while true; do
clear
# Optionen definieren
2024-10-15 18:05:03 +02:00
options = ( "Start Server" "Connect to Server" "Set EULA" "Set RAM" "Install Mods" "Exit" ) # Lists all the Options available in the script
2024-10-14 18:44:33 +02:00
echo "ServerManager"
echo "----------------------------------------------"
2024-10-15 18:05:03 +02:00
select opt in " ${ options [@] } " ; do # Selects an option from a list and then does this
2024-10-14 18:44:33 +02:00
case $opt in
"Start Server" )
2024-10-15 18:05:03 +02:00
# Add an interaction Do you want to start the server y/n, so he is not starting
# right away.
2024-10-15 13:45:48 +02:00
clear
echo "Launch Menu"
echo "------------------------------------------------------------"
2024-10-15 18:05:03 +02:00
if [ [ -e " ${ server } /eula.txt " ] ] ; then # Checks if the EULA file exists
condition = $( cat " ${ server } /eula.txt " | grep -c "eula=true" ) # Sets the condition, in this case counting how many lines with eula=true exist in the EULA file
if [ [ ${ condition } -eq 1 ] ] ; then # If EULA is accepted, start the server
2024-10-14 18:44:33 +02:00
echo "Starting Server...."
2024-10-15 18:05:03 +02:00
cd " ${ server } " # Change directory to where the start script is to avoid a tmux exit
tmux new -d -s " ${ server_name } " "./start_server.sh" # Starts the server detatched in a new session
elif [ [ ${ condition } -eq 0 ] ] ; then # If EULA is not accepted, start the server
2024-10-14 18:44:33 +02:00
echo "Before starting the server, please accept the EULA"
else
echo "Something went wrong, please recreate the EULA"
fi
else
echo "Before starting the server, please accept the EULA"
fi
read -p "Press Enter to continue..."
break
; ;
2024-10-15 13:48:08 +02:00
"Connect to Server" )
clear
echo "Launch Menu"
echo "------------------------------------------------------------"
2024-10-15 18:05:03 +02:00
# Add a chck before connecting to the session if the session already exists
# if not promt the user to start it manually
tmux a -t " ${ server_name } " # Attaches to the running tmux session of the server if the session exists
2024-10-15 13:48:08 +02:00
read -p "Press Enter to continue..."
break
; ;
2024-10-14 18:44:33 +02:00
"Set EULA" )
2024-10-15 13:11:33 +02:00
current_date = $( date)
2024-10-14 18:44:33 +02:00
clear
echo " Setting EULA "
echo "------------------------------------------------------------"
2024-10-15 17:51:08 +02:00
echo "In order to start an minecraft Server you have to accept it."
echo "You can find more information here: "
echo "https://www.minecraft.net/en-us/eula "
echo "------------------------------------------------------------"
read -p "Do you accept the Minecraft EULA? [y/n]: " eula_answer
2024-10-14 18:44:33 +02:00
if [ [ ${ eula_answer } = = "y" ] ] ; then
echo " # ${ current_date } " > " ${ server } /eula.txt "
echo "eula=true" >> " ${ server } /eula.txt "
2024-10-15 18:05:03 +02:00
elif [ [ ${ eula_answer } = = "n" ] ] ; then
2024-10-14 18:44:33 +02:00
echo " # ${ current_date } " > " ${ server } /eula.txt "
echo "eula=false" >> " ${ server } /eula.txt "
echo "You will not be able to start the server!"
else
echo "Invalid input"
fi
read -p "Press Enter to continue..."
break
; ;
"Set RAM" )
echo "Setting RAM..."
read -p "Press Enter to continue..."
break
; ;
"Install Mods" )
echo "Installing mods..."
read -p "Press Enter to continue..."
break
; ;
"Exit" )
echo "Exiting script. Goodbye!"
exit 0
; ;
*)
echo "Invalid selection. Please try again."
; ;
esac
done
done