]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Starting with bin/update-nextcloud
authorFrank Brehm <frank@brehm-online.com>
Sat, 25 Apr 2020 15:32:37 +0000 (17:32 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sat, 25 Apr 2020 15:32:37 +0000 (17:32 +0200)
bin/update-nextcloud [new file with mode: 0755]
lib/functions.rc

diff --git a/bin/update-nextcloud b/bin/update-nextcloud
new file mode 100755 (executable)
index 0000000..667eba8
--- /dev/null
@@ -0,0 +1,160 @@
+#!/bin/bash
+
+set -e
+set -u
+
+BASE_NAME="$( basename ${0} )"
+MY_REAL_NAME=$( readlink -f $0 )
+BIN_DIR=$( dirname "${MY_REAL_NAME}" )
+BASE_DIR=$( dirname "${BIN_DIR}" )
+LIB_DIR="${BASE_DIR}/lib"
+CONF_DIR="${BASE_DIR}/etc"
+
+NEW_VERSION=""
+OLD_VERSION=""
+BASEDIR=/var/www
+NEXTCLOUD_DIR_LINK="${BASEDIR}/nextcloud"
+
+if [[ -f "${LIB_DIR}/functions.rc" ]] ; then
+    . "${LIB_DIR}/functions.rc"
+else
+    echo "Bash resource file '${LIB_DIR}/functions.rc' not found" >&2
+    exit 5
+fi
+
+detect_color
+
+DESCRIPTION=$( cat <<-EOF
+       Updates the local Nextcloud installation under '${CYAN}${NEXTCLOUD_DIR_LINK}${NORMAL}'.
+
+       You must be root to execute this script.
+
+       EOF
+)
+
+#------------------------------------------------------------------------------
+usage() {
+    cat <<-EOF
+       Usage: ${BASE_NAME} NEXTCLOUD_VERSION [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[@]}" -lt 2 ]] ; then
+        error "No new Nextcloud version given."
+        echo >&2
+        usage >&2
+        exit 2
+    fi
+    unset REMAINING_ARGS[0]
+
+    if [[ "${#REMAINING_ARGS[@]}" -gt 1 ]] ; then
+        error "Invalid arguments: ${REMAINING_ARGS[*]}"
+        echo >&2
+        usage >&2
+        exit 2
+    fi
+
+    NEW_VERSION="${REMAINING_ARGS[1]}"
+
+    check_for_root
+
+}
+
+#------------------------------------------------------------------------------
+get_old_version() {
+
+    local cur_real_nc_dir=$( readlink -f "${NEXTCLOUD_DIR_LINK}" )
+    debug "Current real nextcloud directory: '${CYAN}${cur_real_nc_dir}${NORMAL}'."
+    OLD_VERSION=$( echo "${cur_real_nc_dir}" | xargs basename | sed -e 's/^nextcloud-//' )
+    debug "Current Nextcloud version: '${CYAN}${OLD_VERSION}${NORMAL}'."
+
+    if [[ "${OLD_VERSION}" == "${NEW_VERSION}" ]] ; then
+        warn "The given version '${YELLOW}${NEW_VERSION}${NORMAL}' is the current active Nextcloud version."
+        exit 1
+    fi
+
+    local older_version=$( echo -e "${OLD_VERSION}\n${NEW_VERSION}" | sort --version-sort | head -n 1 )
+    if [[ "${older_version}" == "${NEW_VERSION}" ]] ; then
+        warn "New Nextcloud version '${YELLOW}${NEW_VERSION}${NORMAL}' is older then the current version."
+        if yes_or_no "Continue [y/n]? " ; then
+            info "Downgrading to '${YELLOW}${NEW_VERSION}${NORMAL}'."
+        else
+            info "Give it up."
+            exit 1
+        fi
+    fi
+
+    echo
+    info "Updating Nextcloud from version '${GREEN}${OLD_VERSION}${NORMAL}' to '${GREEN}${NEW_VERSION}${NORMAL}' ..."
+
+}
+
+#------------------------------------------------------------------------------
+main() {
+
+    get_options "$@"
+    umask 0022
+
+    get_old_version
+}
+
+main "$@"
+
+exit 0
+# NEW_NEXTCLOUD_DIR="${BASEDIR}/nextcloud-${VERSION}"
+# 
+# if [[ -d "${NEW_NEXTCLOUD_DIR}" ]] ; then
+#     echo "Nextcloud version '${VERSION}' seems to be already installed."
+#     exit 2
+# fi
+# 
+# ARTIFACT="nextcloud-${VERSION}.tar.bz2"
+# RELEASE_URL="https://download.nextcloud.com/server/releases/${ARTIFACT}"
+# CHECKSUM_URL="https://download.nextcloud.com/server/releases/${ARTIFACT}.md5"
+# DOWNLOAD_DIR="/root/Downloads"
+# 
+# cd "${DOWNLOAD_DIR}"
+# wget -q "${RELEASE_URL}"
+# wget -q "${CHECKSUM_URL}"
+# md5sum -c "${ARTIFACT}.md5"
+# 
+
+
+
+# vim: ts=4 et list
index 6673068257d503a96cbf54ac5c3abb2377111078..566b4bcbd33c57decc396103deeaf2ef0abb5f3c 100644 (file)
@@ -10,7 +10,7 @@ BLUE=""
 CYAN=""
 NORMAL=""
 
-VERSION="0.3.1"
+VERSION="0.3.2"
 
 STD_SHORT_OPTIONS="sdvhV"
 STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"
@@ -314,6 +314,21 @@ CP() {
 
 }
 
+#------------------------------------------------------------------------------
+MV() {
+
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        debug "Simulated moving of: $*"
+        return
+    fi
+    if [[ "${VERBOSE}" != "y" ]] ; then
+        mv "$@"
+    else
+        mv --verbose "$@"
+    fi
+
+}
+
 #------------------------------------------------------------------------------
 set_locale() {
 
@@ -363,4 +378,30 @@ check_for_root() {
     fi
 }
 
+#------------------------------------------------------------------------------
+yes_or_no() {
+
+    local msg="$1"
+    local timeout="10"
+    if [[ "$#" -gt 1 ]] ; then
+        timeout="$2"
+    fi
+
+    local answer=
+    debug "Trying to get an answer with a timeout of ${timeout} seconds."
+    if read -p "${msg}" -t "${timeout}" answer ; then
+        debug "Got an answer: '${answer}'"
+    else
+        exit 1
+    fi
+
+    local first_letter=$( echo "${answer}" | tr '[:upper:]' '[:lower:]' | sed -e 's/^\(.\).*/\1/' )
+    if [[ "${first_letter}" == 'y' || "${first_letter}" == 'j' ]] ; then
+        return 0
+    else
+        return 1
+    fi
+
+}
+
 # vim: filetype=sh ts=4 et list