]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Checking preferences
authorFrank Brehm <frank@brehm-online.com>
Sun, 18 Apr 2021 12:32:13 +0000 (14:32 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sun, 18 Apr 2021 12:32:13 +0000 (14:32 +0200)
bin/update-minecraft-server-jar.sh

index f7e1ed18a877d75a848561d9af4b5439d78ed5aa..2c309bd930dfabcb80a024b033d2cb51621103b6 100755 (executable)
@@ -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