From 8d407905f30dcd4b4af4e8f56edecba149640aee Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 27 Apr 2020 16:17:23 +0200 Subject: [PATCH] Nearly completed bin/update-nextcloud --- bin/update-nextcloud | 83 ++++++++++++++++++++++++++++++++++++++++++-- lib/functions.rc | 28 ++++++++++++++- 2 files changed, 108 insertions(+), 3 deletions(-) diff --git a/bin/update-nextcloud b/bin/update-nextcloud index bb0aa1d..034e373 100755 --- a/bin/update-nextcloud +++ b/bin/update-nextcloud @@ -27,7 +27,7 @@ WWW_USER="www-data" WWW_GROUP="www-data" FILE_PERMS="0640" DIR_PERMS="0750" - +SERVICE_NAME="apache2.service" if [[ -f "${LIB_DIR}/functions.rc" ]] ; then . "${LIB_DIR}/functions.rc" @@ -217,7 +217,7 @@ cleanup_tmp_dir() { cd debug "Removing temporary directory '${CYAN}${TEMP_DIR}${NORMAL}' ..." - RM -r "${TEMP_DIR}" + purge -r "${TEMP_DIR}" } @@ -296,6 +296,78 @@ sync_apps() { cleanup_tmp_dir } +#------------------------------------------------------------------------------ +set_maintenance() { + + info "Setting maintenance mode ..." + cd "${NEXTCLOUD_DIR_LINK}" + sudo -u "${WWW_USER}" php occ maintenance:mode --on + +} + +#------------------------------------------------------------------------------ +copy_config() { + + local cur_nc_dir="${WWW_BASE}/nextcloud-${OLD_VERSION}" + local cur_cfg_file="${cur_nc_dir}/config/config.php" + local new_cfg_file="${NEW_NEXTCLOUD_DIR}/config/config.php" + + info "Copying configuration ..." + CP "${cur_cfg_file}" "${new_cfg_file}" + +} + +#------------------------------------------------------------------------------ +stop_service() { + + info "Stopping '${CYAN}${SERVICE_NAME}${NORMAL}' ..." + systemctl stop "${SERVICE_NAME}" + if [[ "${VERBOSE}" == 'y' ]] ; then + systemctl status "${SERVICE_NAME}" || true + fi + +} + +#------------------------------------------------------------------------------ +change_symlinks() { + + info "Setting symlink '${CYAN}${NEXTCLOUD_DIR_LINK}${NORMAL}' -> '${CYAN}nextcloud-${NEW_VERSION}${NORMAL}' ..." + cd + RM "${NEXTCLOUD_DIR_LINK}" + LN "nextcloud-${NEW_VERSION}" "${NEXTCLOUD_DIR_LINK}" + +} + +#------------------------------------------------------------------------------ +upgrade_nc() { + + echo + info "Upgrading Nextcloud ..." + cd "${NEXTCLOUD_DIR_LINK}" + sudo -u "${WWW_USER}" php occ upgrade + +} + +#------------------------------------------------------------------------------ +start_service() { + + info "Starting '${CYAN}${SERVICE_NAME}${NORMAL}' ..." + systemctl start "${SERVICE_NAME}" + if [[ "${VERBOSE}" == 'y' ]] ; then + systemctl status "${SERVICE_NAME}" || true + fi + +} + +#------------------------------------------------------------------------------ +release_maintenance() { + + info "Releasing maintenance mode ..." + cd "${NEXTCLOUD_DIR_LINK}" + sudo -u "${WWW_USER}" php occ maintenance:mode --off + +} + #------------------------------------------------------------------------------ main() { @@ -307,6 +379,13 @@ main() { unpack_archive adjust_permissions sync_apps + set_maintenance + copy_config + stop_service + change_symlinks + upgrade_nc + start_service + release_maintenance } diff --git a/lib/functions.rc b/lib/functions.rc index ad6af55..077e9bb 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -10,7 +10,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.3.4" +VERSION="0.3.5" STD_SHORT_OPTIONS="sdvhV" STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version" @@ -299,6 +299,17 @@ RM() { } +#------------------------------------------------------------------------------ +purge() { + + if [[ "${VERBOSE}" != "y" ]] ; then + rm "$@" + else + rm --verbose "$@" + fi + +} + #------------------------------------------------------------------------------ CP() { @@ -344,6 +355,21 @@ CHOWN() { } +#------------------------------------------------------------------------------ +LN() { + + if [[ "${SIMULATE}" == "y" ]] ; then + debug "Simulating: ln $*" + return + fi + if [[ "${VERBOSE}" != "y" ]] ; then + ln "$@" + else + ln --verbose "$@" + fi + +} + #------------------------------------------------------------------------------ set_locale() { -- 2.39.5