summaryrefslogtreecommitdiff
path: root/nc-update.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nc-update.sh')
-rwxr-xr-xnc-update.sh91
1 files changed, 91 insertions, 0 deletions
diff --git a/nc-update.sh b/nc-update.sh
new file mode 100755
index 0000000..820bfa0
--- /dev/null
+++ b/nc-update.sh
@@ -0,0 +1,91 @@
+#!/usr/bin/env bash
+# Nc-update performs automated NextCloud update
+# Copyright (C) 2018 Aaron Ball <nullspoon@oper.io>
+#
+# 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 <https://www.gnu.org/licenses/>.
+
+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 ${@}

Generated by cgit