#!/usr/bin/env bash # Nc-update performs automated NextCloud update # Copyright (C) 2018 Aaron Ball # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . NC_DL_BASE=https://download.nextcloud.com/server/releases cp_custom_apps() { local old=${1} local new=${2} local oldabs # Absolute path to the old instance local newabs # Absolute path to the new instance newabs="$(cd ${new} && pwd)" oldabs="$(cd ${old} && pwd)" for app in $(ls -1 ${old}/apps); do # Sanitize the app path app="$(basename ${app})" if [ ! -e "${new}/apps/${app}" ]; then printf "Copying custom app %s\n" "${app}" cp -r "${old}/apps/${app}" "${new}/apps/" fi done } main() { local path="${1}" local version="${2}" if [ -z "${path:-}" ]; then printf "Path to nextcloud instant to upgrade is required.\n" return 1 fi if [ -z "${version:-}" ]; then printf "Nextcloud version to upgrade to is required.\n" return 1 fi tmp=$(mktemp -d /tmp/nc-update.XXXXXXX) printf "Downloading update package version %s\n" "${version}" curl -L -# \ -o ${tmp}/nc-${version}.tar.bz2 \ ${NC_DL_BASE}/nextcloud-${version}.tar.bz2 printf "Extracting update package for version %s\n" "${version}" tar -x -C "${tmp}" -f "${tmp}/nc-${version}.tar.bz2" local oldinst="$(dirname ${path})/$(basename ${path}).$(date '+%F')" mv "${path}" "${oldinst}" mv "${tmp}/nextcloud" "${path}" printf "Copying configs from the old instance\n" cp ${oldinst}/config/config.php ${path}/config/config.php printf "Copying custom apps from the old instance\n" cp_custom_apps "${oldinst}" "${path}" printf "Upgrading instance\n" php ${path}/occ upgrade printf "Compressing old version for backup purposes\n" cd "$(dirname ${oldinst})" tar -c $(basename ${oldinst}) | xz -cv > $(basename ${oldinst}).tar.xz rm -rf "$(basename ${oldinst})" printf "Cleaning up upgrade resource\n" rm -rf "${tmp}" printf "\nYour owncloud instance at %s is upgraded to %s\n" \ "${path}" "${version}" printf "The old version is archived at %s\n" "${oldinst}.tar.xz" } main ${@}