mirror of
https://github.com/msmhq/msm.git
synced 2024-08-30 18:12:35 +00:00
Remove unnecessary whitespace (thanks Atom)
This commit is contained in:
parent
0455eb0236
commit
ffff59c6cb
266
init/msm
266
init/msm
@ -143,7 +143,7 @@ echo_if() {
|
|||||||
[ ! -z "$1" ] && echo "$1"
|
[ ! -z "$1" ] && echo "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Exit's the script
|
# Exit's the script
|
||||||
error_exit() {
|
error_exit() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
INVALID_USER) code=64;;
|
INVALID_USER) code=64;;
|
||||||
@ -160,7 +160,7 @@ error_exit() {
|
|||||||
JAVA_NOT_INSTALLED) code=75;;
|
JAVA_NOT_INSTALLED) code=75;;
|
||||||
EULA_UNACCEPTED) code=76;;
|
EULA_UNACCEPTED) code=76;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo "${2:-"Unknown Error"}" 1>&2
|
echo "${2:-"Unknown Error"}" 1>&2
|
||||||
exit "${code:-$1}"
|
exit "${code:-$1}"
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ debug() {
|
|||||||
is_valid_name() {
|
is_valid_name() {
|
||||||
local valid="^[a-zA-Z0-9\_\-]+$"
|
local valid="^[a-zA-Z0-9\_\-]+$"
|
||||||
local invalid="^(start|stop|restart|version|server|jargroup|all|config|update|help|\-\-.*)$"
|
local invalid="^(start|stop|restart|version|server|jargroup|all|config|update|help|\-\-.*)$"
|
||||||
|
|
||||||
if [[ "$1" =~ $valid ]]; then
|
if [[ "$1" =~ $valid ]]; then
|
||||||
if [[ "$1" =~ $invalid ]]; then
|
if [[ "$1" =~ $invalid ]]; then
|
||||||
error_exit INVALID_ARGUMENT "Invalid name \"$1\": A name may not be any of the following reserved worlds \"start\", \"stop\", \"restart\", \"server\", \"version\", \"jargroup\", \"all\", \"config\", \"update\" or \"help\" or start with two dashes (--)."
|
error_exit INVALID_ARGUMENT "Invalid name \"$1\": A name may not be any of the following reserved worlds \"start\", \"stop\", \"restart\", \"server\", \"version\", \"jargroup\", \"all\", \"config\", \"update\" or \"help\" or start with two dashes (--)."
|
||||||
@ -266,21 +266,21 @@ get_latest_file() {
|
|||||||
|
|
||||||
local best_time=0
|
local best_time=0
|
||||||
local best_file=""
|
local best_file=""
|
||||||
|
|
||||||
while IFS= read -r -d $'\0' file; do
|
while IFS= read -r -d $'\0' file; do
|
||||||
# Remove the path, leaving just the file name
|
# Remove the path, leaving just the file name
|
||||||
local date_time="$(basename "$file" | awk -F '-' '{print $1 "-" $2 "-" $3 " " $4 ":" $5 ":" $6}')"
|
local date_time="$(basename "$file" | awk -F '-' '{print $1 "-" $2 "-" $3 " " $4 ":" $5 ":" $6}')"
|
||||||
|
|
||||||
# Get the time in seconds since 1970 from file name
|
# Get the time in seconds since 1970 from file name
|
||||||
local seconds="$(date -d "$date_time" "+%s" 2> /dev/null)"
|
local seconds="$(date -d "$date_time" "+%s" 2> /dev/null)"
|
||||||
|
|
||||||
# If that is newer than the current best, override variables
|
# If that is newer than the current best, override variables
|
||||||
if [[ "$seconds" -gt "$best_time" ]]; then
|
if [[ "$seconds" -gt "$best_time" ]]; then
|
||||||
best_time="$seconds"
|
best_time="$seconds"
|
||||||
best_file="$file"
|
best_file="$file"
|
||||||
fi
|
fi
|
||||||
done < <(find "$1" -maxdepth 1 -type f -print0)
|
done < <(find "$1" -maxdepth 1 -type f -print0)
|
||||||
|
|
||||||
RETURN="$best_file"
|
RETURN="$best_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ world_toggle_ramdisk_state() {
|
|||||||
echo -n "Removing RAM flag from world \"${WORLD_NAME[$1]}\"... "
|
echo -n "Removing RAM flag from world \"${WORLD_NAME[$1]}\"... "
|
||||||
as_user "${SERVER_USERNAME[$sid]}" "rm -f \"${WORLD_FLAG_INRAM[$1]}\""
|
as_user "${SERVER_USERNAME[$sid]}" "rm -f \"${WORLD_FLAG_INRAM[$1]}\""
|
||||||
echo "Done."
|
echo "Done."
|
||||||
|
|
||||||
echo -n "Removing world \"${WORLD_NAME[$1]}\" from RAM... "
|
echo -n "Removing world \"${WORLD_NAME[$1]}\" from RAM... "
|
||||||
as_user "${SERVER_USERNAME[$sid]}" "rm -r \"${WORLD_RAMDISK_PATH[$1]}\""
|
as_user "${SERVER_USERNAME[$sid]}" "rm -r \"${WORLD_RAMDISK_PATH[$1]}\""
|
||||||
echo "Done."
|
echo "Done."
|
||||||
@ -363,12 +363,12 @@ world_toggle_ramdisk_state() {
|
|||||||
echo -n "Adding RAM flag to world \"${WORLD_NAME[$1]}\"... "
|
echo -n "Adding RAM flag to world \"${WORLD_NAME[$1]}\"... "
|
||||||
as_user "${SERVER_USERNAME[$sid]}" "touch \"${WORLD_FLAG_INRAM[$1]}\""
|
as_user "${SERVER_USERNAME[$sid]}" "touch \"${WORLD_FLAG_INRAM[$1]}\""
|
||||||
echo "Done."
|
echo "Done."
|
||||||
|
|
||||||
echo -n "Copying world to RAM... "
|
echo -n "Copying world to RAM... "
|
||||||
world_to_ram "$1"
|
world_to_ram "$1"
|
||||||
echo "Done."
|
echo "Done."
|
||||||
fi
|
fi
|
||||||
echo "Changes will only take effect after server is restarted."
|
echo "Changes will only take effect after server is restarted."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Backs up a world
|
# Backs up a world
|
||||||
@ -387,7 +387,7 @@ world_backup() {
|
|||||||
|
|
||||||
|
|
||||||
if [[ "$SETTINGS_WORLD_ARCHIVE_ENABLED" == "true" ]]; then
|
if [[ "$SETTINGS_WORLD_ARCHIVE_ENABLED" == "true" ]]; then
|
||||||
echo -n "Backing up world \"${WORLD_NAME[$1]}\"... "
|
echo -n "Backing up world \"${WORLD_NAME[$1]}\"... "
|
||||||
file_name="$(date "+%F-%H-%M-%S").zip"
|
file_name="$(date "+%F-%H-%M-%S").zip"
|
||||||
server_property "$server_id" USERNAME
|
server_property "$server_id" USERNAME
|
||||||
as_user "${SERVER_USERNAME[$server_id]}" "mkdir -p \"${WORLD_BACKUP_PATH[$1]}\" && cd \"$containing_dir\" && zip -rq \"${WORLD_BACKUP_PATH[$1]}/${file_name}\" \"${dir_name}\""
|
as_user "${SERVER_USERNAME[$server_id]}" "mkdir -p \"${WORLD_BACKUP_PATH[$1]}\" && cd \"$containing_dir\" && zip -rq \"${WORLD_BACKUP_PATH[$1]}/${file_name}\" \"${dir_name}\""
|
||||||
@ -408,7 +408,7 @@ world_backup() {
|
|||||||
as_user "${SERVER_USERNAME[$server_id]}" "mkdir -p \"${RSYNC_BACKUP_PATH[$1]}\" && cd \"$containing_dir\" && rsync -aH --link-dest=\"${RSYNC_BACKUP_PATH[$1]}/latest\" \"${dir_name}\" \"${RSYNC_BACKUP_PATH[$1]}/${file_name}\" && rm -f \"${RSYNC_BACKUP_PATH[$1]}/latest\" && ln -s \"${file_name}\" \"${RSYNC_BACKUP_PATH[$1]}/latest\""
|
as_user "${SERVER_USERNAME[$server_id]}" "mkdir -p \"${RSYNC_BACKUP_PATH[$1]}\" && cd \"$containing_dir\" && rsync -aH --link-dest=\"${RSYNC_BACKUP_PATH[$1]}/latest\" \"${dir_name}\" \"${RSYNC_BACKUP_PATH[$1]}/${file_name}\" && rm -f \"${RSYNC_BACKUP_PATH[$1]}/latest\" && ln -s \"${file_name}\" \"${RSYNC_BACKUP_PATH[$1]}/latest\""
|
||||||
echo "Done."
|
echo "Done."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Activates a world
|
# Activates a world
|
||||||
@ -589,7 +589,7 @@ server_get_id() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
error_exit NAME_NOT_FOUND "Could not find id for server name \"$1\"."
|
error_exit NAME_NOT_FOUND "Could not find id for server name \"$1\"."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,7 +606,7 @@ server_world_get_id() {
|
|||||||
|
|
||||||
local start="${SERVER_WORLD_OFFSET[$1]}"
|
local start="${SERVER_WORLD_OFFSET[$1]}"
|
||||||
local max="$(( $start + ${SERVER_NUM_WORLDS[$1]} ))"
|
local max="$(( $start + ${SERVER_NUM_WORLDS[$1]} ))"
|
||||||
|
|
||||||
# For each of the servers worlds:
|
# For each of the servers worlds:
|
||||||
for ((i=$start; i<$max; i++)); do
|
for ((i=$start; i<$max; i++)); do
|
||||||
if [[ "${WORLD_NAME[$i]}" == "$2" ]]; then
|
if [[ "${WORLD_NAME[$i]}" == "$2" ]]; then
|
||||||
@ -615,7 +615,7 @@ server_world_get_id() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
error_exit NAME_NOT_FOUND "Could not find id for world \"$2\" for server \"${SERVER_NAME[$1]}\"."
|
error_exit NAME_NOT_FOUND "Could not find id for world \"$2\" for server \"${SERVER_NAME[$1]}\"."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,7 +641,7 @@ server_ensure_jar() {
|
|||||||
if [ -f "${SERVER_JAR_PATH[$1]}" ]; then
|
if [ -f "${SERVER_JAR_PATH[$1]}" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
error_exit FILE_NOT_FOUND "Could not find jar for server \"${SERVER_NAME[$1]}\": Expected \"${SERVER_JAR_PATH[$1]}\"."
|
error_exit FILE_NOT_FOUND "Could not find jar for server \"${SERVER_NAME[$1]}\": Expected \"${SERVER_JAR_PATH[$1]}\"."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +684,7 @@ server_ensure_links() {
|
|||||||
local start="${SERVER_WORLD_OFFSET[$1]}"
|
local start="${SERVER_WORLD_OFFSET[$1]}"
|
||||||
local max="$(( $start + ${SERVER_NUM_WORLDS[$1]} ))"
|
local max="$(( $start + ${SERVER_NUM_WORLDS[$1]} ))"
|
||||||
local output="false"
|
local output="false"
|
||||||
|
|
||||||
for ((i=$start; i<$max; i++)); do
|
for ((i=$start; i<$max; i++)); do
|
||||||
world_property "$i" STATUS
|
world_property "$i" STATUS
|
||||||
world_property "$i" LINK
|
world_property "$i" LINK
|
||||||
@ -696,18 +696,18 @@ server_ensure_links() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
world_property "$i" INRAM
|
world_property "$i" INRAM
|
||||||
|
|
||||||
# -L checks for the path being a link rather than a file
|
# -L checks for the path being a link rather than a file
|
||||||
# ! -a, since it is within double square brackets means: the negation of
|
# ! -a, since it is within double square brackets means: the negation of
|
||||||
# the existence of the file. In other words: true if does not exist
|
# the existence of the file. In other words: true if does not exist
|
||||||
if [[ -L "${WORLD_LINK[$i]}" || ! -a "${WORLD_LINK[$i]}" ]]; then
|
if [[ -L "${WORLD_LINK[$i]}" || ! -a "${WORLD_LINK[$i]}" ]]; then
|
||||||
# If there is a symbolic link in the server directory to this world,
|
# If there is a symbolic link in the server directory to this world,
|
||||||
# or there is not a directory in the server directory containing this world.
|
# or there is not a directory in the server directory containing this world.
|
||||||
|
|
||||||
# Get the original file path the symbolic link is pointing to
|
# Get the original file path the symbolic link is pointing to
|
||||||
# If there is no link, link_target will contain nothing
|
# If there is no link, link_target will contain nothing
|
||||||
link_target="$(readlink "${WORLD_LINK[$i]}")"
|
link_target="$(readlink "${WORLD_LINK[$i]}")"
|
||||||
|
|
||||||
if "${WORLD_INRAM[$i]}"; then
|
if "${WORLD_INRAM[$i]}"; then
|
||||||
# If this world is marked as loaded into RAM
|
# If this world is marked as loaded into RAM
|
||||||
|
|
||||||
@ -742,7 +742,7 @@ server_ensure_links() {
|
|||||||
output="true"
|
output="true"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$output" == "true" ]]; then
|
if [[ "$output" == "true" ]]; then
|
||||||
echo -e "\nDone."
|
echo -e "\nDone."
|
||||||
else
|
else
|
||||||
@ -760,7 +760,7 @@ server_worlds_to_ram() {
|
|||||||
echo -n "Synchronising flagged worlds on disk to RAM... "
|
echo -n "Synchronising flagged worlds on disk to RAM... "
|
||||||
local i="${SERVER_WORLD_OFFSET[$1]}"
|
local i="${SERVER_WORLD_OFFSET[$1]}"
|
||||||
local max="$(( $i + ${SERVER_NUM_WORLDS[$1]} ))"
|
local max="$(( $i + ${SERVER_NUM_WORLDS[$1]} ))"
|
||||||
|
|
||||||
# For each of the servers worlds:
|
# For each of the servers worlds:
|
||||||
while [[ "$i" -lt "$max" ]]; do
|
while [[ "$i" -lt "$max" ]]; do
|
||||||
world_property "$i" INRAM
|
world_property "$i" INRAM
|
||||||
@ -769,7 +769,7 @@ server_worlds_to_ram() {
|
|||||||
if "${WORLD_INRAM[$i]}" && [ -L "${WORLD_LINK[$i]}" ]; then
|
if "${WORLD_INRAM[$i]}" && [ -L "${WORLD_LINK[$i]}" ]; then
|
||||||
world_to_ram "$i"
|
world_to_ram "$i"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
i="$(( $i + 1 ))"
|
i="$(( $i + 1 ))"
|
||||||
done
|
done
|
||||||
echo "Done."
|
echo "Done."
|
||||||
@ -785,14 +785,14 @@ server_worlds_to_disk() {
|
|||||||
echo -n "Synchronising worlds in RAM to disk... "
|
echo -n "Synchronising worlds in RAM to disk... "
|
||||||
local i="${SERVER_WORLD_OFFSET[$1]}"
|
local i="${SERVER_WORLD_OFFSET[$1]}"
|
||||||
local max="$(( $i + ${SERVER_NUM_WORLDS[$1]} ))"
|
local max="$(( $i + ${SERVER_NUM_WORLDS[$1]} ))"
|
||||||
|
|
||||||
# For each of the servers worlds:
|
# For each of the servers worlds:
|
||||||
while [[ "$i" -lt "$max" ]]; do
|
while [[ "$i" -lt "$max" ]]; do
|
||||||
world_property "$i" RAMDISK_PATH
|
world_property "$i" RAMDISK_PATH
|
||||||
if [ -d "${WORLD_RAMDISK_PATH[$i]}" ]; then
|
if [ -d "${WORLD_RAMDISK_PATH[$i]}" ]; then
|
||||||
world_to_disk "$i"
|
world_to_disk "$i"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
i="$(( $i + 1 ))"
|
i="$(( $i + 1 ))"
|
||||||
done
|
done
|
||||||
echo "Done."
|
echo "Done."
|
||||||
@ -959,7 +959,7 @@ server_pid() {
|
|||||||
# $1: The ID of the server to wait for
|
# $1: The ID of the server to wait for
|
||||||
server_wait_for_stop() {
|
server_wait_for_stop() {
|
||||||
local pid="$(server_pid "$1")"
|
local pid="$(server_pid "$1")"
|
||||||
|
|
||||||
# if the process is still running, wait for it to stop
|
# if the process is still running, wait for it to stop
|
||||||
if [ ! -z "$pid" ]; then
|
if [ ! -z "$pid" ]; then
|
||||||
while ps -p "$pid" > /dev/null; do
|
while ps -p "$pid" > /dev/null; do
|
||||||
@ -1009,7 +1009,7 @@ jargroup_list() {
|
|||||||
if [[ -d "${SETTINGS_JAR_STORAGE_PATH}" ]]; then
|
if [[ -d "${SETTINGS_JAR_STORAGE_PATH}" ]]; then
|
||||||
local jargroup_name
|
local jargroup_name
|
||||||
local jar_name
|
local jar_name
|
||||||
|
|
||||||
while IFS= read -r -d $'\0' jargroup_path; do
|
while IFS= read -r -d $'\0' jargroup_path; do
|
||||||
jargroup_name="$(basename "${jargroup_path}")"
|
jargroup_name="$(basename "${jargroup_path}")"
|
||||||
echo "$jargroup_name"
|
echo "$jargroup_name"
|
||||||
@ -1034,19 +1034,19 @@ jargroup_create() {
|
|||||||
|
|
||||||
if [[ ! -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
if [[ ! -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
||||||
echo -n "Creating jar group... "
|
echo -n "Creating jar group... "
|
||||||
|
|
||||||
local error="$(as_user_stderr "$SETTINGS_USERNAME" "mkdir -p \"$SETTINGS_JAR_STORAGE_PATH/$1\"")"
|
local error="$(as_user_stderr "$SETTINGS_USERNAME" "mkdir -p \"$SETTINGS_JAR_STORAGE_PATH/$1\"")"
|
||||||
if [[ "$error" != "" ]]; then
|
if [[ "$error" != "" ]]; then
|
||||||
echo "Failed."
|
echo "Failed."
|
||||||
error_exit FILE_NOT_FOUND "$error"
|
error_exit FILE_NOT_FOUND "$error"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
error="$(as_user "$SETTINGS_USERNAME" "echo \"$2\" > \"$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_TARGET\"")"
|
error="$(as_user "$SETTINGS_USERNAME" "echo \"$2\" > \"$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_TARGET\"")"
|
||||||
if [[ "$error" != "" ]]; then
|
if [[ "$error" != "" ]]; then
|
||||||
echo "Failed."
|
echo "Failed."
|
||||||
error_exit FILE_NOT_FOUND "$error"
|
error_exit FILE_NOT_FOUND "$error"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
else
|
else
|
||||||
error_exit DUPLICATE_NAME "A jar group with that name already exists."
|
error_exit DUPLICATE_NAME "A jar group with that name already exists."
|
||||||
@ -1090,14 +1090,14 @@ jargroup_getlatest() {
|
|||||||
if [[ -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
if [[ -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
||||||
if [[ -f "$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_TARGET" ]]; then
|
if [[ -f "$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_TARGET" ]]; then
|
||||||
printf "Downloading latest version... "
|
printf "Downloading latest version... "
|
||||||
|
|
||||||
# Try and make
|
# Try and make
|
||||||
local error="$(as_user_stderr "$SETTINGS_USERNAME" "mkdir -p '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR'")"
|
local error="$(as_user_stderr "$SETTINGS_USERNAME" "mkdir -p '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR'")"
|
||||||
if [[ "$error" != "" ]]; then
|
if [[ "$error" != "" ]]; then
|
||||||
echo "Failed."
|
echo "Failed."
|
||||||
error_exit FILE_NOT_FOUND "$error"
|
error_exit FILE_NOT_FOUND "$error"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# test wget for --trust-server-names option
|
# test wget for --trust-server-names option
|
||||||
local wget_opts="--trust-server-names"
|
local wget_opts="--trust-server-names"
|
||||||
wget $wget_opts >/dev/null 2>&1
|
wget $wget_opts >/dev/null 2>&1
|
||||||
@ -1130,29 +1130,29 @@ jargroup_getlatest() {
|
|||||||
as_user "$SETTINGS_USERNAME" "wget --quiet $wget_opts --no-check-certificate --input-file='$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_TARGET' --directory-prefix='$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR'"
|
as_user "$SETTINGS_USERNAME" "wget --quiet $wget_opts --no-check-certificate --input-file='$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_TARGET' --directory-prefix='$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR'"
|
||||||
fi
|
fi
|
||||||
echo "Done."
|
echo "Done."
|
||||||
|
|
||||||
local num_files="$(as_user "$SETTINGS_USERNAME" "ls -1 '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR' | wc -l")"
|
local num_files="$(as_user "$SETTINGS_USERNAME" "ls -1 '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR' | wc -l")"
|
||||||
|
|
||||||
if [[ "$num_files" == 1 ]]; then
|
if [[ "$num_files" == 1 ]]; then
|
||||||
# There was 1 file downloaded
|
# There was 1 file downloaded
|
||||||
|
|
||||||
local file_name="$(ls -1 "$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR")"
|
local file_name="$(ls -1 "$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR")"
|
||||||
local new_name="$(date +%F-%H-%M-%S)-$file_name"
|
local new_name="$(date +%F-%H-%M-%S)-$file_name"
|
||||||
|
|
||||||
get_latest_file "$SETTINGS_JAR_STORAGE_PATH/$1"
|
get_latest_file "$SETTINGS_JAR_STORAGE_PATH/$1"
|
||||||
local most_recent_jar="$RETURN"
|
local most_recent_jar="$RETURN"
|
||||||
|
|
||||||
|
|
||||||
if [[ ! -f "$most_recent_jar" ]] || ! diff "$most_recent_jar" "$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR/$file_name" > /dev/null; then
|
if [[ ! -f "$most_recent_jar" ]] || ! diff "$most_recent_jar" "$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR/$file_name" > /dev/null; then
|
||||||
# There is not a previous version to do a comparison against, or
|
# There is not a previous version to do a comparison against, or
|
||||||
# The previous version is different:
|
# The previous version is different:
|
||||||
# Add it to the group
|
# Add it to the group
|
||||||
|
|
||||||
[[ -f "$most_recent_jar" ]]
|
[[ -f "$most_recent_jar" ]]
|
||||||
local was_previous="$?"
|
local was_previous="$?"
|
||||||
|
|
||||||
as_user "$SETTINGS_USERNAME" "mv '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR/$file_name' '$SETTINGS_JAR_STORAGE_PATH/$1/$new_name'"
|
as_user "$SETTINGS_USERNAME" "mv '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR/$file_name' '$SETTINGS_JAR_STORAGE_PATH/$1/$new_name'"
|
||||||
|
|
||||||
if [[ ! -z "$most_recent_jar" ]]; then
|
if [[ ! -z "$most_recent_jar" ]]; then
|
||||||
echo "Downloaded version was different to previous latest. Saved as \"$SETTINGS_JAR_STORAGE_PATH/$1/$new_name\"."
|
echo "Downloaded version was different to previous latest. Saved as \"$SETTINGS_JAR_STORAGE_PATH/$1/$new_name\"."
|
||||||
else
|
else
|
||||||
@ -1161,7 +1161,7 @@ jargroup_getlatest() {
|
|||||||
else
|
else
|
||||||
echo "Existing version \"$most_recent_jar\" was already up to date."
|
echo "Existing version \"$most_recent_jar\" was already up to date."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif [[ "$num_files" == 0 ]]; then
|
elif [[ "$num_files" == 0 ]]; then
|
||||||
# No file was downloaded
|
# No file was downloaded
|
||||||
echo "Failed. No files were downloaded."
|
echo "Failed. No files were downloaded."
|
||||||
@ -1169,7 +1169,7 @@ jargroup_getlatest() {
|
|||||||
# Multiple files were
|
# Multiple files were
|
||||||
echo "Error. URL downloads multiple files."
|
echo "Error. URL downloads multiple files."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up the temp download folder
|
# Clean up the temp download folder
|
||||||
as_user "$SETTINGS_USERNAME" "rm -fr '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR'"
|
as_user "$SETTINGS_USERNAME" "rm -fr '$SETTINGS_JAR_STORAGE_PATH/$1/$SETTINGS_JARGROUP_DOWNLOAD_DIR'"
|
||||||
else
|
else
|
||||||
@ -1190,7 +1190,7 @@ jargroup_delete() {
|
|||||||
|
|
||||||
if [[ -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
if [[ -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
||||||
printf "Are you sure you want to delete this jar group [y/N]: "
|
printf "Are you sure you want to delete this jar group [y/N]: "
|
||||||
|
|
||||||
read answer
|
read answer
|
||||||
if [[ "$answer" =~ ^y|Y|yes$ ]]; then
|
if [[ "$answer" =~ ^y|Y|yes$ ]]; then
|
||||||
as_user "$SETTINGS_USERNAME" "rm -rf \"$SETTINGS_JAR_STORAGE_PATH/$1\""
|
as_user "$SETTINGS_USERNAME" "rm -rf \"$SETTINGS_JAR_STORAGE_PATH/$1\""
|
||||||
@ -1215,7 +1215,7 @@ jargroup_rename() {
|
|||||||
if [[ -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
if [[ -d "$SETTINGS_JAR_STORAGE_PATH/$1" ]]; then
|
||||||
# If the jar group name is valid,
|
# If the jar group name is valid,
|
||||||
# and there is no other jar group with the name $1
|
# and there is no other jar group with the name $1
|
||||||
|
|
||||||
if is_valid_name "$2"; then
|
if is_valid_name "$2"; then
|
||||||
if [[ -e "$SETTINGS_JAR_STORAGE_PATH/$2" ]]; then
|
if [[ -e "$SETTINGS_JAR_STORAGE_PATH/$2" ]]; then
|
||||||
error_exit DUPLICATE_NAME "Could not be renamed, there is already a jar group with the name \"$2\"."
|
error_exit DUPLICATE_NAME "Could not be renamed, there is already a jar group with the name \"$2\"."
|
||||||
@ -1274,7 +1274,7 @@ server_list() {
|
|||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "[There are no servers]"
|
echo "[There are no servers]"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Creates a new server
|
# Creates a new server
|
||||||
@ -1321,7 +1321,7 @@ server_create() {
|
|||||||
NUM_SERVERS=$(($NUM_SERVERS+1))
|
NUM_SERVERS=$(($NUM_SERVERS+1))
|
||||||
|
|
||||||
# TODO: Dirty all server variables, or don't allow further in script access
|
# TODO: Dirty all server variables, or don't allow further in script access
|
||||||
|
|
||||||
# TODO: Handle server default setup stuff better than just using
|
# TODO: Handle server default setup stuff better than just using
|
||||||
# the "minecraft" jar group. And make it configurable.
|
# the "minecraft" jar group. And make it configurable.
|
||||||
if [ -d "$SETTINGS_JAR_STORAGE_PATH/minecraft" ]; then
|
if [ -d "$SETTINGS_JAR_STORAGE_PATH/minecraft" ]; then
|
||||||
@ -1372,7 +1372,7 @@ server_rename() {
|
|||||||
|
|
||||||
if [ -d "$SETTINGS_SERVER_STORAGE_PATH/$1" ]; then
|
if [ -d "$SETTINGS_SERVER_STORAGE_PATH/$1" ]; then
|
||||||
# If the server name is valid and exists
|
# If the server name is valid and exists
|
||||||
|
|
||||||
server_get_id "$1"
|
server_get_id "$1"
|
||||||
local existing_id="$RETURN"
|
local existing_id="$RETURN"
|
||||||
|
|
||||||
@ -1415,7 +1415,7 @@ server_start() {
|
|||||||
server_worlds_to_ram "$1"
|
server_worlds_to_ram "$1"
|
||||||
|
|
||||||
local time_now="$(now)"
|
local time_now="$(now)"
|
||||||
|
|
||||||
printf "Starting server..."
|
printf "Starting server..."
|
||||||
|
|
||||||
# This is the important line! Let's start this server!
|
# This is the important line! Let's start this server!
|
||||||
@ -1453,7 +1453,7 @@ server_save_off() {
|
|||||||
echo -n "Disabling level saving... "
|
echo -n "Disabling level saving... "
|
||||||
server_command "$1" SAVE_OFF
|
server_command "$1" SAVE_OFF
|
||||||
echo "Done."
|
echo "Done."
|
||||||
|
|
||||||
# Writes any in-memory data managed by the kernel to disk
|
# Writes any in-memory data managed by the kernel to disk
|
||||||
sync
|
sync
|
||||||
else
|
else
|
||||||
@ -1482,21 +1482,21 @@ server_stop() {
|
|||||||
if server_is_running "$1"; then
|
if server_is_running "$1"; then
|
||||||
# Change the state of the script
|
# Change the state of the script
|
||||||
STOP_COUNTDOWN[$1]="true"
|
STOP_COUNTDOWN[$1]="true"
|
||||||
|
|
||||||
server_eval "$1" "say ${SERVER_MESSAGE_STOP[$1]}"
|
server_eval "$1" "say ${SERVER_MESSAGE_STOP[$1]}"
|
||||||
echo "Issued the warning \"${SERVER_MESSAGE_STOP[$1]}\" to players."
|
echo "Issued the warning \"${SERVER_MESSAGE_STOP[$1]}\" to players."
|
||||||
|
|
||||||
echo -n "Shutting down... "
|
echo -n "Shutting down... "
|
||||||
|
|
||||||
for ((i="${SERVER_STOP_DELAY[$1]}"; i>0; i--)); do
|
for ((i="${SERVER_STOP_DELAY[$1]}"; i>0; i--)); do
|
||||||
tput sc # Save cursor position
|
tput sc # Save cursor position
|
||||||
echo -n "in $i seconds."
|
echo -n "in $i seconds."
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
tput rc # Restore cursor to position of last `sc'
|
tput rc # Restore cursor to position of last `sc'
|
||||||
tput el # Clear to end of line
|
tput el # Clear to end of line
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "Now."
|
echo -e "Now."
|
||||||
server_stop_now "$1"
|
server_stop_now "$1"
|
||||||
else
|
else
|
||||||
@ -1509,16 +1509,16 @@ server_stop() {
|
|||||||
server_stop_now() {
|
server_stop_now() {
|
||||||
if server_is_running "$1"; then
|
if server_is_running "$1"; then
|
||||||
server_save_all "$1"
|
server_save_all "$1"
|
||||||
|
|
||||||
echo -n "Stopping the server... "
|
echo -n "Stopping the server... "
|
||||||
|
|
||||||
server_eval "$1" "stop"
|
server_eval "$1" "stop"
|
||||||
STOP_COUNTDOWN[$1]="false"
|
STOP_COUNTDOWN[$1]="false"
|
||||||
RESTART_COUNTDOWN[$1]="false"
|
RESTART_COUNTDOWN[$1]="false"
|
||||||
server_wait_for_stop "$1"
|
server_wait_for_stop "$1"
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
|
|
||||||
# Synchronise all worlds in RAM to disk
|
# Synchronise all worlds in RAM to disk
|
||||||
server_worlds_to_disk "$1"
|
server_worlds_to_disk "$1"
|
||||||
else
|
else
|
||||||
@ -1527,7 +1527,7 @@ server_stop_now() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Restarts a single server after a delay
|
# Restarts a single server after a delay
|
||||||
# $1: The ID of the server
|
# $1: The ID of the server
|
||||||
server_restart() {
|
server_restart() {
|
||||||
server_property "$1" MESSAGE_RESTART
|
server_property "$1" MESSAGE_RESTART
|
||||||
server_property "$1" RESTART_DELAY
|
server_property "$1" RESTART_DELAY
|
||||||
@ -1536,26 +1536,26 @@ server_restart() {
|
|||||||
if server_is_running "$1"; then
|
if server_is_running "$1"; then
|
||||||
# Change the state of the script
|
# Change the state of the script
|
||||||
RESTART_COUNTDOWN[$1]="true"
|
RESTART_COUNTDOWN[$1]="true"
|
||||||
|
|
||||||
server_eval "$1" "say ${SERVER_MESSAGE_RESTART[$1]}"
|
server_eval "$1" "say ${SERVER_MESSAGE_RESTART[$1]}"
|
||||||
echo "Issued the warning \"${SERVER_MESSAGE_RESTART[$1]}\" to players."
|
echo "Issued the warning \"${SERVER_MESSAGE_RESTART[$1]}\" to players."
|
||||||
|
|
||||||
echo -n "Restarting... "
|
echo -n "Restarting... "
|
||||||
|
|
||||||
for ((i="${SERVER_RESTART_DELAY[$1]}"; i>0; i--)); do
|
for ((i="${SERVER_RESTART_DELAY[$1]}"; i>0; i--)); do
|
||||||
tput sc # Save cursor position
|
tput sc # Save cursor position
|
||||||
echo -n "in $i seconds."
|
echo -n "in $i seconds."
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
tput rc # Restore cursor to position of last `sc'
|
tput rc # Restore cursor to position of last `sc'
|
||||||
tput el # Clear to end of line
|
tput el # Clear to end of line
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "Now."
|
echo -e "Now."
|
||||||
|
|
||||||
server_stop_now "$1"
|
server_stop_now "$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
server_start "$1"
|
server_start "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1566,7 +1566,7 @@ server_restart_now() {
|
|||||||
if server_is_running "$1"; then
|
if server_is_running "$1"; then
|
||||||
server_stop_now "$1"
|
server_stop_now "$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
server_start "$1"
|
server_start "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1580,7 +1580,7 @@ server_worlds_list() {
|
|||||||
|
|
||||||
local i="${SERVER_WORLD_OFFSET[$1]}"
|
local i="${SERVER_WORLD_OFFSET[$1]}"
|
||||||
local max="$(( $i + ${SERVER_NUM_WORLDS[$1]} ))"
|
local max="$(( $i + ${SERVER_NUM_WORLDS[$1]} ))"
|
||||||
|
|
||||||
# For each of the servers worlds:
|
# For each of the servers worlds:
|
||||||
for ((i=$i; i<$max; i++)); do
|
for ((i=$i; i<$max; i++)); do
|
||||||
world_property "$i" INRAM
|
world_property "$i" INRAM
|
||||||
@ -1628,11 +1628,11 @@ server_log_roll() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "Rolling server logs... "
|
echo -n "Rolling server logs... "
|
||||||
|
|
||||||
if [ -e "${SERVER_LOG_PATH[$1]}" ]; then
|
if [ -e "${SERVER_LOG_PATH[$1]}" ]; then
|
||||||
file_name="${SERVER_NAME[$1]}-$(date +%F-%H-%M-%S).log"
|
file_name="${SERVER_NAME[$1]}-$(date +%F-%H-%M-%S).log"
|
||||||
as_user "${SERVER_USERNAME[$1]}" "mkdir -p \"${SERVER_LOG_ARCHIVE_PATH[$1]}\" && cp \"${SERVER_LOG_PATH[$1]}\" \"${SERVER_LOG_ARCHIVE_PATH[$1]}/${file_name}\" && gzip \"${SERVER_LOG_ARCHIVE_PATH[$1]}/${file_name}\""
|
as_user "${SERVER_USERNAME[$1]}" "mkdir -p \"${SERVER_LOG_ARCHIVE_PATH[$1]}\" && cp \"${SERVER_LOG_PATH[$1]}\" \"${SERVER_LOG_ARCHIVE_PATH[$1]}/${file_name}\" && gzip \"${SERVER_LOG_ARCHIVE_PATH[$1]}/${file_name}\""
|
||||||
|
|
||||||
if [ -e "${SERVER_LOG_ARCHIVE_PATH[$1]}/${file_name}.gz" ]; then
|
if [ -e "${SERVER_LOG_ARCHIVE_PATH[$1]}/${file_name}.gz" ]; then
|
||||||
as_user "${SERVER_USERNAME[$1]}" "cp \"/dev/null\" \"${SERVER_LOG_PATH[$1]}\""
|
as_user "${SERVER_USERNAME[$1]}" "cp \"/dev/null\" \"${SERVER_LOG_PATH[$1]}\""
|
||||||
as_user "${SERVER_USERNAME[$1]}" "echo \"Previous logs can be found at \\\"${SERVER_LOG_ARCHIVE_PATH[$1]}\\\"\" > \"${SERVER_LOG_PATH[$1]}\""
|
as_user "${SERVER_USERNAME[$1]}" "echo \"Previous logs can be found at \\\"${SERVER_LOG_ARCHIVE_PATH[$1]}\\\"\" > \"${SERVER_LOG_PATH[$1]}\""
|
||||||
@ -1641,7 +1641,7 @@ server_log_roll() {
|
|||||||
error_exit LOGS_NOT_ROLLED "Logs were not rolled."
|
error_exit LOGS_NOT_ROLLED "Logs were not rolled."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1654,17 +1654,17 @@ server_backup() {
|
|||||||
server_property "$1" USERNAME
|
server_property "$1" USERNAME
|
||||||
|
|
||||||
echo -n "Backing up the entire server directory... "
|
echo -n "Backing up the entire server directory... "
|
||||||
|
|
||||||
zip_flags="-rq"
|
zip_flags="-rq"
|
||||||
# Add the "y" flag if symbolic links should not be followed
|
# Add the "y" flag if symbolic links should not be followed
|
||||||
if [ "${SERVER_COMPLETE_BACKUP_FOLLOW_SYMLINKS[$1]}" != "true" ]; then
|
if [ "${SERVER_COMPLETE_BACKUP_FOLLOW_SYMLINKS[$1]}" != "true" ]; then
|
||||||
zip_flags="${zip_flags}y"
|
zip_flags="${zip_flags}y"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Zip up the server directory
|
# Zip up the server directory
|
||||||
file_name="${SERVER_BACKUP_PATH[$1]}/$(date "+%F-%H-%M-%S").zip"
|
file_name="${SERVER_BACKUP_PATH[$1]}/$(date "+%F-%H-%M-%S").zip"
|
||||||
as_user "${SERVER_USERNAME[$1]}" "mkdir -p \"${SERVER_BACKUP_PATH[$1]}\" && cd \"$SETTINGS_SERVER_STORAGE_PATH\" && zip ${zip_flags} \"${file_name}\" \"${SERVER_NAME[$1]}\""
|
as_user "${SERVER_USERNAME[$1]}" "mkdir -p \"${SERVER_BACKUP_PATH[$1]}\" && cd \"$SETTINGS_SERVER_STORAGE_PATH\" && zip ${zip_flags} \"${file_name}\" \"${SERVER_NAME[$1]}\""
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1678,10 +1678,10 @@ server_set_jar() {
|
|||||||
server_property "$1" USERNAME
|
server_property "$1" USERNAME
|
||||||
|
|
||||||
if [ -d "$SETTINGS_JAR_STORAGE_PATH/$2" ]; then
|
if [ -d "$SETTINGS_JAR_STORAGE_PATH/$2" ]; then
|
||||||
|
|
||||||
if [ -z "$3" ]; then
|
if [ -z "$3" ]; then
|
||||||
# If a specific jar file is not mentioned
|
# If a specific jar file is not mentioned
|
||||||
|
|
||||||
# Download the latest version
|
# Download the latest version
|
||||||
jargroup_getlatest "$2"
|
jargroup_getlatest "$2"
|
||||||
get_latest_file "$SETTINGS_JAR_STORAGE_PATH/$2"
|
get_latest_file "$SETTINGS_JAR_STORAGE_PATH/$2"
|
||||||
@ -1689,12 +1689,12 @@ server_set_jar() {
|
|||||||
else
|
else
|
||||||
# If a specific jar IS mentioned use that
|
# If a specific jar IS mentioned use that
|
||||||
local jar="$SETTINGS_JAR_STORAGE_PATH/$2/$3"
|
local jar="$SETTINGS_JAR_STORAGE_PATH/$2/$3"
|
||||||
|
|
||||||
if [[ ! -e "$jar" ]]; then
|
if [[ ! -e "$jar" ]]; then
|
||||||
error_exit NAME_NOT_FOUND "There is no jar named \"$3\" in jargroup \"$2\"."
|
error_exit NAME_NOT_FOUND "There is no jar named \"$3\" in jargroup \"$2\"."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -z "$jar" ]]; then
|
if [[ ! -z "$jar" ]]; then
|
||||||
as_user "${SERVER_USERNAME[$1]}" "ln -sf \"$jar\" \"${SERVER_JAR_PATH[$1]}\""
|
as_user "${SERVER_USERNAME[$1]}" "ln -sf \"$jar\" \"${SERVER_JAR_PATH[$1]}\""
|
||||||
echo "Server \"${SERVER_NAME[$1]}\" is now using \"$jar\"."
|
echo "Server \"${SERVER_NAME[$1]}\" is now using \"$jar\"."
|
||||||
@ -1738,7 +1738,7 @@ server_property() {
|
|||||||
if [ -z "$value" ]; then
|
if [ -z "$value" ]; then
|
||||||
# If the value is empty it has not been loaded yet
|
# If the value is empty it has not been loaded yet
|
||||||
|
|
||||||
# These properties are not overridable
|
# These properties are not overridable
|
||||||
case "$2" in
|
case "$2" in
|
||||||
NAME|PATH)
|
NAME|PATH)
|
||||||
# Defined at allocation
|
# Defined at allocation
|
||||||
@ -1893,7 +1893,7 @@ server_dirty_properties() {
|
|||||||
### -----------------
|
### -----------------
|
||||||
|
|
||||||
# Stops all running servers after a servers specified delay
|
# Stops all running servers after a servers specified delay
|
||||||
# $1: String containing "stop" or "restart". Represents whether the stop is
|
# $1: String containing "stop" or "restart". Represents whether the stop is
|
||||||
# with a mind to stop the server, or just to restart it. And affects
|
# with a mind to stop the server, or just to restart it. And affects
|
||||||
# the message issued to players on a server.
|
# the message issued to players on a server.
|
||||||
manager_stop_all_servers() {
|
manager_stop_all_servers() {
|
||||||
@ -1901,10 +1901,10 @@ manager_stop_all_servers() {
|
|||||||
local was_running
|
local was_running
|
||||||
# False if no servers were running at all
|
# False if no servers were running at all
|
||||||
local any_running="false"
|
local any_running="false"
|
||||||
|
|
||||||
# For all running servers issue the stop warning
|
# For all running servers issue the stop warning
|
||||||
local max_countdown=0
|
local max_countdown=0
|
||||||
|
|
||||||
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
||||||
if server_is_running "$server"; then
|
if server_is_running "$server"; then
|
||||||
any_running="true"
|
any_running="true"
|
||||||
@ -1918,21 +1918,21 @@ manager_stop_all_servers() {
|
|||||||
if [[ "${SERVER_STOP_DELAY[$server]}" -gt "$max_countdown" ]]; then
|
if [[ "${SERVER_STOP_DELAY[$server]}" -gt "$max_countdown" ]]; then
|
||||||
max_countdown="${SERVER_STOP_DELAY[$server]}"
|
max_countdown="${SERVER_STOP_DELAY[$server]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Send a warning message to the server
|
# Send a warning message to the server
|
||||||
case "$1" in
|
case "$1" in
|
||||||
stop) server_eval "$server" "say ${SERVER_MESSAGE_STOP[$server]}";;
|
stop) server_eval "$server" "say ${SERVER_MESSAGE_STOP[$server]}";;
|
||||||
restart) server_eval "$server" "say ${SERVER_MESSAGE_RESTART[$server]}";;
|
restart) server_eval "$server" "say ${SERVER_MESSAGE_RESTART[$server]}";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Send message to stdout
|
# Send message to stdout
|
||||||
echo "Server \"${SERVER_NAME[$server]}\" was running, now stopping:"
|
echo "Server \"${SERVER_NAME[$server]}\" was running, now stopping:"
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
stop) echo " Issued the warning \"${SERVER_MESSAGE_STOP[$server]}\" to players.";;
|
stop) echo " Issued the warning \"${SERVER_MESSAGE_STOP[$server]}\" to players.";;
|
||||||
restart) echo " Issued the warning \"${SERVER_MESSAGE_RESTART[$server]}\" to players.";;
|
restart) echo " Issued the warning \"${SERVER_MESSAGE_RESTART[$server]}\" to players.";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "${SERVER_STOP_DELAY[$server]}" in
|
case "${SERVER_STOP_DELAY[$server]}" in
|
||||||
0) echo " Stopping without delay.";;
|
0) echo " Stopping without delay.";;
|
||||||
1) echo " Stopping after 1 second.";;
|
1) echo " Stopping after 1 second.";;
|
||||||
@ -1943,20 +1943,20 @@ manager_stop_all_servers() {
|
|||||||
was_running[$server]="false"
|
was_running[$server]="false"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if "$any_running"; then
|
if "$any_running"; then
|
||||||
# Wait for the maximum possible delay, stopping servers
|
# Wait for the maximum possible delay, stopping servers
|
||||||
# at the correct times
|
# at the correct times
|
||||||
echo -n "All servers will have been issued the stop command... "
|
echo -n "All servers will have been issued the stop command... "
|
||||||
for ((tick="${max_countdown}"; tick>=0; tick--)); do
|
for ((tick="${max_countdown}"; tick>=0; tick--)); do
|
||||||
tput sc # Save cursor position
|
tput sc # Save cursor position
|
||||||
|
|
||||||
if [[ "$tick" -le 1 ]]; then
|
if [[ "$tick" -le 1 ]]; then
|
||||||
echo -n "in $tick second."
|
echo -n "in $tick second."
|
||||||
else
|
else
|
||||||
echo -n "in $tick seconds."
|
echo -n "in $tick seconds."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Each second check all servers, to see if it's their time to
|
# Each second check all servers, to see if it's their time to
|
||||||
# stop. If so issue the stop command, and don't wait.
|
# stop. If so issue the stop command, and don't wait.
|
||||||
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
||||||
@ -1968,7 +1968,7 @@ manager_stop_all_servers() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$tick" > 0 ]]; then
|
if [[ "$tick" > 0 ]]; then
|
||||||
sleep 1
|
sleep 1
|
||||||
fi
|
fi
|
||||||
@ -1976,10 +1976,10 @@ manager_stop_all_servers() {
|
|||||||
tput rc # Restore cursor to position of last `sc'
|
tput rc # Restore cursor to position of last `sc'
|
||||||
tput el # Clear to end of line
|
tput el # Clear to end of line
|
||||||
done
|
done
|
||||||
|
|
||||||
# Start a new line
|
# Start a new line
|
||||||
echo "Now."
|
echo "Now."
|
||||||
|
|
||||||
# Finally check all servers have stopped
|
# Finally check all servers have stopped
|
||||||
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
||||||
if "${was_running[$server]}"; then
|
if "${was_running[$server]}"; then
|
||||||
@ -1999,7 +1999,7 @@ manager_stop_all_servers_now() {
|
|||||||
local was_running
|
local was_running
|
||||||
# False if no servers were running at all
|
# False if no servers were running at all
|
||||||
local any_running="false"
|
local any_running="false"
|
||||||
|
|
||||||
# Stop all servers at the same time
|
# Stop all servers at the same time
|
||||||
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
||||||
if server_is_running "$server"; then
|
if server_is_running "$server"; then
|
||||||
@ -2013,7 +2013,7 @@ manager_stop_all_servers_now() {
|
|||||||
was_running[$server]="false"
|
was_running[$server]="false"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if "$any_running"; then
|
if "$any_running"; then
|
||||||
# Ensure all the servers have stopped
|
# Ensure all the servers have stopped
|
||||||
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
for ((server=0; server<${NUM_SERVERS}; server++)); do
|
||||||
@ -2110,7 +2110,7 @@ command_stop_now() {
|
|||||||
command_restart() {
|
command_restart() {
|
||||||
echo "Stopping servers:"
|
echo "Stopping servers:"
|
||||||
manager_stop_all_servers "restart"
|
manager_stop_all_servers "restart"
|
||||||
|
|
||||||
echo "Starting servers:"
|
echo "Starting servers:"
|
||||||
command_start
|
command_start
|
||||||
}
|
}
|
||||||
@ -2119,7 +2119,7 @@ command_restart() {
|
|||||||
command_restart_now() {
|
command_restart_now() {
|
||||||
echo "Stopping servers:"
|
echo "Stopping servers:"
|
||||||
manager_stop_all_servers_now
|
manager_stop_all_servers_now
|
||||||
|
|
||||||
echo "Starting servers:"
|
echo "Starting servers:"
|
||||||
command_start
|
command_start
|
||||||
}
|
}
|
||||||
@ -2359,7 +2359,7 @@ command_update() {
|
|||||||
source "$COMPLETION"
|
source "$COMPLETION"
|
||||||
|
|
||||||
if "$created"; then
|
if "$created"; then
|
||||||
echo " > Created: $COMPLETION"
|
echo " > Created: $COMPLETION"
|
||||||
else
|
else
|
||||||
echo " > Updated: $COMPLETION"
|
echo " > Updated: $COMPLETION"
|
||||||
fi
|
fi
|
||||||
@ -2379,7 +2379,7 @@ command_update() {
|
|||||||
as_user "root" "chmod +x \"$SCRIPT\""
|
as_user "root" "chmod +x \"$SCRIPT\""
|
||||||
|
|
||||||
if "$created"; then
|
if "$created"; then
|
||||||
echo " > Created: $SCRIPT"
|
echo " > Created: $SCRIPT"
|
||||||
else
|
else
|
||||||
echo " > Updated: $SCRIPT"
|
echo " > Updated: $SCRIPT"
|
||||||
fi
|
fi
|
||||||
@ -2410,7 +2410,7 @@ command_update() {
|
|||||||
as_user "root" "chown ${SETTINGS_USERNAME}:${SETTINGS_USERNAME} \"$version_path\""
|
as_user "root" "chown ${SETTINGS_USERNAME}:${SETTINGS_USERNAME} \"$version_path\""
|
||||||
|
|
||||||
if "$created"; then
|
if "$created"; then
|
||||||
echo " > Created: $version_path"
|
echo " > Created: $version_path"
|
||||||
else
|
else
|
||||||
echo " > Updated: $version_path"
|
echo " > Updated: $version_path"
|
||||||
fi
|
fi
|
||||||
@ -3237,7 +3237,7 @@ register_setting() {
|
|||||||
SETTING_COUNT=$(( $SETTING_COUNT + 1 ))
|
SETTING_COUNT=$(( $SETTING_COUNT + 1 ))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Registers a setting that can be defined for each server
|
# Registers a setting that can be defined for each server
|
||||||
# $1: Server setting name to register
|
# $1: Server setting name to register
|
||||||
# $2: Optionally a default value
|
# $2: Optionally a default value
|
||||||
register_server_setting() {
|
register_server_setting() {
|
||||||
@ -3278,7 +3278,7 @@ register_settings() {
|
|||||||
register_setting JARGROUP_TARGET "target.txt"
|
register_setting JARGROUP_TARGET "target.txt"
|
||||||
register_setting JARGROUP_DOWNLOAD_DIR "downloads"
|
register_setting JARGROUP_DOWNLOAD_DIR "downloads"
|
||||||
register_setting SERVER_PROPERTIES "server.properties"
|
register_setting SERVER_PROPERTIES "server.properties"
|
||||||
|
|
||||||
register_server_setting USERNAME "minecraft"
|
register_server_setting USERNAME "minecraft"
|
||||||
register_server_setting SCREEN_NAME "msm-{SERVER_NAME}"
|
register_server_setting SCREEN_NAME "msm-{SERVER_NAME}"
|
||||||
register_server_setting VERSION "unknown"
|
register_server_setting VERSION "unknown"
|
||||||
@ -3335,9 +3335,9 @@ register_command() {
|
|||||||
# Here we build a regular expression which will match any user input
|
# Here we build a regular expression which will match any user input
|
||||||
# that could be passed to the given handler function. It is derived
|
# that could be passed to the given handler function. It is derived
|
||||||
# automatically from the given command signature.
|
# automatically from the given command signature.
|
||||||
|
|
||||||
local regex="^"
|
local regex="^"
|
||||||
|
|
||||||
# Iterate over each element in the command signature
|
# Iterate over each element in the command signature
|
||||||
for word in $1; do
|
for word in $1; do
|
||||||
# Variables are denoted by angle brackets (e.g. "<variable>") and can
|
# Variables are denoted by angle brackets (e.g. "<variable>") and can
|
||||||
@ -3356,7 +3356,7 @@ register_command() {
|
|||||||
esac
|
esac
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Sometimes different worlds may be used to call the same command, in
|
# Sometimes different worlds may be used to call the same command, in
|
||||||
# these cases, the different words may be written contiguously,
|
# these cases, the different words may be written contiguously,
|
||||||
# separated by the pipe character (i.e. "|") and any of the options
|
# separated by the pipe character (i.e. "|") and any of the options
|
||||||
@ -3365,20 +3365,20 @@ register_command() {
|
|||||||
regex="${regex}($word) "
|
regex="${regex}($word) "
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Anything else found in the command signature will be taken to mean
|
# Anything else found in the command signature will be taken to mean
|
||||||
# a fixed string, which must be provided to match this command.
|
# a fixed string, which must be provided to match this command.
|
||||||
regex="${regex}$word "
|
regex="${regex}$word "
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ ${#regex} -ge 1 ]; then
|
if [ ${#regex} -ge 1 ]; then
|
||||||
regex="${regex:0:${#regex}-1}\$"
|
regex="${regex:0:${#regex}-1}\$"
|
||||||
|
|
||||||
# Sets the global command variables in order to register this command
|
# Sets the global command variables in order to register this command
|
||||||
COMMAND_SIGNATURE[$COMMAND_COUNT]="$1"
|
COMMAND_SIGNATURE[$COMMAND_COUNT]="$1"
|
||||||
COMMAND_REGEX[$COMMAND_COUNT]="$regex"
|
COMMAND_REGEX[$COMMAND_COUNT]="$regex"
|
||||||
COMMAND_HANDLER[$COMMAND_COUNT]="$2"
|
COMMAND_HANDLER[$COMMAND_COUNT]="$2"
|
||||||
|
|
||||||
COMMAND_COUNT=$(( $COMMAND_COUNT + 1 ))
|
COMMAND_COUNT=$(( $COMMAND_COUNT + 1 ))
|
||||||
else
|
else
|
||||||
error_exit FATAL_ERROR "Fatal error: Sorry about this, would you be so kind as to file a bug at http://git.io/2f_x-A and cite: \"Erroneous command regex '${regex}' for signature '${1}'\""
|
error_exit FATAL_ERROR "Fatal error: Sorry about this, would you be so kind as to file a bug at http://git.io/2f_x-A and cite: \"Erroneous command regex '${regex}' for signature '${1}'\""
|
||||||
@ -3423,7 +3423,7 @@ call_command() {
|
|||||||
args[$arg_offset]="$1"
|
args[$arg_offset]="$1"
|
||||||
arg_offset="$(( $arg_offset + 1 ))"
|
arg_offset="$(( $arg_offset + 1 ))"
|
||||||
}
|
}
|
||||||
|
|
||||||
# The following loop builds a set of arguments to pass to the
|
# The following loop builds a set of arguments to pass to the
|
||||||
# matched command handler function. Rather than passing all args
|
# matched command handler function. Rather than passing all args
|
||||||
# given to the script, to the handler (which may contain constant
|
# given to the script, to the handler (which may contain constant
|
||||||
@ -3443,8 +3443,8 @@ call_command() {
|
|||||||
# Do no checks, just push the argument onto the stack
|
# Do no checks, just push the argument onto the stack
|
||||||
push_arg "${!word_offset}"
|
push_arg "${!word_offset}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
# The "<strings>" token must only be placed at the end of a
|
# The "<strings>" token must only be placed at the end of a
|
||||||
# command signature, and allows an arbitrary amount of
|
# command signature, and allows an arbitrary amount of
|
||||||
# arguments to be passed to the command handler function.
|
# arguments to be passed to the command handler function.
|
||||||
@ -3481,8 +3481,8 @@ call_command() {
|
|||||||
word_offset=$(( $word_offset + $num_flags - 1 ))
|
word_offset=$(( $word_offset + $num_flags - 1 ))
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
# The "<name>" token is similar to "<string>" but adds an
|
# The "<name>" token is similar to "<string>" but adds an
|
||||||
# extra assurance that the string is a valid name, as used
|
# extra assurance that the string is a valid name, as used
|
||||||
# for creating servers and other things.
|
# for creating servers and other things.
|
||||||
@ -3494,8 +3494,8 @@ call_command() {
|
|||||||
push_arg "$specified_name"
|
push_arg "$specified_name"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
# The "<name:server>" token improves on "<name>" by also
|
# The "<name:server>" token improves on "<name>" by also
|
||||||
# checking that the server exists, and passing the argument
|
# checking that the server exists, and passing the argument
|
||||||
# on as the server id, instead of the server name to
|
# on as the server id, instead of the server name to
|
||||||
@ -3520,8 +3520,8 @@ call_command() {
|
|||||||
|
|
||||||
push_arg "$sid"
|
push_arg "$sid"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
# The "<name:world>" token also improves upon "<name>" by
|
# The "<name:world>" token also improves upon "<name>" by
|
||||||
# ensuring that the world actually exists, and passes the
|
# ensuring that the world actually exists, and passes the
|
||||||
# argument on to command handlers as the world ID, rather
|
# argument on to command handlers as the world ID, rather
|
||||||
@ -3580,16 +3580,16 @@ call_command() {
|
|||||||
replaced_args[$k]="${args[$k]//server:all/${WORLD_SERVER_ID[$j]}}"
|
replaced_args[$k]="${args[$k]//server:all/${WORLD_SERVER_ID[$j]}}"
|
||||||
replaced_args[$k]="${args[$k]//world:all/$j}"
|
replaced_args[$k]="${args[$k]//world:all/$j}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Call the function with the specific replaced args
|
# Call the function with the specific replaced args
|
||||||
${COMMAND_HANDLER[$command]} "${replaced_args[@]}"
|
${COMMAND_HANDLER[$command]} "${replaced_args[@]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Prevent the default singular call later on.
|
# Prevent the default singular call later on.
|
||||||
unset COMMAND_FLAGS; return
|
unset COMMAND_FLAGS; return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# This calls the handler for all possible servers, and preserves
|
# This calls the handler for all possible servers, and preserves
|
||||||
# all other arguments.
|
# all other arguments.
|
||||||
if [[ "$sid" == "server:all" ]]; then
|
if [[ "$sid" == "server:all" ]]; then
|
||||||
for ((j=0; j<$NUM_SERVERS; j++)); do
|
for ((j=0; j<$NUM_SERVERS; j++)); do
|
||||||
@ -3597,13 +3597,13 @@ call_command() {
|
|||||||
for k in ${!args[@]}; do
|
for k in ${!args[@]}; do
|
||||||
replaced_args[$k]="${args[$k]//server\:all/$j}"
|
replaced_args[$k]="${args[$k]//server\:all/$j}"
|
||||||
done
|
done
|
||||||
|
|
||||||
${COMMAND_HANDLER[$command]} "${replaced_args[@]}"
|
${COMMAND_HANDLER[$command]} "${replaced_args[@]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
unset COMMAND_FLAGS; return
|
unset COMMAND_FLAGS; return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# This calls the handlers for all possible worlds for a specific
|
# This calls the handlers for all possible worlds for a specific
|
||||||
# server.
|
# server.
|
||||||
if [[ "$sid" != "server:all" ]] && [[ "$wid" == "world:all" ]]; then
|
if [[ "$sid" != "server:all" ]] && [[ "$wid" == "world:all" ]]; then
|
||||||
@ -3612,19 +3612,19 @@ call_command() {
|
|||||||
for k in ${!args[@]}; do
|
for k in ${!args[@]}; do
|
||||||
replaced_args[$k]="${args[$k]//world:all/$j}"
|
replaced_args[$k]="${args[$k]//world:all/$j}"
|
||||||
done
|
done
|
||||||
|
|
||||||
${COMMAND_HANDLER[$command]} "${replaced_args[@]}"
|
${COMMAND_HANDLER[$command]} "${replaced_args[@]}"
|
||||||
done
|
done
|
||||||
|
|
||||||
unset COMMAND_FLAGS; return
|
unset COMMAND_FLAGS; return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Otherwise it's a simple single call of the handler.
|
# Otherwise it's a simple single call of the handler.
|
||||||
${COMMAND_HANDLER[$command]} "${args[@]}"
|
${COMMAND_HANDLER[$command]} "${args[@]}"
|
||||||
unset COMMAND_FLAGS; return
|
unset COMMAND_FLAGS; return
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "No such command. See $0 help"
|
echo "No such command. See $0 help"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3661,14 +3661,14 @@ register_commands() {
|
|||||||
# <name:world> Same as "<name>", also converts value to world id or
|
# <name:world> Same as "<name>", also converts value to world id or
|
||||||
# fails if the world does not exist. Must only be
|
# fails if the world does not exist. Must only be
|
||||||
# included after a "<name:server>" element.
|
# included after a "<name:server>" element.
|
||||||
#
|
#
|
||||||
# Elements listed above encapsulated within angle brackets must be included
|
# Elements listed above encapsulated within angle brackets must be included
|
||||||
# within a signature verbatim, as opposed to the "fixedstring" element
|
# within a signature verbatim, as opposed to the "fixedstring" element
|
||||||
# which is arbitrary.
|
# which is arbitrary.
|
||||||
#
|
#
|
||||||
# Variables passed to handler functions are of course positional and there
|
# Variables passed to handler functions are of course positional and there
|
||||||
# position matches the position of that element in the command signature.
|
# position matches the position of that element in the command signature.
|
||||||
|
|
||||||
register_command "start" "command_start"
|
register_command "start" "command_start"
|
||||||
register_command "stop" "command_stop"
|
register_command "stop" "command_stop"
|
||||||
register_command "stop now" "command_stop_now"
|
register_command "stop now" "command_stop_now"
|
||||||
@ -3960,7 +3960,7 @@ interrupt() {
|
|||||||
server_eval "$i" "say ${SERVER_MESSAGE_STOP_ABORT[$i]}"
|
server_eval "$i" "say ${SERVER_MESSAGE_STOP_ABORT[$i]}"
|
||||||
echo "Server \"${SERVER_NAME[$i]}\" shutdown was aborted."
|
echo "Server \"${SERVER_NAME[$i]}\" shutdown was aborted."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${RESTART_COUNTDOWN[$i]}" == "true" ]] && server_is_running "$i"; then
|
if [[ "${RESTART_COUNTDOWN[$i]}" == "true" ]] && server_is_running "$i"; then
|
||||||
if [[ "$exit_message" == "false" ]]; then
|
if [[ "$exit_message" == "false" ]]; then
|
||||||
echo -e "\nInterrupted..."
|
echo -e "\nInterrupted..."
|
||||||
@ -4070,7 +4070,7 @@ main() {
|
|||||||
|
|
||||||
# Trap interrupts to the script by calling the interrupt function
|
# Trap interrupts to the script by calling the interrupt function
|
||||||
trap interrupt EXIT
|
trap interrupt EXIT
|
||||||
|
|
||||||
# This function call matches the user input to a registered command
|
# This function call matches the user input to a registered command
|
||||||
# signature, and then calls that command's handler function with positional
|
# signature, and then calls that command's handler function with positional
|
||||||
# arguments containing any "variable" strings.
|
# arguments containing any "variable" strings.
|
||||||
|
Loading…
Reference in New Issue
Block a user