Files
pyMCDPS/server_manager.sh

118 lines
5.6 KiB
Bash
Raw Normal View History

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-15 18:46:12 +02:00
echo " ServerManager"
2024-10-14 18:44:33 +02:00
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
2024-10-15 18:46:12 +02:00
echo " Launch Menu"
2024-10-15 13:45:48 +02:00
echo "------------------------------------------------------------"
read -p "Do you want to start the server? [y/n] " start_answer
if [[ ${eula_answer} == "y" ]]; then
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
echo "Starting Server...."
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
echo "Before starting the server, please accept the EULA"
else
echo "Something went wrong, please recreate the EULA"
fi
2024-10-14 18:44:33 +02:00
else
echo "Before starting the server, please accept the EULA"
fi
elif [[ ${eula_answer} == "n" ]]; then
break
2024-10-14 18:44:33 +02:00
else
echo "Invalid input"
break
fi
2024-10-14 18:44:33 +02:00
read -p "Press Enter to continue..."
break
;;
2024-10-15 13:48:08 +02:00
"Connect to Server")
clear
2024-10-15 18:46:12 +02:00
echo " Connecting to Server"
2024-10-15 13:48:08 +02:00
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
2024-10-15 18:05:03 +02:00
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")
current_date=$(date)
2024-10-14 18:44:33 +02:00
clear
2024-10-15 18:46:12 +02:00
echo " Setting EULA "
2024-10-14 18:44:33 +02:00
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"
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