]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding download of metadata file in bin/update-nextcloud; adding option to disable...
authorFrank Brehm <frank@brehm-online.com>
Sun, 12 Jan 2025 13:53:10 +0000 (14:53 +0100)
committerFrank Brehm <frank@brehm-online.com>
Sun, 12 Jan 2025 13:53:10 +0000 (14:53 +0100)
bin/update-nextcloud

index ff1f3c7b87f9346b248afe3ee7041bdf89e7e57b..d02ea7db3a754115da7151b5a6a3e1081e4f1bc7 100755 (executable)
@@ -19,6 +19,7 @@ NEXTCLOUD_DIR_NEW="${NEXTCLOUD_DIR}.new"
 NEXTCLOUD_DIR_OLD="${NEXTCLOUD_DIR}.old"
 DOWNLOAD_DIR="/root/Downloads"
 ARTIFACT="nextcloud-bla.tar.bz2"
+METADATA="nextcloud-bla.metadata"
 MD5_FILE="${ARTIFACT}.md5"
 SHA256_FILE="${ARTIFACT}.sha256"
 SHA512_FILE="${ARTIFACT}.sha512"
@@ -49,6 +50,8 @@ if [[ -f "${CONF_FILE}" ]] ; then
     . "${CONF_FILE}"
 fi
 
+DO_BACKUP="y"
+
 DESCRIPTION=$( cat <<-EOF
        Updates the local Nextcloud installation under '${CYAN}${NEXTCLOUD_DIR}${NORMAL}'.
 
@@ -60,7 +63,7 @@ DESCRIPTION=$( cat <<-EOF
 #------------------------------------------------------------------------------
 usage() {
     cat <<-EOF
-       Usage: ${BASE_NAME} NEXTCLOUD_VERSION [Common Options]
+       Usage: ${BASE_NAME} [-N|--no-backup] NEXTCLOUD_VERSION [Common Options]
               ${BASE_NAME} [-h|--help]
               ${BASE_NAME} [-V|--version]
 
@@ -70,14 +73,51 @@ usage() {
 
 }
 
+#------------------------------------------------------------------------------
+eval_my_options() {
+
+    debug "Evaluating my options."
+
+    REMAINING_ARGS=()
+    REMAINING_OPTS=()
+
+    if [[ "$#" -gt 0 ]] ; then
+        while true ; do
+            case "$1" in
+                -N|--no-backup)
+                    DO_BACKUP=""
+                    shift
+                    ;;
+                --) shift
+                    break
+                    ;;
+                *)  REMAINING_OPTS+=($1)
+                    shift
+                    ;;
+            esac
+        done
+    fi
+
+    if [[ "$#" -gt "0" ]] ; then
+        # REMAINING_ARGS=("--")
+        while [[ "$#" -gt "0" ]]  ; do
+            REMAINING_ARGS+=($1)
+            shift
+        done
+    fi
+
+}
+
 #------------------------------------------------------------------------------
 get_options() {
 
     local tmp=
     local base_dir=
+    local short_options="${STD_SHORT_OPTIONS}N"
+    local long_options="${STD_LONG_OPTIONS},no-backup"
 
     set +e
-    tmp=$( getopt -o ${STD_SHORT_OPTIONS} --long ${STD_LONG_OPTIONS} -n "${BASE_NAME}" -- "$@" )
+    tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASE_NAME}" -- "$@" )
     if [[ $? != 0 ]] ; then
         echo "" >&2
         usage >&2
@@ -93,6 +133,12 @@ get_options() {
         declare -p REMAINING_ARGS
     fi
 
+    eval_my_options "${REMAINING_OPTS[@]}" -- "${REMAINING_ARGS[@]}"
+    if [[ "${DEBUG}" ]] ; then
+        declare -p REMAINING_OPTS
+        declare -p REMAINING_ARGS
+    fi
+
     if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then
         error "Unknown options: ${REMAINING_OPTS[*]}"
         echo >&2
@@ -117,10 +163,15 @@ get_options() {
 
     NEW_VERSION="${REMAINING_ARGS[1]}"
     ARTIFACT="nextcloud-${NEW_VERSION}.tar.bz2"
+    METADATA="nextcloud-${NEW_VERSION}.metadata"
     MD5_FILE="${ARTIFACT}.md5"
     SHA256_FILE="${ARTIFACT}.sha256"
     SHA512_FILE="${ARTIFACT}.sha512"
 
+    if [[ -z "${DO_BACKUP}" ]] ; then
+        warn "Backup of current Nextcloud directory '${CYAN}${WWW_BASE}/nextcloud${NORMAL}' will not be executed."
+    fi
+
     check_for_root
 
 }
@@ -237,6 +288,7 @@ download_release() {
     cd "${DOWNLOAD_DIR}"
 
     local release_url="${DOWNLOAD_URL_BASE}/${ARTIFACT}"
+    local metadata_url="${DOWNLOAD_URL_BASE}/${METADATA}"
     local md5_url="${DOWNLOAD_URL_BASE}/${MD5_FILE}"
     local sha256_url="${DOWNLOAD_URL_BASE}/${SHA256_FILE}"
     local sha512_url="${DOWNLOAD_URL_BASE}/${SHA512_FILE}"
@@ -245,6 +297,10 @@ download_release() {
         WGET "${release_url}"
     fi
 
+    if [[ ! -f "${METADATA}" ]] ; then
+        WGET "${metadata_url}"
+    fi
+
     if [[ ! -f "${MD5_FILE}" ]] ; then
         WGET "${md5_url}"
     fi
@@ -452,7 +508,9 @@ main() {
     debug "Verbose level is '${CYAN}${VERBOSE}${NORMAL}'."
 
     get_old_version
-    do_backup
+    if [[ "${DO_BACKUP}" ]] ; then
+        do_backup
+    fi
     download_release
     unpack_archive
     adjust_permissions