From 4ce9c4031b7361f335ceab504c98b9926f2897cb Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sat, 31 Jul 2021 19:19:21 -0500 Subject: [PATCH] Updated Usage function --- CentOS/Minecraft/Minecraft-Start-Server.bash | 46 +++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/CentOS/Minecraft/Minecraft-Start-Server.bash b/CentOS/Minecraft/Minecraft-Start-Server.bash index 3c2c9de..1f2da4c 100755 --- a/CentOS/Minecraft/Minecraft-Start-Server.bash +++ b/CentOS/Minecraft/Minecraft-Start-Server.bash @@ -9,7 +9,7 @@ MAX_MEM=8 INITIAL_MEM=2 #rcon password -DEFAULT_RCON_PASSWORD="" +DEFAULT_RCON_PASSWORD="bqMLwxCJKRktrQoir2pg4KkTeBDQLjb4C+RYesdmeKF4sie8" echo_rgb() { # Echo a colored string to the terminal based on rgb values @@ -164,19 +164,27 @@ usage() { # POSIX Compliant: # Yes # - printf "Usage: %s%s\n" \ - "$(basename ${0}) " \ - " - -i \"this is some input\" -t \"this is some more example input\" - --input | -i + printf "Usage: %s\n" \ + "$(basename "${0}") -s | $(basename "${0}") -s -r | $(basename "${0}") -s -j + --server -s + Which minecraft server to start, see the ~/Minecraft directory -- each number corresponds to an ID + Example: - --input \"this is an example input\" - --test | -t + --server 1 + --r | --rcon-ignore + Flag that takes no parameters -- when enabled this script will not overwrite the RCON password in the targeted server + Example: - --test \"this is more example input\"" + --rcon-ignore + --jar | -j + Takes in a path to a minecraft server jar file. It copies that file to create the new server + + Example: + --jar ~/Minecraft-Server-Jars/minecraft_server1.17.1.jar" } + server_id="" minecraft_jar="" rcon_ignore=0 @@ -235,16 +243,20 @@ parse_args "$@" minecraft_directory=~/Minecraft/Server-"${server_id}" -mkdir -p "${minecraft_directory}" -mkdir -p "${minecraft_directory}/backups" +create_directories() { + mkdir -p "${minecraft_directory}" + mkdir -p "${minecraft_directory}/backups" + cd "${minecraft_directory}" || (log "error" "Unable to change directory to ${minecraft_directory}" && exit 1) +} -cd "${minecraft_directory}" || (log "error" "Unable to change directory to ${minecraft_directory}" && exit 1) +create_directories if [ -n "${minecraft_jar}" ]; then if [ ! -f "${minecraft_jar}" ]; then log "error" "Could not find a minecraft server jar \"${minecraft_jar}\"" exit 1 fi + minecraft_jar_name="$(basename "${minecraft_jar}")" log "info" "Copying minecraft server files..." cp "${minecraft_jar}" "${minecraft_directory}" \ @@ -253,8 +265,8 @@ if [ -n "${minecraft_jar}" ]; then log "info" "Installed a minecraft server.jar to Minecraft-Server-${server_id}" java -jar "${minecraft_directory}"/server.jar > /dev/null 2>&1 log "info" "Successfully installed the minecraft server.jar to Minecraft-Server-${server_id}, continuing with setup" -elif [ ! -d "${minecraft_directory}" ]; then - log "error" "The minecraft server \"${minecraft_directory}\" did not exist, to create it please pass the \"--jar\" flag..." +elif [ ! -f "${minecraft_directory}"/server.jar ]; then + log "error" "No server.jar found within ${minecraft_directory}, to create a new server there use the \"--jar\" flag" exit 1 fi @@ -326,4 +338,8 @@ log "info" "Starting Minecraft-Server-${server_id}" tmux new-session -d -s \ "Minecraft-Server-${server_id}" \ java -Xms"${INITIAL_MEM}G" -Xmx"${MAX_MEM}G" -jar server.jar --nogui \ - && log "info" "Server Minecraft-Server-${server_id} started successfully!" + && log "info" \ +"Server Minecraft-Server-${server_id} started successfully: + Game Port: ${server_port} + Query Port: ${query_port} + RCON Port: ${rcon_port}"