]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Start with downloading
authorFrank Brehm <frank@brehm-online.com>
Mon, 19 Apr 2021 10:26:42 +0000 (12:26 +0200)
committerFrank Brehm <frank@brehm-online.com>
Mon, 19 Apr 2021 10:26:42 +0000 (12:26 +0200)
bin/update-minecraft-server-jar

index 08f6879366865cc2f008fecb9fa41c07529d4658..30282abad8c0128fe41177379e02370676ef731d 100755 (executable)
@@ -24,11 +24,15 @@ MC_SERVER_DIR="${MC_ROOT_DIR}/server"
 SERVER_JAR="${MC_SERVER_DIR}/minecraft_server.jar"
 MC_SERVER_CUR_LINK_BASE="minecraft_server.current.jar"
 
+MC_USER="minecraft"
+MC_GROUP="users"
+
 VERSION_MANIFEST='https://launchermeta.mojang.com/mc/game/version_manifest.json'
 
 CURRENT_VERSION=
 UPSTREAM_VERSION=
 DOWNLOAD_URL=
+TARGET_JAR=
 
 DESCRIPTION=$( cat <<-EOF
        Update Micraft server .jar file.
@@ -98,6 +102,8 @@ check_preferences() {
     info "Checking preferences ..."
     local all_ok="y"
 
+    check_for_root
+
     local -a tools=('curl' 'jq')
     local tool=
     local folder=
@@ -181,6 +187,28 @@ get_upstream_info() {
         exit 7
     fi
     debug "Download URL: '${CYAN}${DOWNLOAD_URL}${NORMAL}'."
+    TARGET_JAR="minecraft_server.${UPSTREAM_VERSION}.jar"
+
+}
+
+#------------------------------------------------------------------------------
+do_download() {
+
+    info "Downloading upstream server.jar => '${CYAN}${TARGET_JAR}${NORMAL}' ..."
+
+    if [[ -f "${TARGET_JAR}" ]] ; then
+        warn "Server jar file '${YELLOW}${MC_BACKUP_DIR}/${TARGET_JAR}${NORMAL}' already exists."
+        return
+    fi
+
+    local cmd="curl -o \"${TARGET_JAR}\" -s \"${DOWNLOAD_URL}\""
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}"
+    else
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+    fi
+    CHOWN "${MC_USER}:${MC_GROUP}" "${TARGET_JAR}"
 
 }
 
@@ -197,6 +225,7 @@ main() {
         info "Version '${GREEN}${UPSTREAM_VERSION}${NORMAL}' not changed, no update."
         exit 0
     fi
+    do_download
 
 }