Updated Usage function

This commit is contained in:
Price Hiller 2021-07-31 19:19:21 -05:00
parent ba6ca6e2c2
commit 4ce9c4031b

View File

@ -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 <string> | -i <string>
printf "Usage: %s\n" \
"$(basename "${0}") -s <server id> | $(basename "${0}") -s <server id> -r | $(basename "${0}") -s <server id> -j <path/to/minecraft/jar>
--server <server id> -s <server id>
Which minecraft server to start, see the ~/Minecraft directory -- each number corresponds to an ID
Example:
--input \"this is an example input\"
--test <string> | -t <string>
--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 <path/to/mc/server/jar/file> | -j <path/to/mc/server/jar/file>
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}"