BASE_DIR=$( dirname "${BIN_DIR}" )
LIB_DIR="${BASE_DIR}/lib"
CONF_DIR="${BASE_DIR}/etc"
+CONF_FILE="${CONF_DIR}/update-nextcloud.rc"
NEW_VERSION=""
OLD_VERSION=""
BASEDIR=/var/www
NEXTCLOUD_DIR_LINK="${BASEDIR}/nextcloud"
+NEW_NEXTCLOUD_DIR="${BASEDIR}/nextcloud-bla"
DOWNLOAD_DIR="/root/Downloads"
ARTIFACT="nextcloud-bla.tar.bz2"
MD5_FILE="${ARTIFACT}.md5"
SHA256_FILE="${ARTIFACT}.sha256"
DOWNLOAD_URL_BASE="https://download.nextcloud.com/server/releases"
+TEMP_DIR_PARENT="/var/tmp"
+TEMP_DIR=
+WWW_USER="www-data"
+WWW_GROUP="www-data"
+FILE_PERMS="0640"
+DIR_PERMS="0750"
+
if [[ -f "${LIB_DIR}/functions.rc" ]] ; then
. "${LIB_DIR}/functions.rc"
detect_color
+if [[ -f "${CONF_FILE}" ]] ; then
+ debug "Sourcing '${CYAN}${CONF_FILE}${NORMAL}' ..."
+ . "${CONF_FILE}"
+fi
+
DESCRIPTION=$( cat <<-EOF
Updates the local Nextcloud installation under '${CYAN}${NEXTCLOUD_DIR_LINK}${NORMAL}'.
ARTIFACT="nextcloud-${NEW_VERSION}.tar.bz2"
MD5_FILE="${ARTIFACT}.md5"
SHA256_FILE="${ARTIFACT}.sha256"
+ NEW_NEXTCLOUD_DIR="${BASEDIR}/nextcloud-${NEW_VERSION}"
check_for_root
fi
fi
+ if [[ -d "${NEW_NEXTCLOUD_DIR}" ]] ; then
+ warn "The directory '${YELLOW}${NEW_NEXTCLOUD_DIR}${NORMAL}' is already existing."
+ if yes_or_no "Continue [y/n]? " ; then
+ info "Removing existing '${YELLOW}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..."
+ RM -r "${NEW_NEXTCLOUD_DIR}"
+ else
+ info "Give it up."
+ exit 1
+ fi
+ fi
+
echo
info "Updating Nextcloud from version '${GREEN}${OLD_VERSION}${NORMAL}' to '${GREEN}${NEW_VERSION}${NORMAL}' ..."
}
+#------------------------------------------------------------------------------
+cleanup_tmp_dir() {
+
+ if [[ -z "${TEMP_DIR}" ]] ; then
+ return 0
+ fi
+
+ if [[ ! -d "${TEMP_DIR}" ]] ; then
+ return 0
+ fi
+
+ cd
+
+ debug "Removing temporary directory '${CYAN}${TEMP_DIR}${NORMAL}' ..."
+ RM -r "${TEMP_DIR}"
+
+}
+
+#------------------------------------------------------------------------------
+unpack_archive() {
+
+ TEMP_DIR=$( mktemp -d "${TEMP_DIR_PARENT}/nextcloud-unpack-XXXXXXXXXX" )
+ local archive="${DOWNLOAD_DIR}/${ARTIFACT}"
+
+ debug "Activating trap ..."
+ trap cleanup_tmp_dir INT TERM EXIT ABRT
+
+ cd "${TEMP_DIR}"
+ info "Unpacking '${GREEN}${archive}${NORMAL}' ..."
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ tar xfvj "${archive}"
+ else
+ tar xfj "${archive}"
+ fi
+
+ info "Moving '${CYAN}${TEMP_DIR}/nextcloud${NORMAL}' to '${CYAN}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..."
+ mv "${TEMP_DIR}/nextcloud" "${NEW_NEXTCLOUD_DIR}"
+ cd
+
+ debug "Deactivating trap ..."
+ trap - INT TERM EXIT ABRT
+ cleanup_tmp_dir
+
+}
+
+#------------------------------------------------------------------------------
+adjust_permissions() {
+
+ cd "${NEW_NEXTCLOUD_DIR}"
+ local verbose_opt=""
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ verbose_opt=" --verbose"
+ fi
+
+ info "Adjusting permissions if '${CYAN}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..."
+ info "Setting ownership to ${WWW_USER}:${WWW_GROUP} ..."
+ CHOWN -R "${WWW_USER}:${WWW_GROUP}" .
+ info "Setting file mode to '${FILE_PERMS}' ..."
+ find ./ -type f -print0 | xargs --null chmod ${verbose_opt} "${FILE_PERMS}"
+ info "Setting dir mode to '${DIR_PERMS}' ..."
+ find ./ -type d -print0 | xargs --null chmod ${verbose_opt} "${DIR_PERMS}"
+
+}
+
#------------------------------------------------------------------------------
main() {
get_old_version
download_release
+ unpack_archive
+ adjust_permissions
+
}
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