From 8ce5947ad770f9da68747b5fa57b00261e787ce6 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 18 Apr 2021 14:32:13 +0200 Subject: [PATCH] Checking preferences --- bin/update-minecraft-server-jar.sh | 116 +++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/bin/update-minecraft-server-jar.sh b/bin/update-minecraft-server-jar.sh index f7e1ed1..2c309bd 100755 --- a/bin/update-minecraft-server-jar.sh +++ b/bin/update-minecraft-server-jar.sh @@ -18,6 +18,122 @@ else fi +MC_ROOT_DIR="/home/minecraft" +MC_BACKUP_DIR="${MC_ROOT_DIR}/backup" +MC_SERVER_DIR="${MC_ROOT_DIR}/server" +SERVER_JAR="${MC_SERVER_DIR}/minecraft_server.jar" + +VERSION_MANIFEST='https://launchermeta.mojang.com/mc/game/version_manifest.json' + +CURRENT_VERSION= +UPSTREAM_VERSION= + +DESCRIPTION=$( cat <<-EOF + Update Micraft server .jar file. + + EOF + +#------------------------------------------------------------------------------ +usage() { + cat <<-EOF + Usage: ${BASE_NAME} [Common Options] + ${BASE_NAME} [-h|--help] + ${BASE_NAME} [-V|--version] + + Common Options: + ${STD_USAGE_MSG} + EOF + +} + +#------------------------------------------------------------------------------ +get_options() { + + local tmp= + local base_dir= + + set +e + tmp=$( getopt -o ${STD_SHORT_OPTIONS} --long ${STD_LONG_OPTIONS} -n "${BASE_NAME}" -- "$@" ) + if [[ $? != 0 ]] ; then + echo "" >&2 + usage >&2 + exit 1 + fi + set -e + + # Note the quotes around `$TEMP': they are essential! + eval set -- "${tmp}" + eval_common_options "$@" + if [[ "${DEBUG}" == 'y' ]] ; then + declare -p REMAINING_OPTS + declare -p REMAINING_ARGS + fi + + if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then + error "Unknown options: ${REMAINING_OPTS[*]}" + echo >&2 + usage >&2 + exit 2 + fi + + if [[ "${#REMAINING_ARGS[@]}" -gt 0 ]] ; then + error "Invalid arguments: ${REMAINING_ARGS[*]}" + echo >&2 + usage >&2 + exit 2 + fi + + check_for_root + + LOGFILE="/var/log/${BASE_NAME}.log" + +} + +#------------------------------------------------------------------------------ +check_preferences() { + + info "Checking preferences ..." + local all_ok="y" + + local -a tools=('curl' 'jq') + local tool= + local folder= + + for tool in "${tools[@]}" ; do + debug "Checking for '${CYAN}${tool}${NORMAL}' ..." + if type -p ${tool} >/dev/null ; then + : + else + all_ok="n" + error "Did not found '${RED}${tool}${NORMAL}'. Maybe not installed?" + fi + done + + for folder in "${MC_BACKUP_DIR}" "${MC_SERVER_DIR}" ; do + debug "Checking for directory '${folder}' ..." + if [[ ! -d "${folder}" ]]; then + all_ok="n" + error "Did not found directory '${RED}${folder}${NORMAL}'." + fi + done + + if [[ "${all_ok}" != "y" ]] ; then + exit 5 + fi + +} + +#------------------------------------------------------------------------------ +main() { + + get_options "$@" + umask 0022 + + check_preferences +} + +main "$@" + exit 0 # vim: et list -- 2.39.5