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
|
|
|
|
# --------------------------------------------------------------------------
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# Imports:
|
2024-10-12 18:20:25 +02:00
|
|
|
|
# --------------------------------------------------------------------------
|
2024-10-13 12:31:41 +02:00
|
|
|
|
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# Sourcing the .env file which contains the server information
|
2024-10-13 12:31:41 +02:00
|
|
|
|
source .env
|
|
|
|
|
|
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
|
# Beginning Of the Script by cerberus
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
2024-10-14 18:44:33 +02:00
|
|
|
|
|
|
|
|
|
|
# Set empty promt
|
|
|
|
|
|
PS3=""
|
|
|
|
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
|
clear
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# Lists all the Options available in the script
|
2024-10-16 16:24:01 +02:00
|
|
|
|
options=("Start Server" "Connect to Server" "Set EULA" "Set RAM" "Install Mods" "Exit")
|
2024-10-15 18:46:12 +02:00
|
|
|
|
echo " ServerManager"
|
2024-10-14 18:44:33 +02:00
|
|
|
|
echo "----------------------------------------------"
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# Selects an option from a list and executes it
|
|
|
|
|
|
select opt in "${options[@]}"; do
|
2024-10-14 18:44:33 +02:00
|
|
|
|
case $opt in
|
|
|
|
|
|
"Start Server")
|
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 "------------------------------------------------------------"
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# Promting before actually starting the server
|
|
|
|
|
|
read -p "Do you want to start the server? [y/n] " start_answer
|
2024-10-16 16:24:01 +02:00
|
|
|
|
# Checks if the EULA file exists
|
2024-10-16 14:43:13 +02:00
|
|
|
|
if [[ ${start_answer} == "y" ]]; then
|
2024-10-16 15:09:08 +02:00
|
|
|
|
if [[ -e "${server}/eula.txt" ]]; then
|
2024-10-16 16:24:01 +02:00
|
|
|
|
# Sets the condition, in this case counting how many lines with eula=true exist in the EULA file
|
2024-10-16 15:09:08 +02:00
|
|
|
|
condition=$(cat "${server}/eula.txt" | grep -c "eula=true")
|
|
|
|
|
|
# If EULA is accepted, start the server
|
|
|
|
|
|
if [[ ${condition} -eq 1 ]]; then
|
2024-10-16 12:21:59 +02:00
|
|
|
|
echo "Starting Server...."
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# Change directory to where the start script is to avoid a tmux error [exited]
|
|
|
|
|
|
# without any other error message
|
|
|
|
|
|
cd "${server}"
|
|
|
|
|
|
# Starts the server detatched in a new session
|
|
|
|
|
|
# To check for sessions tmux ls and to reconnect to an existing one tmux a -t session_name
|
|
|
|
|
|
tmux new -d -s "${server_name}" "./start_server.sh"
|
2024-10-16 16:24:01 +02:00
|
|
|
|
# If EULA is not accepted, tells the user to accept the EULA before
|
2024-10-16 15:09:08 +02:00
|
|
|
|
elif [[ ${condition} -eq 0 ]]; then
|
2024-10-16 12:21:59 +02:00
|
|
|
|
echo "Before starting the server, please accept the EULA"
|
2024-10-16 16:24:01 +02:00
|
|
|
|
# An case that should only appear if more than just one EULA entry was made.
|
|
|
|
|
|
# Either commented or not. This should be easily fixed by accepting the EULA again
|
|
|
|
|
|
# since every action in this menu doesn´t matter if agreed or not, the file gets
|
|
|
|
|
|
# overwritten
|
|
|
|
|
|
# Using "Set EULA" should fix that
|
2024-10-16 12:21:59 +02:00
|
|
|
|
else
|
|
|
|
|
|
echo "Something went wrong, please recreate the EULA"
|
|
|
|
|
|
fi
|
2024-10-16 16:24:01 +02:00
|
|
|
|
# Error massage if the EULA file does not exist. Using "Set EULA" should fix that
|
2024-10-14 18:44:33 +02:00
|
|
|
|
else
|
2024-10-16 12:21:59 +02:00
|
|
|
|
echo "Before starting the server, please accept the EULA"
|
2024-10-16 15:09:08 +02:00
|
|
|
|
echo "error - missing file "eula.txt""
|
|
|
|
|
|
fi
|
2024-10-16 16:24:01 +02:00
|
|
|
|
# If the user prompts n in the server start menu, he returns back to the main menu
|
2024-10-16 14:43:13 +02:00
|
|
|
|
elif [[ ${start_answer} == "n" ]]; then
|
2024-10-16 12:21:59 +02:00
|
|
|
|
break
|
2024-10-16 16:24:01 +02:00
|
|
|
|
# If the user prompts something else than y or n in the server start menu, he returns back to the main menu
|
2024-10-14 18:44:33 +02:00
|
|
|
|
else
|
2024-10-16 12:21:59 +02:00
|
|
|
|
echo "Invalid input"
|
|
|
|
|
|
break
|
2024-10-16 16:24:01 +02:00
|
|
|
|
fi
|
2024-10-16 15:09:08 +02:00
|
|
|
|
read -p "Press Enter to return to the menu"
|
2024-10-14 18:44:33 +02:00
|
|
|
|
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-16 15:33:04 +02:00
|
|
|
|
if tmux has-session -t ${server_name} 2>/dev/null; then
|
|
|
|
|
|
# Attaches to the running tmux session of the server if the session exists
|
|
|
|
|
|
tmux a -t "${server_name}"
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "You need to start the server before trying to connect to it."
|
|
|
|
|
|
read -p "Press Enter to continue..."
|
|
|
|
|
|
fi
|
2024-10-15 13:48:08 +02:00
|
|
|
|
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
|
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 "------------------------------------------------------------"
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# Promts the user if he wants to accept or not accept the minecraft EULA
|
2024-10-15 17:51:08 +02:00
|
|
|
|
read -p "Do you accept the Minecraft EULA? [y/n]: " eula_answer
|
2024-10-16 15:09:08 +02:00
|
|
|
|
# If the user promts yes, the EULA gets created/ overwritten and sets it to true
|
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-16 16:24:01 +02:00
|
|
|
|
# If the user promts no, the EULA gets created/ overwritten and sets it to false.
|
|
|
|
|
|
# User also gets a reminder that he will not be able to start the server without accepting
|
|
|
|
|
|
# to it
|
2024-10-16 15:09:08 +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"
|
2024-10-16 15:09:08 +02:00
|
|
|
|
echo "Caution: You will not be able to start the serverwithout accepting to the EULA."
|
2024-10-14 18:44:33 +02:00
|
|
|
|
else
|
2024-10-16 15:09:08 +02:00
|
|
|
|
echo "Invalid input!"
|
2024-10-14 18:44:33 +02:00
|
|
|
|
fi
|
|
|
|
|
|
read -p "Press Enter to continue..."
|
|
|
|
|
|
break
|
|
|
|
|
|
;;
|
|
|
|
|
|
"Set RAM")
|
2024-10-16 16:24:01 +02:00
|
|
|
|
clear
|
|
|
|
|
|
echo " Allocate RAM "
|
|
|
|
|
|
echo "------------------------------------------------------------"
|
|
|
|
|
|
presets=("1 GB" "2 GB" "4 GB" "8 GB" "16 GB" "Check")
|
|
|
|
|
|
select opt in "${presets[@]}"; do
|
|
|
|
|
|
case $opt in
|
|
|
|
|
|
"1 GB")
|
2024-10-16 16:36:56 +02:00
|
|
|
|
echo "------------------------"
|
|
|
|
|
|
echo "Allocated 1GB of RAM"
|
2024-10-16 16:24:01 +02:00
|
|
|
|
echo "-Xms512M" > "${server}/user_jvm_args.txt"
|
|
|
|
|
|
echo "-Xmx1G" >> "${server}/user_jvm_args.txt"
|
|
|
|
|
|
;;
|
|
|
|
|
|
"2 GB")
|
2024-10-16 16:36:56 +02:00
|
|
|
|
echo "------------------------"
|
|
|
|
|
|
echo "Allocated 2GB of RAM"
|
2024-10-16 16:24:01 +02:00
|
|
|
|
echo "-Xms1G" > "${server}/user_jvm_args.txt"
|
|
|
|
|
|
echo "-Xmx2G" >> "${server}/user_jvm_args.txt"
|
|
|
|
|
|
;;
|
|
|
|
|
|
"4 GB")
|
2024-10-16 16:36:56 +02:00
|
|
|
|
echo "------------------------"
|
|
|
|
|
|
echo "Allocated 4GB of RAM"
|
2024-10-16 16:24:01 +02:00
|
|
|
|
echo "-Xms2G" > "${server}/user_jvm_args.txt"
|
|
|
|
|
|
echo "-Xmx4G" >> "${server}/user_jvm_args.txt"
|
|
|
|
|
|
;;
|
|
|
|
|
|
"8 GB")
|
2024-10-16 16:36:56 +02:00
|
|
|
|
echo "------------------------"
|
|
|
|
|
|
echo "Allocated 8GB of RAM"
|
2024-10-16 16:24:01 +02:00
|
|
|
|
echo "-Xms4G" > "${server}/user_jvm_args.txt"
|
|
|
|
|
|
echo "-Xmx8G" >> "${server}/user_jvm_args.txt"
|
|
|
|
|
|
;;
|
|
|
|
|
|
"16 GB")
|
2024-10-16 16:36:56 +02:00
|
|
|
|
echo "------------------------"
|
|
|
|
|
|
echo "Allocated 16GB of RAM"
|
2024-10-16 16:24:01 +02:00
|
|
|
|
echo "-Xms8G" > "${server}/user_jvm_args.txt"
|
|
|
|
|
|
echo "-Xmx16G" >> "${server}/user_jvm_args.txt"
|
|
|
|
|
|
;;
|
|
|
|
|
|
"Check")
|
2024-10-16 16:36:56 +02:00
|
|
|
|
echo "------------------------"
|
|
|
|
|
|
echo "User Args: "
|
|
|
|
|
|
echo " "
|
2024-10-16 16:24:01 +02:00
|
|
|
|
cat "${server}/user_jvm_args.txt"
|
2024-10-16 16:36:56 +02:00
|
|
|
|
echo " "
|
2024-10-16 16:24:01 +02:00
|
|
|
|
break
|
|
|
|
|
|
;;
|
|
|
|
|
|
*)
|
|
|
|
|
|
echo "invalid input"
|
2024-10-16 16:33:14 +02:00
|
|
|
|
break
|
2024-10-16 16:24:01 +02:00
|
|
|
|
;;
|
|
|
|
|
|
esac
|
|
|
|
|
|
done
|
2024-10-16 16:33:14 +02:00
|
|
|
|
read -p "Press Enter to return to main menu"
|
2024-10-14 18:44:33 +02:00
|
|
|
|
break
|
|
|
|
|
|
;;
|
|
|
|
|
|
"Install Mods")
|
2024-10-16 16:24:01 +02:00
|
|
|
|
clear
|
|
|
|
|
|
echo "Installing mods is not supported yet"
|
2024-10-14 18:44:33 +02:00
|
|
|
|
read -p "Press Enter to continue..."
|
|
|
|
|
|
break
|
|
|
|
|
|
;;
|
|
|
|
|
|
"Exit")
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
;;
|
|
|
|
|
|
*)
|
|
|
|
|
|
echo "Invalid selection. Please try again."
|
|
|
|
|
|
;;
|
|
|
|
|
|
esac
|
|
|
|
|
|
done
|
|
|
|
|
|
done
|