From 53e36756a47660a73cc8ad0fe06b1b2127051c24 Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 12:26:35 -0600 Subject: [PATCH 01/22] Prepare server settings to allow for multiple server versions and update comments --- minecraft_server | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/minecraft_server b/minecraft_server index f689de9..9b897c5 100755 --- a/minecraft_server +++ b/minecraft_server @@ -160,19 +160,11 @@ CURRENT_VERSION=$( # Minecraft Server Settings # --------------------------------------------------------------------------- -# Choose only one server distribution, leave the other commented out. +# Default settings if not provided in the world's server.properties file. -# Default Mojang server distribution. -SERVER_JAR="minecraft_server.jar" +SERVER_JAR="minecraft_server.$CURRENT_VERSION.jar" SERVER_URL="https://s3.amazonaws.com/Minecraft.Download/versions/$CURRENT_VERSION/minecraft_server.$CURRENT_VERSION.jar" SERVER_ARGS="nogui" - -# CraftBukkit server distribution. -# SERVER_URL="http://dl.bukkit.org/latest-rb/craftbukkit.jar" -# SERVER_JAR="craftbukkit.jar" -# SERVER_ARGS="" - -# Generic server options. INITIAL_MEMORY="128M" MAXIMUM_MEMORY="2048M" SERVER_LOCATION="$LOCATION/minecraft_server" From 46191d72a24067742aa6adc125e6ceafb8238ce0 Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 12:29:32 -0600 Subject: [PATCH 02/22] Prepare server settings to allow for multiple server versions and update comments --- minecraft_server | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/minecraft_server b/minecraft_server index f689de9..9b897c5 100755 --- a/minecraft_server +++ b/minecraft_server @@ -160,19 +160,11 @@ CURRENT_VERSION=$( # Minecraft Server Settings # --------------------------------------------------------------------------- -# Choose only one server distribution, leave the other commented out. +# Default settings if not provided in the world's server.properties file. -# Default Mojang server distribution. -SERVER_JAR="minecraft_server.jar" +SERVER_JAR="minecraft_server.$CURRENT_VERSION.jar" SERVER_URL="https://s3.amazonaws.com/Minecraft.Download/versions/$CURRENT_VERSION/minecraft_server.$CURRENT_VERSION.jar" SERVER_ARGS="nogui" - -# CraftBukkit server distribution. -# SERVER_URL="http://dl.bukkit.org/latest-rb/craftbukkit.jar" -# SERVER_JAR="craftbukkit.jar" -# SERVER_ARGS="" - -# Generic server options. INITIAL_MEMORY="128M" MAXIMUM_MEMORY="2048M" SERVER_LOCATION="$LOCATION/minecraft_server" From 5f5d4f7d33714d9f5daa59de0f4bb816b103618d Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 12:56:43 -0600 Subject: [PATCH 03/22] Move the check for the server software into the start method --- minecraft_server | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/minecraft_server b/minecraft_server index 9b897c5..b73909f 100755 --- a/minecraft_server +++ b/minecraft_server @@ -657,6 +657,11 @@ syncMirrorImage() { # --------------------------------------------------------------------------- start() { local PID WORLD_DIR + # Make sure that the server software exists. + if [ ! -e "$SERVER_LOCATION/$SERVER_JAR" ]; then + printf "Server software not found, downloading it...\n" + updateServerSoftware "$1" + fi # Make sure that the world's directory exists. WORLD_DIR="$WORLDS_LOCATION/$1" execute "mkdir -p $WORLD_DIR" $USER_NAME @@ -1152,12 +1157,6 @@ if [ $(id -u) -ne 0 ] && [ "$(whoami)" != "$USER_NAME" ]; then exit 1 fi -# Make sure that the server software exists. -if [ ! -e "$SERVER_LOCATION/$SERVER_JAR" ]; then - printf "Server software not found, downloading it...\n" - updateServerSoftware -fi - # Grab the list of worlds. ALL_WORLDS=$(getWorlds) From ef9f3a92d071ca0f81f3c71952cb102c415d4c0a Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 13:09:11 -0600 Subject: [PATCH 04/22] Simplify the updateServerSoftware method --- minecraft_server | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/minecraft_server b/minecraft_server index b73909f..d6d695e 100755 --- a/minecraft_server +++ b/minecraft_server @@ -811,19 +811,14 @@ updateClientSoftware() { # --------------------------------------------------------------------------- updateServerSoftware() { execute "mkdir -p $SERVER_LOCATION" $USER_NAME - # Backup the old jar file. - if [ -e "$SERVER_LOCATION/$SERVER_JAR" ]; then - execute "mv -f \"$SERVER_LOCATION/$SERVER_JAR\" \"$SERVER_LOCATION/$SERVER_JAR.old\"" $USER_NAME - fi - # Download the new minecraft server software. - execute "$WGET -qO \"$SERVER_LOCATION/$SERVER_JAR\" \"$SERVER_URL\"" $USER_NAME - # Check for error and restore backup if found. - if [ $? -ne 0 ]; then - printf "\nError updating the Minecraft server software.\n" - if [ -e "$SERVER_LOCATION/$SERVER_JAR.old" ]; then - execute "mv -f $SERVER_LOCATION/$SERVER_JAR.old $SERVER_LOCATION/$SERVER_JAR" $USER_NAME + if [ ! -e "$SERVER_LOCATION/$SERVER_JAR" ]; then + # Download the new minecraft server software. + execute "$WGET -qO \"$SERVER_LOCATION/$SERVER_JAR\" \"$SERVER_URL\"" $USER_NAME + # Report any errors. + if [ $? -ne 0 ]; then + printf "\nError updating the Minecraft server software.\n" + exit 1 fi - exit 1 fi } From 72945fb33ba8ff1ea733aef341633afea3aff780 Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 13:20:59 -0600 Subject: [PATCH 05/22] Update the software for each world server, patch 1 --- minecraft_server | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/minecraft_server b/minecraft_server index d6d695e..a7583a9 100755 --- a/minecraft_server +++ b/minecraft_server @@ -112,8 +112,9 @@ Options: Run the Minecraft Overviewer mapping software on the Minecraft world. Map all worlds by default. - update - Update the client and server software. + update + Update the server software for the Minecraft world server. Update + server software for all worlds by default. EOF ) @@ -1458,9 +1459,18 @@ case "$1" in printf ".\n" ;; update) + # Figure out which worlds to update. + WORLDS="$ALL_WORLDS" + if [ -n "$2" ] && [ $(listContains "$2" "$ALL_WORLDS") -eq 1 ]; then + WORLDS="$2" + elif [ -n "$2" ]; then + printf "World '$2' not recognized.\n" + printf " Usage: $0 $1 \n" + exit 1 + fi # Stop all of the world servers and backup the worlds. printf "Stopping Minecraft Server:" - for WORLD in $ALL_WORLDS; do + for WORLD in $WORLDS; do if [ $(serverRunning $WORLD) -eq 1 ]; then printf " $WORLD" if [ $(printf "%d" $(queryStatus $WORLD | cut -f6)) -gt 0 ]; then @@ -1476,21 +1486,20 @@ case "$1" in done printf ".\n" printf "Backing up Minecraft Server:" - for WORLD in $ALL_WORLDS; do + for WORLD in $WORLDS; do printf " $WORLD" worldBackup $WORLD done printf ".\n" - printf "Updating software package:" - # Update the client software. - printf " client" - updateClientSoftware # Update the server software. - printf " server" - updateServerSoftware + printf "Updating Server Software:" + for WORLD in $WORLDS; do + printf " $WORLD" + updateServerSoftware "$WORLD" + done printf ".\n" printf "Restarting Minecraft Server:" - for WORLD in $ALL_WORLDS; do + for WORLD in $WORLDS; do printf " $WORLD" start $WORLD done From f3380107049d90e16511880c253605ab0c1f07ac Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 13:25:40 -0600 Subject: [PATCH 06/22] Remove duplicate check for the server software --- minecraft_server | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/minecraft_server b/minecraft_server index a7583a9..89b347a 100755 --- a/minecraft_server +++ b/minecraft_server @@ -659,10 +659,7 @@ syncMirrorImage() { start() { local PID WORLD_DIR # Make sure that the server software exists. - if [ ! -e "$SERVER_LOCATION/$SERVER_JAR" ]; then - printf "Server software not found, downloading it...\n" - updateServerSoftware "$1" - fi + updateServerSoftware "$1" # Make sure that the world's directory exists. WORLD_DIR="$WORLDS_LOCATION/$1" execute "mkdir -p $WORLD_DIR" $USER_NAME From cd981a13358abff9c2676f27471079e24a9a31ed Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 18:21:01 -0600 Subject: [PATCH 07/22] Retrieve world specific values from the server.properties file if provided --- minecraft_server | 112 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 104 insertions(+), 8 deletions(-) diff --git a/minecraft_server b/minecraft_server index db8d6b5..9da5874 100755 --- a/minecraft_server +++ b/minecraft_server @@ -163,13 +163,13 @@ CURRENT_VERSION=$( # --------------------------------------------------------------------------- # Default settings if not provided in the world's server.properties file. -SERVER_JAR="minecraft_server.$CURRENT_VERSION.jar" -SERVER_URL="https://s3.amazonaws.com/Minecraft.Download/versions/$CURRENT_VERSION/minecraft_server.$CURRENT_VERSION.jar" -SERVER_ARGS="nogui" -INITIAL_MEMORY="128M" -MAXIMUM_MEMORY="2048M" -SERVER_LOCATION="$LOCATION/minecraft_server" -SERVER_COMMAND="$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGS" +DEFAULT_SERVER_JAR='minecraft_server.$CURRENT_VERSION.jar' +DEFAULT_SERVER_URL='https://s3.amazonaws.com/Minecraft.Download/versions/$CURRENT_VERSION/minecraft_server.$CURRENT_VERSION.jar' +DEFAULT_SERVER_ARGS='nogui' +DEFAULT_INITIAL_MEMORY='128M' +DEFAULT_MAXIMUM_MEMORY='2048M' +DEFAULT_SERVER_LOCATION=$LOCATION'/minecraft_server' +DEFAULT_SERVER_COMMAND='$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGS' # Minecraft Client Settings @@ -537,6 +537,94 @@ setPropertiesValue() { fi } +# --------------------------------------------------------------------------- +# Retrieve the properties for the world. +# +# @param 1 The world server to parse a string for. +# @return SERVER_VERSION SERVER_JAR SERVER_LOCATION SERVER_URL SERVER_COMMAND +# --------------------------------------------------------------------------- +getWorldProperties() { + local SERVER_VERSION SERVER_JAR SERVER_LOCATION SERVER_URL SERVER_ARGS INITIAL_MEMORY MAXIMUM_MEMORY SERVER_COMMAND + # Get the server version, use the current version if not provided. + SERVER_VERSION=$( + getPropertiesValue "$1" "mscs-server-version" $CURRENT_VERSION | + $PERL -ne ' + $current_version="'$CURRENT_VERSION'"; + $_ =~ s/\$CURRENT_VERSION/$current_version/g; + print; + ' + ) + # Get the server jar, use the default value if not provided. + SERVER_JAR=$( + getPropertiesValue "$1" "mscs-server-jar" $DEFAULT_SERVER_JAR | + $PERL -ne ' + $current_version="'$CURRENT_VERSION'"; + $server_version="'$SERVER_VERSION'"; + $_ =~ s/\$CURRENT_VERSION/$current_version/g; + $_ =~ s/\$SERVER_VERSION/$server_version/g; + print; + ' + ) + # Get the server location, use the default value if not provided. + SERVER_LOCATION=$( + getPropertiesValue "$1" "mscs-server-location" $DEFAULT_SERVER_LOCATION | + $PERL -ne ' + $current_version="'$CURRENT_VERSION'"; + $server_version="'$SERVER_VERSION'"; + $_ =~ s/\$CURRENT_VERSION/$current_version/g; + $_ =~ s/\$SERVER_VERSION/$server_version/g; + print; + ' + ) + # Get the server download URL, use the default value if not provided. + SERVER_URL=$( + getPropertiesValue "$1" "mscs-server-url" $DEFAULT_SERVER_URL | + $PERL -ne ' + $current_version="'$CURRENT_VERSION'"; + $server_version="'$SERVER_VERSION'"; + $_ =~ s/\$CURRENT_VERSION/$current_version/g; + $_ =~ s/\$SERVER_VERSION/$server_version/g; + print; + ' + ) + # Get the server agruments, use the default value if not provided. + SERVER_ARGS=$( + getPropertiesValue "$1" "mscs-server-args" $DEFAULT_SERVER_ARGS + ) + # Get the initial memory, use the default value if not provided. + INITIAL_MEMORY=$( + getPropertiesValue "$1" "mscs-initial-memory" $DEFAULT_INITIAL_MEMORY + ) + # Get the maximum memory, use the default value if not provided. + MAXIMUM_MEMORY=$( + getPropertiesValue "$1" "mscs-maximum-memory" $DEFAULT_MAXIMUM_MEMORY + ) + # Get the server command, use the default value if not provided. + SERVER_COMMAND=$( + getPropertiesValue "$1" "mscs-server-command" $DEFAULT_SERVER_COMMAND | + $PERL -ne ' + $java = "'$JAVA'"; + $current_version = "'$CURRENT_VERSION'"; + $server_version = "'$SERVER_VERSION'"; + $server_jar = "'$SERVER_JAR'"; + $server_location = "'$SERVER_LOCATION'"; + $server_args = "'$SERVER_ARGS'"; + $initial_memory = "'$INITIAL_MEMORY'"; + $maximum_memory = "'$MAXIMUM_MEMORY'"; + $_ =~ s/\$JAVA/$java/g; + $_ =~ s/\$CURRENT_VERSION/$current_version/g; + $_ =~ s/\$SERVER_VERSION/$server_version/g; + $_ =~ s/\$SERVER_JAR/$server_jar/g; + $_ =~ s/\$SERVER_LOCATION/$server_location/g; + $_ =~ s/\$SERVER_ARGS/$server_args/g; + $_ =~ s/\$INITIAL_MEMORY/$initial_memory/g; + $_ =~ s/\$MAXIMUM_MEMORY/$maximum_memory/g; + print; + ' + ) + echo "$SERVER_VERSION\t$SERVER_JAR\t$SERVER_LOCATION\t$SERVER_URL\t$SERVER_COMMAND" +} + # --------------------------------------------------------------------------- # Send a message to the desktop using lib-notify, if it is available. # @@ -661,7 +749,7 @@ syncMirrorImage() { # @param 1 The world server to start. # --------------------------------------------------------------------------- start() { - local PID WORLD_DIR + local PID SERVER_COMMAND WORLD_DIR # Make sure that the server software exists. updateServerSoftware "$1" # Make sure that the world's directory exists. @@ -692,6 +780,7 @@ start() { # Change to the world's directory. cd $WORLD_DIR # Start the server. + SERVER_COMMAND=$(getWorldProperties "$1" | cut -f5) execute "$SCREEN -dmS minecraft-$1 $SERVER_COMMAND" $USER_NAME if [ $? -ne 0 ]; then printf "Error starting the server.\n" @@ -812,8 +901,15 @@ updateClientSoftware() { # --------------------------------------------------------------------------- # Update the Minecraft server software. +# +# @param 1 The world server to update. # --------------------------------------------------------------------------- updateServerSoftware() { + local WORLD_PROPERTIES SERVER_JAR SERVER_LOCATION SERVER_URL + WORLD_PROPERTIES=$(getWorldProperties "$1") + SERVER_JAR=$(echo "$WORLD_PROPERTIES" | cut -f2) + SERVER_LOCATION=$(echo "$WORLD_PROPERTIES" | cut -f3) + SERVER_URL=$(echo "$WORLD_PROPERTIES" | cut -f4) execute "mkdir -p $SERVER_LOCATION" $USER_NAME if [ ! -e "$SERVER_LOCATION/$SERVER_JAR" ]; then # Download the new minecraft server software. From bb2453c712c621f4b5992b0a937fc085f7a08c0f Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 20:44:57 -0600 Subject: [PATCH 08/22] Remove a backslash from the URL. --- minecraft_server | 1 + 1 file changed, 1 insertion(+) diff --git a/minecraft_server b/minecraft_server index 9da5874..d10d866 100755 --- a/minecraft_server +++ b/minecraft_server @@ -584,6 +584,7 @@ getWorldProperties() { $server_version="'$SERVER_VERSION'"; $_ =~ s/\$CURRENT_VERSION/$current_version/g; $_ =~ s/\$SERVER_VERSION/$server_version/g; + $_ =~ s/\\\:/\:/g; print; ' ) From a2ddedfd08e80f25f67e3bc94cfe373eff391210 Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 21:12:01 -0600 Subject: [PATCH 09/22] Add comments on customizing the server.properties file --- minecraft_server | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/minecraft_server b/minecraft_server index d10d866..e57d1bc 100755 --- a/minecraft_server +++ b/minecraft_server @@ -171,6 +171,39 @@ DEFAULT_MAXIMUM_MEMORY='2048M' DEFAULT_SERVER_LOCATION=$LOCATION'/minecraft_server' DEFAULT_SERVER_COMMAND='$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGS' +# The server settings for each world can be customized by adding certain +# key/value pairs to the world's server.properties file. +# +# The following keys are available: +# mscs-server-version - Assign the version of the server to run. +# mscs-server-jar - Assign the .jar file for the server to run. +# mscs-server-url - Assign the download URL for the server software. +# mscs-server-args - Assign the arguments to the server. +# mscs-initial-memory - Assign the initial amount of memory for the server. +# mscs-maximum-memory - Assign the maximum amount of memory for the server. +# mscs-server-location - Assign the location of the server .jar file. +# mscs-server-command - Assign the command to run for the server. +# +# The following variables may be used in some of the values of the above +# keys: +# $JAVA - The Java virtual machine. +# $CURRENT_VERSION - The current Mojang Minecraft release version. +# $SERVER_VERSION - The version of the server that will be run. +# $SERVER_JAR - The .jar file to run for the server. +# $SERVER_ARGS - The arguments to the server. +# $INITIAL_MEMORY - The initial amount of memory for the server. +# $MAXIMUM_MEMORY - The maximum amount of memory for the server. +# $SERVER_LOCATION - The location of the server .jar file. +# +# The following example key/value pairs are equivalent to the default values: +# mscs-server-version=$CURRENT_VERSION +# mscs-server-jar=minecraft_server.$CURRENT_VERSION.jar +# mscs-server-args=nogui +# mscs-initial-memory=128M +# mscs-maximum-memory=2048M +# mscs-server-location=/home/minecraft/minecraft_server +# mscs-server-command=$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERVER_LOCATION/$SERVER_JAR $SERVER_ARGS + # Minecraft Client Settings # --------------------------------------------------------------------------- From 58b8b8e87c01d6d316fa3a65ae32a73c6be84acb Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Fri, 1 Nov 2013 21:35:17 -0600 Subject: [PATCH 10/22] Add quotes around the default values --- minecraft_server | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/minecraft_server b/minecraft_server index e57d1bc..b9aaaf6 100755 --- a/minecraft_server +++ b/minecraft_server @@ -580,7 +580,7 @@ getWorldProperties() { local SERVER_VERSION SERVER_JAR SERVER_LOCATION SERVER_URL SERVER_ARGS INITIAL_MEMORY MAXIMUM_MEMORY SERVER_COMMAND # Get the server version, use the current version if not provided. SERVER_VERSION=$( - getPropertiesValue "$1" "mscs-server-version" $CURRENT_VERSION | + getPropertiesValue "$1" "mscs-server-version" "$CURRENT_VERSION" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; $_ =~ s/\$CURRENT_VERSION/$current_version/g; @@ -589,7 +589,7 @@ getWorldProperties() { ) # Get the server jar, use the default value if not provided. SERVER_JAR=$( - getPropertiesValue "$1" "mscs-server-jar" $DEFAULT_SERVER_JAR | + getPropertiesValue "$1" "mscs-server-jar" "$DEFAULT_SERVER_JAR" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; $server_version="'$SERVER_VERSION'"; @@ -600,7 +600,7 @@ getWorldProperties() { ) # Get the server location, use the default value if not provided. SERVER_LOCATION=$( - getPropertiesValue "$1" "mscs-server-location" $DEFAULT_SERVER_LOCATION | + getPropertiesValue "$1" "mscs-server-location" "$DEFAULT_SERVER_LOCATION" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; $server_version="'$SERVER_VERSION'"; @@ -611,7 +611,7 @@ getWorldProperties() { ) # Get the server download URL, use the default value if not provided. SERVER_URL=$( - getPropertiesValue "$1" "mscs-server-url" $DEFAULT_SERVER_URL | + getPropertiesValue "$1" "mscs-server-url" "$DEFAULT_SERVER_URL" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; $server_version="'$SERVER_VERSION'"; @@ -623,19 +623,19 @@ getWorldProperties() { ) # Get the server agruments, use the default value if not provided. SERVER_ARGS=$( - getPropertiesValue "$1" "mscs-server-args" $DEFAULT_SERVER_ARGS + getPropertiesValue "$1" "mscs-server-args" "$DEFAULT_SERVER_ARGS" ) # Get the initial memory, use the default value if not provided. INITIAL_MEMORY=$( - getPropertiesValue "$1" "mscs-initial-memory" $DEFAULT_INITIAL_MEMORY + getPropertiesValue "$1" "mscs-initial-memory" "$DEFAULT_INITIAL_MEMORY" ) # Get the maximum memory, use the default value if not provided. MAXIMUM_MEMORY=$( - getPropertiesValue "$1" "mscs-maximum-memory" $DEFAULT_MAXIMUM_MEMORY + getPropertiesValue "$1" "mscs-maximum-memory" "$DEFAULT_MAXIMUM_MEMORY" ) # Get the server command, use the default value if not provided. SERVER_COMMAND=$( - getPropertiesValue "$1" "mscs-server-command" $DEFAULT_SERVER_COMMAND | + getPropertiesValue "$1" "mscs-server-command" "$DEFAULT_SERVER_COMMAND" | $PERL -ne ' $java = "'$JAVA'"; $current_version = "'$CURRENT_VERSION'"; From 64e86b01c597ca1f28f715cced19bb1490bb9e00 Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Sun, 3 Nov 2013 11:30:48 -0700 Subject: [PATCH 11/22] Make sure the mscs-server-version works even if it is the only option used. Move the default server version to the top of the file rather than forcing the current version to be default. --- minecraft_server | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/minecraft_server b/minecraft_server index b9aaaf6..c3e9829 100755 --- a/minecraft_server +++ b/minecraft_server @@ -163,8 +163,9 @@ CURRENT_VERSION=$( # --------------------------------------------------------------------------- # Default settings if not provided in the world's server.properties file. -DEFAULT_SERVER_JAR='minecraft_server.$CURRENT_VERSION.jar' -DEFAULT_SERVER_URL='https://s3.amazonaws.com/Minecraft.Download/versions/$CURRENT_VERSION/minecraft_server.$CURRENT_VERSION.jar' +DEFAULT_SERVER_VERSION=$CURRENT_VERSION +DEFAULT_SERVER_JAR='minecraft_server.$SERVER_VERSION.jar' +DEFAULT_SERVER_URL='https://s3.amazonaws.com/Minecraft.Download/versions/$SERVER_VERSION/minecraft_server.$SERVER_VERSION.jar' DEFAULT_SERVER_ARGS='nogui' DEFAULT_INITIAL_MEMORY='128M' DEFAULT_MAXIMUM_MEMORY='2048M' @@ -197,7 +198,7 @@ DEFAULT_SERVER_COMMAND='$JAVA -Xms$INITIAL_MEMORY -Xmx$MAXIMUM_MEMORY -jar $SERV # # The following example key/value pairs are equivalent to the default values: # mscs-server-version=$CURRENT_VERSION -# mscs-server-jar=minecraft_server.$CURRENT_VERSION.jar +# mscs-server-jar=minecraft_server.$SERVER_VERSION.jar # mscs-server-args=nogui # mscs-initial-memory=128M # mscs-maximum-memory=2048M @@ -580,7 +581,7 @@ getWorldProperties() { local SERVER_VERSION SERVER_JAR SERVER_LOCATION SERVER_URL SERVER_ARGS INITIAL_MEMORY MAXIMUM_MEMORY SERVER_COMMAND # Get the server version, use the current version if not provided. SERVER_VERSION=$( - getPropertiesValue "$1" "mscs-server-version" "$CURRENT_VERSION" | + getPropertiesValue "$1" "mscs-server-version" "$DEFAULT_SERVER_VERSION" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; $_ =~ s/\$CURRENT_VERSION/$current_version/g; From c50b774c1986bce3c5ac041a27e503aa148bab7a Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Sun, 3 Nov 2013 11:41:14 -0700 Subject: [PATCH 12/22] Move the default world, port, and IP variables to join the rest of the default world variables --- minecraft_server | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/minecraft_server b/minecraft_server index c3e9829..bf6bef7 100755 --- a/minecraft_server +++ b/minecraft_server @@ -163,6 +163,9 @@ CURRENT_VERSION=$( # --------------------------------------------------------------------------- # Default settings if not provided in the world's server.properties file. +DEFAULT_WORLD="world" +DEFAULT_PORT="25565" +DEFAULT_IP="" DEFAULT_SERVER_VERSION=$CURRENT_VERSION DEFAULT_SERVER_JAR='minecraft_server.$SERVER_VERSION.jar' DEFAULT_SERVER_URL='https://s3.amazonaws.com/Minecraft.Download/versions/$SERVER_VERSION/minecraft_server.$SERVER_VERSION.jar' @@ -224,12 +227,6 @@ WORLDS_LOCATION="$LOCATION/worlds" # The location to store disabled world server files. DISABLED_WORLDS_LOCATION="$LOCATION/worlds-disabled" -# Default world name, port, and IP address if the worlds.conf file is -# missing. -DEFAULT_WORLD="world" -DEFAULT_PORT="25565" -DEFAULT_IP="" - # Global Message Of The Day file (MOTD) # --------------------------------------------------------------------------- From be13cb96091b0ce4b632767f15c784498dbf23ac Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Sun, 3 Nov 2013 19:11:49 -0700 Subject: [PATCH 13/22] spelling fix --- minecraft_server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_server b/minecraft_server index bf6bef7..be278c8 100755 --- a/minecraft_server +++ b/minecraft_server @@ -619,7 +619,7 @@ getWorldProperties() { print; ' ) - # Get the server agruments, use the default value if not provided. + # Get the server arguments, use the default value if not provided. SERVER_ARGS=$( getPropertiesValue "$1" "mscs-server-args" "$DEFAULT_SERVER_ARGS" ) From c292495f1362f7c1c0dfedeaefa4c1f1cee1e4ff Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Wed, 6 Nov 2013 19:21:37 -0700 Subject: [PATCH 14/22] Split the getWorldProperties method into multiple methods --- minecraft_server | 81 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 19 deletions(-) diff --git a/minecraft_server b/minecraft_server index 1e52816..dccc227 100755 --- a/minecraft_server +++ b/minecraft_server @@ -569,14 +569,14 @@ setPropertiesValue() { } # --------------------------------------------------------------------------- -# Retrieve the properties for the world. +# Retrieve the version of the server running the world. # -# @param 1 The world server to parse a string for. -# @return SERVER_VERSION SERVER_JAR SERVER_LOCATION SERVER_URL SERVER_COMMAND +# @param 1 The world server. +# @return SERVER_VERSION # --------------------------------------------------------------------------- -getWorldProperties() { - local SERVER_VERSION SERVER_JAR SERVER_LOCATION SERVER_URL SERVER_ARGS INITIAL_MEMORY MAXIMUM_MEMORY SERVER_COMMAND - # Get the server version, use the current version if not provided. +getServerVersion() { + local SERVER_VERSION + # Get the server version, use the default version if not provided. SERVER_VERSION=$( getPropertiesValue "$1" "mscs-server-version" "$DEFAULT_SERVER_VERSION" | $PERL -ne ' @@ -585,40 +585,84 @@ getWorldProperties() { print; ' ) + echo "$SERVER_VERSION" +} + +# --------------------------------------------------------------------------- +# Retrieve the .jar file name for the server running the world. +# +# @param 1 The world server. +# @return SERVER_JAR +# --------------------------------------------------------------------------- +getServerJar() { + local SERVER_JAR # Get the server jar, use the default value if not provided. SERVER_JAR=$( getPropertiesValue "$1" "mscs-server-jar" "$DEFAULT_SERVER_JAR" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; - $server_version="'$SERVER_VERSION'"; + $server_version="'$(getServerVersion "$1")'"; $_ =~ s/\$CURRENT_VERSION/$current_version/g; $_ =~ s/\$SERVER_VERSION/$server_version/g; print; ' ) + echo "$SERVER_JAR" +} + +# --------------------------------------------------------------------------- +# Retrieve the location of the server files for the server running the world. +# +# @param 1 The world server. +# @return SERVER_LOCATION +# --------------------------------------------------------------------------- +getServerLocation() { + local SERVER_LOCATION # Get the server location, use the default value if not provided. SERVER_LOCATION=$( getPropertiesValue "$1" "mscs-server-location" "$DEFAULT_SERVER_LOCATION" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; - $server_version="'$SERVER_VERSION'"; + $server_version="'$(getServerVersion "$1")'"; $_ =~ s/\$CURRENT_VERSION/$current_version/g; $_ =~ s/\$SERVER_VERSION/$server_version/g; print; ' ) + echo "$SERVER_LOCATION" +} + +# --------------------------------------------------------------------------- +# Retrieve the URL to download the server running the world. +# +# @param 1 The world server. +# @return SERVER_URL +# --------------------------------------------------------------------------- +getServerURL() { + local SERVER_URL # Get the server download URL, use the default value if not provided. SERVER_URL=$( getPropertiesValue "$1" "mscs-server-url" "$DEFAULT_SERVER_URL" | $PERL -ne ' $current_version="'$CURRENT_VERSION'"; - $server_version="'$SERVER_VERSION'"; + $server_version="'$(getServerVersion "$1")'"; $_ =~ s/\$CURRENT_VERSION/$current_version/g; $_ =~ s/\$SERVER_VERSION/$server_version/g; $_ =~ s/\\\:/\:/g; print; ' ) + echo "$SERVER_URL" +} + +# --------------------------------------------------------------------------- +# Retrieve the command to start the server running the world. +# +# @param 1 The world server. +# @return SERVER_COMMAND +# --------------------------------------------------------------------------- +getServerCommand() { + local SERVER_ARGS INITIAL_MEMORY MAXIMUM_MEMORY SERVER_COMMAND # Get the server arguments, use the default value if not provided. SERVER_ARGS=$( getPropertiesValue "$1" "mscs-server-args" "$DEFAULT_SERVER_ARGS" @@ -637,9 +681,9 @@ getWorldProperties() { $PERL -ne ' $java = "'$JAVA'"; $current_version = "'$CURRENT_VERSION'"; - $server_version = "'$SERVER_VERSION'"; - $server_jar = "'$SERVER_JAR'"; - $server_location = "'$SERVER_LOCATION'"; + $server_version = "'$(getServerVersion "$1")'"; + $server_jar = "'$(getServerJar "$1")'"; + $server_location = "'$(getServerLocation "$1")'"; $server_args = "'$SERVER_ARGS'"; $initial_memory = "'$INITIAL_MEMORY'"; $maximum_memory = "'$MAXIMUM_MEMORY'"; @@ -654,7 +698,7 @@ getWorldProperties() { print; ' ) - echo "$SERVER_VERSION\t$SERVER_JAR\t$SERVER_LOCATION\t$SERVER_URL\t$SERVER_COMMAND" + echo "$SERVER_COMMAND" } # --------------------------------------------------------------------------- @@ -812,7 +856,7 @@ start() { # Change to the world's directory. cd $WORLD_DIR # Start the server. - SERVER_COMMAND=$(getWorldProperties "$1" | cut -f5) + SERVER_COMMAND=$(getServerCommand "$1") execute "$SCREEN -dmS minecraft-$1 $SERVER_COMMAND" $USER_NAME if [ $? -ne 0 ]; then printf "Error starting the server.\n" @@ -933,11 +977,10 @@ updateClientSoftware() { # @param 1 The world server to update. # --------------------------------------------------------------------------- updateServerSoftware() { - local WORLD_PROPERTIES SERVER_JAR SERVER_LOCATION SERVER_URL - WORLD_PROPERTIES=$(getWorldProperties "$1") - SERVER_JAR=$(echo "$WORLD_PROPERTIES" | cut -f2) - SERVER_LOCATION=$(echo "$WORLD_PROPERTIES" | cut -f3) - SERVER_URL=$(echo "$WORLD_PROPERTIES" | cut -f4) + local SERVER_JAR SERVER_LOCATION SERVER_URL + SERVER_JAR=$(getServerJar "$1") + SERVER_LOCATION=$(getServerLocation "$1") + SERVER_URL=$(getServerURL "$1") execute "mkdir -p $SERVER_LOCATION" $USER_NAME if [ ! -e "$SERVER_LOCATION/$SERVER_JAR" ]; then # Download the new minecraft server software. From 0fd382021a89468544ff206b1f288390996c038d Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Mon, 2 Dec 2013 21:50:29 -0700 Subject: [PATCH 15/22] whitespace --- minecraft_server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_server b/minecraft_server index 45a4deb..2b10d46 100755 --- a/minecraft_server +++ b/minecraft_server @@ -49,7 +49,7 @@ # --------------------------------------------------------------------------- USAGE=$(cat < +Usage: $0