NEW_VERSION=""
OLD_VERSION=""
WWW_BASE=/var/www
-NEXTCLOUD_DIR_LINK="${WWW_BASE}/nextcloud"
-NEW_NEXTCLOUD_DIR="${WWW_BASE}/nextcloud-bla"
+NEXTCLOUD_DIR="${WWW_BASE}/nextcloud"
+NEXTCLOUD_DIR_NEW="${NEXTCLOUD_DIR}.new"
+NEXTCLOUD_DIR_OLD="${NEXTCLOUD_DIR}.old"
DOWNLOAD_DIR="/root/Downloads"
ARTIFACT="nextcloud-bla.tar.bz2"
MD5_FILE="${ARTIFACT}.md5"
SHA256_FILE="${ARTIFACT}.sha256"
+SHA512_FILE="${ARTIFACT}.sha512"
DOWNLOAD_URL_BASE="https://download.nextcloud.com/server/releases"
TEMP_DIR_PARENT="/var/tmp"
TEMP_DIR=
FILE_PERMS="0640"
DIR_PERMS="0750"
SERVICE_NAME="apache2.service"
+MY_HOSTNAME=$( hostname )
+BACKUP_DIR_ROOT="/var/backup"
+MY_BACKUP_DIR="${BACKUP_DIR_ROOT}/${MY_HOSTNAME}"
+BACKUP_DIR="${MY_BACKUP_DIR}/nextcloud-update"
if [[ -f "${LIB_DIR}/functions.rc" ]] ; then
. "${LIB_DIR}/functions.rc"
fi
DESCRIPTION=$( cat <<-EOF
- Updates the local Nextcloud installation under '${CYAN}${NEXTCLOUD_DIR_LINK}${NORMAL}'.
+ Updates the local Nextcloud installation under '${CYAN}${NEXTCLOUD_DIR}${NORMAL}'.
You must be root to execute this script.
ARTIFACT="nextcloud-${NEW_VERSION}.tar.bz2"
MD5_FILE="${ARTIFACT}.md5"
SHA256_FILE="${ARTIFACT}.sha256"
- NEW_NEXTCLOUD_DIR="${WWW_BASE}/nextcloud-${NEW_VERSION}"
+ SHA512_FILE="${ARTIFACT}.sha512"
check_for_root
}
+#------------------------------------------------------------------------------
+WGET() {
+
+ url="$1"
+
+ info "Downloading '${CYAN}${url}${NORMAL}' ..."
+
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ wget "${url}"
+ else
+ wget -q "${url}"
+ fi
+
+}
+
#------------------------------------------------------------------------------
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-//' )
+ local version_file="${NEXTCLOUD_DIR}/version.php"
+ debug "Get current Nextcloud version from '${CYAN}${version_file}${NORMAL}' ..."
+
+ if [[ ! -f "${version_file}" ]] ; then
+ error "Did not found version file '${RED}${version_file}${NORMAL}'."
+ exit 6
+ fi
+
+ OLD_VERSION=$( cat "${version_file}" | grep -i '^\$OC_VersionString' | sed -e "s/.*= *'//" -e "s/'.*//" )
debug "Current Nextcloud version: '${CYAN}${OLD_VERSION}${NORMAL}'."
if [[ "${OLD_VERSION}" == "${NEW_VERSION}" ]] ; then
fi
fi
- if [[ -d "${NEW_NEXTCLOUD_DIR}" ]] ; then
- warn "The directory '${YELLOW}${NEW_NEXTCLOUD_DIR}${NORMAL}' is already existing."
+ if [[ -d "${NEXTCLOUD_DIR_NEW}" ]] ; then
+ warn "The directory '${YELLOW}${NEXTCLOUD_DIR_NEW}${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}"
+ info "Removing existing '${YELLOW}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
+ RM -r "${NEXTCLOUD_DIR_NEW}"
else
info "Give it up."
exit 1
}
+#------------------------------------------------------------------------------
+do_backup() {
+
+ local backup_file="${BACKUP_DIR}/backup-${OLD_VERSION}.tar.bz2"
+
+ info "Backing up current Nextcloud directory to '${GREEN}${backup_file}${NORMAL}' ..."
+
+ if [[ ! -d "${BACKUP_DIR}" ]] ; then
+ info "Creating '${CYAN}${BACKUP_DIR}${NORMAL}' ..."
+ MKDIR -p "${BACKUP_DIR}"
+ fi
+
+ cd "${WWW_BASE}"
+
+ local cmd="tar -c"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
+ fi
+ cmd+=" --file \"${backup_file}\" --bzip2 nextcloud"
+ info "Executing: ${cmd}"
+ eval ${cmd}
+
+ cd
+
+ empty_line
+ info "Backup directory '${CYAN}${BACKUP_DIR}${NORMAL}':"
+ ls -l "${BACKUP_DIR}"
+
+}
+
#------------------------------------------------------------------------------
download_release() {
local release_url="${DOWNLOAD_URL_BASE}/${ARTIFACT}"
local md5_url="${DOWNLOAD_URL_BASE}/${MD5_FILE}"
local sha256_url="${DOWNLOAD_URL_BASE}/${SHA256_FILE}"
+ local sha512_url="${DOWNLOAD_URL_BASE}/${SHA512_FILE}"
if [[ ! -f "${ARTIFACT}" ]] ; then
- info "Downloading '${CYAN}${release_url}${NORMAL}' ..."
- if [[ "${VERBOSE}" == "y" ]] ; then
- wget "${release_url}"
- else
- wget -q "${release_url}"
- fi
+ WGET "${release_url}"
fi
if [[ ! -f "${MD5_FILE}" ]] ; then
- info "Downloading '${CYAN}${md5_url}${NORMAL}' ..."
- if [[ "${VERBOSE}" == "y" ]] ; then
- wget "${md5_url}"
- else
- wget -q "${md5_url}"
- fi
+ WGET "${md5_url}"
fi
if [[ ! -f "${SHA256_FILE}" ]] ; then
- info "Downloading '${CYAN}${sha256_url}${NORMAL}' ..."
- if [[ "${VERBOSE}" == "y" ]] ; then
- wget "${sha256_url}"
- else
- wget -q "${sha256_url}"
- fi
+ WGET "${sha256_url}"
+ fi
+
+ if [[ ! -f "${SHA512_FILE}" ]] ; then
+ WGET "${sha512_url}"
fi
info "Checking MD5 consistence of ${ARTIFACT} ..."
info "Checking SHA256 consistence of ${ARTIFACT} ..."
sha256sum -c "${SHA256_FILE}"
+ info "Checking SHA512 consistence of ${ARTIFACT} ..."
+ sha512sum -c "${SHA512_FILE}"
+
}
#------------------------------------------------------------------------------
tar xfj "${archive}"
fi
- info "Moving '${CYAN}${TEMP_DIR}/nextcloud${NORMAL}' to '${CYAN}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..."
- mv "${TEMP_DIR}/nextcloud" "${NEW_NEXTCLOUD_DIR}"
+ info "Moving '${CYAN}${TEMP_DIR}/nextcloud${NORMAL}' to '${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
+ mv "${TEMP_DIR}/nextcloud" "${NEXTCLOUD_DIR_NEW}"
cd
debug "Deactivating trap ..."
#------------------------------------------------------------------------------
adjust_permissions() {
- cd "${NEW_NEXTCLOUD_DIR}"
+ cd "${NEXTCLOUD_DIR_NEW}"
- info "Adjusting permissions if '${CYAN}${NEW_NEXTCLOUD_DIR}${NORMAL}' ..."
+ info "Adjusting permissions if '${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' ..."
info "Setting ownership to ${WWW_USER}:${WWW_GROUP} ..."
chown -R "${WWW_USER}:${WWW_GROUP}" .
info "Setting file mode to '${FILE_PERMS}' ..."
#------------------------------------------------------------------------------
sync_apps() {
- local cur_nc_dir="${WWW_BASE}/nextcloud-${OLD_VERSION}"
- local cur_apps_dir="${cur_nc_dir}/apps"
- local new_apps_dir="${NEW_NEXTCLOUD_DIR}/apps"
+ local cur_apps_dir="${NEXTCLOUD_DIR}/apps"
+ local new_apps_dir="${NEXTCLOUD_DIR_NEW}/apps"
local app=
TEMP_DIR=$( mktemp -d "${TEMP_DIR_PARENT}/nextcloud-apps-XXXXXXXXXX" )
cleanup_tmp_dir
}
+#------------------------------------------------------------------------------
+occ() {
+
+ debug "Executing '${CYAN}php occ $*${NORMAL}' ..."
+ (
+ cd "${NEXTCLOUD_DIR}"
+ sudo -u "${WWW_USER}" php occ "$@"
+ )
+
+}
+
#------------------------------------------------------------------------------
set_maintenance() {
info "Setting maintenance mode ..."
- cd "${NEXTCLOUD_DIR_LINK}"
- sudo -u "${WWW_USER}" php occ maintenance:mode --on
+ cd "${NEXTCLOUD_DIR}"
+ 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"
+ local cur_cfg_file="${NEXTCLOUD_DIR}/config/config.php"
+ local new_cfg_file="${NEXTCLOUD_DIR_NEW}/config/config.php"
info "Copying configuration ..."
CP "${cur_cfg_file}" "${new_cfg_file}"
}
#------------------------------------------------------------------------------
-change_symlinks() {
+switch_nc_dirs() {
- info "Setting symlink '${CYAN}${NEXTCLOUD_DIR_LINK}${NORMAL}' -> '${CYAN}nextcloud-${NEW_VERSION}${NORMAL}' ..."
- cd "${WWW_BASE}"
- RM "${NEXTCLOUD_DIR_LINK}"
- LN -s "nextcloud-${NEW_VERSION}" "${NEXTCLOUD_DIR_LINK}"
+ empty_line
+ info "Switching Nextcloud directories to new version ..."
+
+ debug "Moving '${CYAN}${NEXTCLOUD_DIR}${NORMAL}' -> '${CYAN}${NEXTCLOUD_DIR_OLD}${NORMAL}' ..."
+ MV "${NEXTCLOUD_DIR}" "${NEXTCLOUD_DIR_OLD}"
+
+ debug "Moving '${CYAN}${NEXTCLOUD_DIR_NEW}${NORMAL}' -> '${CYAN}${NEXTCLOUD_DIR}${NORMAL}' ..."
+ MV "${NEXTCLOUD_DIR_NEW}" "${NEXTCLOUD_DIR}"
}
#------------------------------------------------------------------------------
upgrade_nc() {
- echo
+ empty_line
info "Upgrading Nextcloud ..."
- cd "${NEXTCLOUD_DIR_LINK}"
- sudo -u "${WWW_USER}" php occ upgrade
+ occ upgrade
}
release_maintenance() {
info "Releasing maintenance mode ..."
- cd "${NEXTCLOUD_DIR_LINK}"
- sudo -u "${WWW_USER}" php occ maintenance:mode --off
+ occ maintenance:mode --off
}
umask 0022
get_old_version
+ do_backup
download_release
unpack_archive
adjust_permissions
set_maintenance
copy_config
stop_service
- change_symlinks
+ switch_nc_dirs
upgrade_nc
start_service
release_maintenance