2019-09-30 19:16:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
## author : Dryusdan
|
|
|
|
## date : 30/09/2019
|
|
|
|
## description : A Nextcloud Update
|
2019-09-30 19:16:25 +02:00
|
|
|
## usage : ./nextcloud.sh
|
2019-09-30 19:16:06 +02:00
|
|
|
|
|
|
|
## Bash strict mode ####################################
|
|
|
|
set -o errexit # abort on nonzero exitstatus
|
|
|
|
set -o nounset # abort on unbound variable
|
|
|
|
set -o pipefail # don't hide errors within pipes
|
|
|
|
|
|
|
|
## Bash color ##########################################
|
|
|
|
# Set colors
|
|
|
|
RED='\033[0;31m'
|
|
|
|
GREEN='\033[00;32m'
|
|
|
|
YELLOW='\033[00;33m'
|
|
|
|
BLUE='\033[00;34m'
|
|
|
|
PURPLE='\033[00;35m'
|
|
|
|
CYAN='\033[00;36m'
|
|
|
|
LIGHTGRAY='\033[00;37m'
|
|
|
|
LRED='\033[01;31m'
|
|
|
|
LGREEN='\033[01;32m'
|
|
|
|
LYELLOW='\033[01;33m'
|
|
|
|
LBLUE='\033[01;34m'
|
|
|
|
LPURPLE='\033[01;35m'
|
|
|
|
LCYAN='\033[01;36m'
|
|
|
|
WHITE='\033[01;37m'
|
|
|
|
NC='\033[0m' # No Color
|
|
|
|
|
|
|
|
## Logs ################################################
|
|
|
|
readonly SCRIPTNAME="$(basename "$0")"
|
|
|
|
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
|
|
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
|
|
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
|
|
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
|
|
|
########################################################
|
|
|
|
|
|
|
|
## Define nextcloud's folder ##########################
|
|
|
|
FOLDER="/var/www/cloud_drycat_fr"
|
|
|
|
|
|
|
|
## Ask nextcloud ######################################
|
|
|
|
read -p "Nextcloud version ? " VERSION
|
|
|
|
|
|
|
|
info "Check if require folders exist"
|
|
|
|
|
2019-10-25 00:27:17 +02:00
|
|
|
if [ -d "${FOLDER}/nextcloud" ]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
warning "Aborded installation exist. Remove nextcloud/ folder"
|
2019-10-25 00:27:17 +02:00
|
|
|
rm -rf ${FOLDER}/nextcloud || fatal "Error when removing folder. Exiting"
|
2019-09-30 19:16:06 +02:00
|
|
|
rm nextcloud-* || fatal "Error when removing nextcloud-* .zip, .zip.sha256, .zip.asc. Please remove $FOLDER/nextcloud and $FOLDER/nextcloud-* and retry"
|
|
|
|
fi
|
2019-10-25 00:27:17 +02:00
|
|
|
if [ -d "${FOLDER}/www" ]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
info "www/ directory exist, continue"
|
|
|
|
NEW_INSTALLATION=false
|
|
|
|
else
|
|
|
|
warning "www/ directory don't exist, creating"
|
2019-10-25 00:27:17 +02:00
|
|
|
mkdir ${FOLDER}/www || fatal "Error when creating folder. Exiting"
|
2019-09-30 19:16:06 +02:00
|
|
|
NEW_INSTALLATION=true
|
|
|
|
fi
|
2019-10-25 00:27:17 +02:00
|
|
|
if [ -d "${FOLDER}/data" ]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
info "data/ directory exist, continue"
|
|
|
|
else
|
|
|
|
warning "data/ directory don't exist, creating"
|
2019-10-25 00:27:17 +02:00
|
|
|
mkdir ${FOLDER}/data || fatal "Error when creating folder. Exiting"
|
2019-09-30 19:16:06 +02:00
|
|
|
NEW_INSTALLATION=true
|
|
|
|
fi
|
2019-10-25 00:27:17 +02:00
|
|
|
if [ -d "${FOLDER}/config" ]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
info "config/ directory exist, continue"
|
|
|
|
else
|
|
|
|
warning "config/ directory don't exist, creating"
|
2019-10-25 00:27:17 +02:00
|
|
|
mkdir ${FOLDER}/config || fatal "Error when creating folder. Exiting"
|
2019-09-30 19:16:06 +02:00
|
|
|
NEW_INSTALLATION=true
|
|
|
|
fi
|
2019-10-25 00:27:17 +02:00
|
|
|
if [ -d "${FOLDER}/apps" ]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
info "apps/ directory exist, continue"
|
|
|
|
else
|
|
|
|
warning "apps/ directory don't exist, creating"
|
2019-10-25 00:27:17 +02:00
|
|
|
mkdir ${FOLDER}/apps || fatal "Error when creating folder. Exiting"
|
2019-09-30 19:16:06 +02:00
|
|
|
NEW_INSTALLATION=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Download nextcloud
|
2019-10-25 00:27:17 +02:00
|
|
|
info "Download Nextcloud ${VERSION}"
|
|
|
|
wget -q https://download.nextcloud.com/server/releases/nextcloud-${VERSION}.zip || fatal "Download failed. Please retry"
|
|
|
|
if [ ! -f "${FOLDER}/nextcloud-${VERSION}.zip" ]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
fatal "Download of Nextcloud archive failed. Please retry"
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Download sha256 of Nextcloud"
|
|
|
|
wget -q https://download.nextcloud.com/server/releases/nextcloud-$VERSION.zip.sha256 || fatal "Download of Nextcloud checksum failed. Please retry"
|
|
|
|
if [ ! -f "$FOLDER/nextcloud-$VERSION.zip.sha256" ]; then
|
|
|
|
fatal "Download of Nextcloud checksum failed. Please retry"
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Download asc of Nextcloud"
|
2019-10-25 00:27:17 +02:00
|
|
|
wget -q https://download.nextcloud.com/server/releases/nextcloud-${VERSION}.zip.asc || fatal "Download of Nextcloud signature failed. Please retry"
|
|
|
|
if [ ! -f "${FOLDER}/nextcloud-${VERSION}.zip.asc" ]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
fatal "Download of Nextcloud signature failed. Please retry"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check integrity nextcloud
|
|
|
|
info "Check nextcloud integrity"
|
2019-10-25 00:27:17 +02:00
|
|
|
sha256sum -c nextcloud-${VERSION}.zip.sha256 >/dev/null || fatal "Checksum did not match"
|
|
|
|
gpg -q --verify nextcloud-${VERSION}.zip.asc 2>/dev/null|| fatal "Signature is not good"
|
2019-09-30 19:16:06 +02:00
|
|
|
|
|
|
|
info "Start update"
|
|
|
|
|
2019-10-25 00:27:17 +02:00
|
|
|
info "Unzip Nextcloud ${VERSION}"
|
|
|
|
unzip -q nextcloud-${VERSION}.zip
|
2019-09-30 19:16:06 +02:00
|
|
|
|
2019-10-25 00:27:17 +02:00
|
|
|
if [[ ${NEW_INSTALLATION} == "false" ]]; then
|
2019-09-30 19:16:06 +02:00
|
|
|
info "Unlink folders that contain the data"
|
2020-02-24 10:35:24 +01:00
|
|
|
cp ${FOLDER}/config/config.php ${FOLDER}/config.php
|
2019-09-30 19:16:06 +02:00
|
|
|
unlink www/data
|
|
|
|
unlink www/config
|
|
|
|
unlink www/apps
|
2020-02-24 11:03:54 +01:00
|
|
|
rm -f ${FOLDER}/apps/workflowengine/appinfo/database.xml
|
2019-09-30 19:16:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
info "Backuping old installation"
|
|
|
|
tar -zcf "www.$(date '+%Y-%m-%d').tar.gz" www
|
2019-10-25 00:27:17 +02:00
|
|
|
tar -zcf "apps.$(date '+%Y-%m-%d').tar.gz" apps
|
2019-09-30 19:16:06 +02:00
|
|
|
|
|
|
|
info "Removing old installation"
|
|
|
|
rm -rf www/*
|
2019-10-25 00:27:17 +02:00
|
|
|
|
|
|
|
info "Copying news apps files"
|
2019-09-30 19:16:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info "Copying new Nextcloud"
|
2019-10-25 00:27:17 +02:00
|
|
|
cp -rf nextcloud/apps/* apps/
|
|
|
|
rm -rf nextcloud/{config,data,apps}
|
2019-09-30 19:16:06 +02:00
|
|
|
cp -rf nextcloud/* www/
|
2020-02-24 10:35:24 +01:00
|
|
|
cp -rf ${FOLDER}/config.php ${FOLDER}/config/config.php
|
2019-09-30 19:16:06 +02:00
|
|
|
|
|
|
|
info "Link folders that contain the data into new installation"
|
2019-10-25 00:27:17 +02:00
|
|
|
ln -s ${FOLDER}/data ${FOLDER}/www/
|
|
|
|
ln -s ${FOLDER}/config ${FOLDER}/www/
|
|
|
|
ln -s ${FOLDER}/apps ${FOLDER}/www/
|
2019-09-30 19:16:06 +02:00
|
|
|
|
|
|
|
info "Removing archive and temp folder"
|
2019-10-25 00:27:17 +02:00
|
|
|
rm -rf nextcloud-${VERSION}.zip* ../nextcloud/
|
2019-09-30 19:16:06 +02:00
|
|
|
|
|
|
|
info "Setting good permission"
|
|
|
|
cd www/
|
|
|
|
find -type f -exec chmod 644 {} \; 2> /dev/null;
|
|
|
|
find -type d -exec chmod 755 {} \; 2> /dev/null;
|
|
|
|
|
|
|
|
info "Launch upgrade with occ"
|
|
|
|
php occ upgrade
|
|
|
|
|
|
|
|
info "Launch integrity check"
|
|
|
|
php occ check
|
|
|
|
|
|
|
|
read -n1 -p "Would you like scann all file (recommanded) [y,n]" SCAN
|
2019-10-25 00:27:17 +02:00
|
|
|
case ${SCAN} in
|
2019-09-30 19:16:06 +02:00
|
|
|
y|Y) info "Launch files scan" && php console.php files:scan --all ;;
|
|
|
|
n|N) info "Don't launch files scan" ;;
|
|
|
|
*) echo Please use y or n ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
###########################################################
|
|
|
|
info "exiting ${SCRIPTNAME}"
|
|
|
|
exit 0
|