From 65db94382b48d77d331b857369e662d80f6a6ed4 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 12 Jan 2025 14:53:10 +0100 Subject: [PATCH] Adding download of metadata file in bin/update-nextcloud; adding option to disable backup in bin/update-nextcloud --- bin/update-nextcloud | 64 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/bin/update-nextcloud b/bin/update-nextcloud index ff1f3c7..d02ea7d 100755 --- a/bin/update-nextcloud +++ b/bin/update-nextcloud @@ -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 -- 2.39.5