--- /dev/null
+#!/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
CYAN=""
NORMAL=""
-VERSION="0.3.1"
+VERSION="0.3.2"
STD_SHORT_OPTIONS="sdvhV"
STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version"
}
+#------------------------------------------------------------------------------
+MV() {
+
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ debug "Simulated moving of: $*"
+ return
+ fi
+ if [[ "${VERBOSE}" != "y" ]] ; then
+ mv "$@"
+ else
+ mv --verbose "$@"
+ fi
+
+}
+
#------------------------------------------------------------------------------
set_locale() {
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