summaryrefslogtreecommitdiff
path: root/nc-update.sh
blob: 820bfa011d419b5e512be968bb32e0c7001cec99 (plain)
    1 #!/usr/bin/env bash
    2 # Nc-update performs automated NextCloud update
    3 # Copyright (C) 2018  Aaron Ball <nullspoon@oper.io>
    4 # 
    5 # This program is free software: you can redistribute it and/or modify
    6 # it under the terms of the GNU General Public License as published by
    7 # the Free Software Foundation, either version 3 of the License, or
    8 # (at your option) any later version.
    9 # 
   10 # This program is distributed in the hope that it will be useful,
   11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 # GNU General Public License for more details.
   14 # 
   15 # You should have received a copy of the GNU General Public License
   16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
   17 
   18 NC_DL_BASE=https://download.nextcloud.com/server/releases
   19 
   20 cp_custom_apps() {
   21   local old=${1}
   22   local new=${2}
   23 
   24   local oldabs # Absolute path to the old instance
   25   local newabs # Absolute path to the new instance
   26 
   27   newabs="$(cd ${new} && pwd)"
   28   oldabs="$(cd ${old} && pwd)"
   29 
   30   for app in $(ls -1 ${old}/apps); do
   31     # Sanitize the app path
   32     app="$(basename ${app})"
   33 
   34     if [ ! -e "${new}/apps/${app}" ]; then
   35       printf "Copying custom app %s\n" "${app}"
   36       cp -r "${old}/apps/${app}" "${new}/apps/"
   37     fi
   38   done
   39 }
   40 
   41 main() {
   42   local path="${1}"
   43   local version="${2}"
   44 
   45   if [ -z "${path:-}" ]; then
   46     printf "Path to nextcloud instant to upgrade is required.\n"
   47     return 1
   48   fi
   49   if [ -z "${version:-}" ]; then
   50     printf "Nextcloud version to upgrade to is required.\n"
   51     return 1
   52   fi
   53 
   54   tmp=$(mktemp -d /tmp/nc-update.XXXXXXX)
   55 
   56   printf "Downloading update package version %s\n" "${version}"
   57   curl -L -# \
   58     -o ${tmp}/nc-${version}.tar.bz2 \
   59     ${NC_DL_BASE}/nextcloud-${version}.tar.bz2
   60 
   61   printf "Extracting update package for version %s\n" "${version}"
   62   tar -x -C "${tmp}" -f "${tmp}/nc-${version}.tar.bz2"
   63 
   64   local oldinst="$(dirname ${path})/$(basename ${path}).$(date '+%F')"
   65   mv "${path}" "${oldinst}"
   66 
   67   mv "${tmp}/nextcloud" "${path}"
   68 
   69   printf "Copying configs from the old instance\n"
   70   cp ${oldinst}/config/config.php ${path}/config/config.php
   71 
   72   printf "Copying custom apps from the old instance\n"
   73   cp_custom_apps "${oldinst}" "${path}"
   74 
   75   printf "Upgrading instance\n"
   76   php ${path}/occ upgrade
   77 
   78   printf "Compressing old version for backup purposes\n"
   79   cd "$(dirname ${oldinst})"
   80   tar -c $(basename ${oldinst}) | xz -cv > $(basename ${oldinst}).tar.xz
   81   rm -rf "$(basename ${oldinst})"
   82 
   83   printf "Cleaning up upgrade resource\n"
   84   rm -rf "${tmp}"
   85 
   86   printf "\nYour owncloud instance at %s is upgraded to %s\n" \
   87     "${path}" "${version}"
   88   printf "The old version is archived at %s\n" "${oldinst}.tar.xz"
   89 }
   90 
   91 main ${@}

Generated by cgit