#!/usr/bin/env bash script_name="$(basename $(realpath $0))" script_dir="$(dirname $(realpath $0))" conf_dir="${script_dir}/conf" declare -a unsorted_website_arr declare -a website_arr log_file="$(mktemp)" backup_date=$(date +%Y-%m-%d-%H%M) # ============= # --- Some functions # ============= clean_up() { if [[ -f "$_backup_crontab_file" ]]; then echononl "(Re)Install previously saved crontab from '$_backup_crontab_file'.." crontab $_backup_crontab_file >> $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi fi # Perform program exit housekeeping rm -f $log_file blank_line exit $1 } is_number() { return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1); # - also possible # - #[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1 #return $([[ ! -z "${1##*[!0-9]*}" ]]) } echononl(){ echo X\\c > /tmp/shprompt$$ if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then echo -e -n "$*\\c" 1>&2 else echo -e -n "$*" 1>&2 fi rm /tmp/shprompt$$ } echo_done() { if $terminal ; then echo -e "\033[75G[ \033[32mdone\033[m ]" else echo " [ done ]" fi } echo_ok() { if $terminal ; then echo -e "\033[75G[ \033[32mok\033[m ]" else echo " [ ok ]" fi } echo_warning() { if $terminal ; then echo -e "\033[75G[ \033[33m\033[1mwarn\033[m ]" else echo " [ warning ]" fi } echo_failed(){ if $terminal ; then echo -e "\033[75G[ \033[1;31mfailed\033[m ]" else echo ' [ failed! ]' fi } echo_skipped() { if $terminal ; then echo -e "\033[75G[ \033[37mskipped\033[m ]" else echo " [ skipped ]" fi } fatal (){ echo "" echo "" if $terminal ; then echo -e "\t[ \033[31m\033[1mFatal\033[m ]: \033[37m\033[1m$*\033[m" echo "" echo -e "\t\033[31m\033[1m Script will be interrupted..\033[m\033[m" else echo "fatal: $*" echo "Script will be interrupted.." fi clean_up 1 } error(){ echo "" if $terminal ; then echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" else echo "Error: $*" fi echo "" } warn (){ echo "" if $terminal ; then echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" else echo "Warning: $*" fi echo "" } info (){ echo "" if $terminal ; then echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" else echo "Info: $*" fi echo "" } detect_os_1 () { if $(which lsb_release > /dev/null 2>&1) ; then os_dist="$(lsb_release -i | awk '{print tolower($3)}')" os_version="$(lsb_release -r | awk '{print tolower($2)}')" os_codename="$(lsb_release -c | awk '{print tolower($2)}')" if [[ "$os_dist" = "debian" ]]; then if $(echo "$os_version" | grep -q '\.') ; then os_version=$(echo "$os_version" | cut --delimiter='.' -f1) fi fi elif [[ -e "/etc/os-release" ]]; then . /etc/os-release os_dist=$ID os_version=${VERSION_ID} fi # remove whitespace from os_dist and os_version os_dist="${os_dist// /}" os_version="${os_version// /}" } ## - Check if a given array (parameter 2) contains a given string (parameter 1) ## - containsElement () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done return 1 } blank_line() { if $terminal ; then echo "" fi } # ---------- # - Jobhandling # ---------- # - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM # - trap clean_up SIGHUP SIGINT SIGTERM ## - while IFS='' read -r -d '' _conf_file ; do source $_conf_file if [[ -n "$WEBSITE" ]] ; then unsorted_website_arr+=("${WEBSITE}:$_conf_file") fi WEBSITE="" done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0) if [[ ${#unsorted_website_arr} -eq 0 ]]; then fatal "No configuration files found in '${script_dir}/conf' or no website configured!" fi # - Sort array # - IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}")) # ============= # --- Some # ============= # - Support systemd ? # - if [[ "X$(which systemd)" = "X" ]]; then SYSTEMD_EXISTS=false else SYSTEMD_EXISTS=true fi # - Running in a terminal? # - if [[ -t 1 ]] ; then terminal=true else terminal=false fi clear echo "" echo -e "\033[32m-----\033[m" echo "Update Nextcloud" echo -e "\033[32m-----\033[m" WEBSITE= _OK=false echo "" echo "Which site would you like to update?" echo "" declare -i i=0 for _site in ${website_arr[@]} ; do IFS=':' read -a _arr <<< ${_site} echo " [$i] ${_arr[0]}" ((i++)) done echo echononl " Eingabe: " while ! $_OK ; do read _IN if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then IFS=':' read -a _arr <<< ${website_arr[$_IN]} conf_file=${_arr[1]} _OK=true else echo "" echo -e "\tFalsche Eingabe !" echo "" echononl " Eingabe: " fi done echo "" echo -e "\033[32m--\033[m" echo "" echo "Insert (new) Nextcloud version number." echo "" echo "" VERSION= while [ "X$VERSION" = "X" ] do echononl " Nextcloud version number: " read VERSION if [ "X$VERSION" = "X" ]; then echo "" echo -e "Eingabe erforderlich" fi done # - Detect Detect OS distribution and Version # - echo "" echo -e " \033[32m--\033[m" echo "" echononl "Detect OS distribution and Version" detect_os_1 > /dev/null 2>&1 if [[ $? -gt 0 ]] ; then echo_failed else echo_ok fi #if [[ "${os_dist,,}" = "debian" ]] ; then # # declare -a dpkg_pkg_colabora_online=() # check_package="loolwsd" # if ! $(dpkg -l "$check_package" 2> /devnull | grep -q -E "^ii\s+${check_package}\s+" 2>/dev/null) ; then # # echononl "Install ColaboraOnline App (yes/no) [yes]: " # read OK # while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do # echononl "Wrong entry! - repeat (yes/no) [yes]: " # read OK # [[ -z "${OK,,}" ]] && OK="yes" # done # # if [[ ${OK,,} = "yes" ]] ; then # INSTALL_COLABORA_ONLINE_APP=true # else # INSTALL_COLABORA_ONLINE_APP=false # fi # else # INSTALL_COLABORA_ONLINE_APP=true # fi #fi echo "" echononl " Include Configuration file.." if [[ ! -f $conf_file ]]; then echo_failed fatal "Missing configuration file '$conf_file'" else source $conf_file echo_ok fi echo "" # ============= # --- Some checks # ============= DEFAULT_SRC_BASE_DIR="/usr/local/src/nextcloud" DEFAULT_HTTP_USER="www-data" DEFAULT_HTTP_GROUP="www-data" if [[ -z ${WEBSITE} ]] ; then fatal "No website given (parameter 'WEBSITE')" fi DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE" DEFAULT_PHP_ENGINE="FPM" [[ -n "$SRC_BASE_DIR" ]] || SRC_BASE_DIR=$DEFAULT_SRC_BASE_DIR #[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER #[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP [[ -n "$WEB_BASE_DIR" ]] || WEB_BASE_DIR=$DEFAULT_WEB_BASE_DIR if [[ ! -d ${WEB_BASE_DIR} ]] ; then fatal "Web base directory not found (parameter 'WEB_BASE_DIR')" fi [[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE if [[ "$DATABASE_TYPE" != "postgres" ]] && [[ "$DATABASE_TYPE" != "mysql" ]]; then fatal "Wrong or missing database type (parameter 'DATABASE_TYPE')" fi if [[ -z "$DATABASE_NAME" ]]; then fatal "Missing database name (parameter 'DATABASE_NAME')" fi if [[ "$DATABASE_TYPE" = "mysql" ]] && [[ -z "$MYSQL_CREDENTIALS" ]]; then fatal "No Database Credentials for MySQL given (parameter 'MYSQL_CREDENTIALS')" fi if [[ "$DATABASE_TYPE" = "postgres" ]]; then if [[ -z "$PSQL_USER" ]] || [[ -z "$PSQL_PASS" ]]; then fatal "No Database Credentials for PostgreSQL given (parameters: 'PSQL_USER' 'PSQL_PASS'" fi fi # Check if NGINX webserver is ctive # if $(systemctl -q is-active nginx) ; then NGINX_IS_ACTIVE=true else NGINX_IS_ACTIVE=false fi # Check PHP Version # if [[ "$PHP_ENGINE" = "FPM" ]] ; then if [[ -z "$PHP_VERSION" ]] ; then if [[ -z "$VHOST_CONFIG_FILE" ]] ; then if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf" fi fi PHP_VERSION="$(grep -o -E "php-?.{1}\..{1}-fpm" $VHOST_CONFIG_FILE | grep -o -E ".{1}\..{1}")" if [[ -z "$PHP_VERSION" ]] ; then fatal "PHP Version must be givven if running PHP-FPM engine (parameter 'PHP_VERSION')" fi fi fi # - Determin PHP binary # - php_binary="$(realpath "$(which php)")" if [[ -z "$php_binary" ]]; then if [[ -x "/usr/local/php/bin/php" ]]; then php_binary="/usr/local/php/bin/php" else fatal "No PHP binary present" fi else if [[ ! -x "$php_binary" ]]; then fatal "Found PHP binary '$php_binary', but this file is not executable!" fi fi # - Determin user/group of the webserver # - httpd_binary="`which httpd`" if [ -z "$httpd_binary" ]; then httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')" if [ -z "$httpd_binary" ]; then if [ -x "/usr/local/apache2/bin/httpd" ]; then httpd_binary="/usr/local/apache2/bin/httpd" fi fi fi if [ -x "$httpd_binary" ];then # - Determin websever user # - _HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" _HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`" # - Is webserver running ? # - PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}') if [[ "X${PID}X" = "XX" ]] ;then IS_HTTPD_RUNNING=false else IS_HTTPD_RUNNING=true fi fi if [[ -n "$_HTTP_USER" ]] ; then if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence." else HTTP_USER=$_HTTP_USER fi else [[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER fi if [[ -n "$_HTTP_GROUP" ]] ; then if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence." else HTTP_GROUP=$_HTTP_GROUP fi else [[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP fi # --- INSTALL_DIR="${WEB_BASE_DIR}/nextcloud-${VERSION}" CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" PRIOR_VERSION="$(basename $CURRENT_INSTALL_DIR | cut -d"-" -f2)" DATA_DIR=${WEB_BASE_DIR}/data-${VERSION} CURRENT_DATA_DIR="$(realpath ${WEB_BASE_DIR}/data-$PRIOR_VERSION)" #_CURRENT_DATA_DIR="$(grep datadirectory "${CURRENT_INSTALL_DIR}/config/config.php" 2> /dev/null \ # | awk '{print$3}' \ # | tr -d "'" \ # | tr -d ",")" # #CURRENT_DATA_DIR="$(realpath ${_CURRENT_DATA_DIR})" echo "" echo -e "\033[1;32mStarting Nextcloud Update for \033[1;37m${WEBSITE}\033[m" echo "" echo -e " New Nextcloud version................: $VERSION" echo -e " Old Nextcloud version................: $PRIOR_VERSION" echo "" echo -e " Website to update....................: $WEBSITE" echo "" echo -e " Web base directory...................: $WEB_BASE_DIR" echo "" echo -e " New Installation directory...........: $INSTALL_DIR" echo -e " Old Installation directory...........: $CURRENT_INSTALL_DIR" echo "" echo -e " New Data directory...................: $DATA_DIR" echo -e " Old Data directory...................: $CURRENT_DATA_DIR" echo "" echo -e " Source directory for tar archiv......: $SRC_BASE_DIR" echo "" echo -e " Webserver user.......................: $HTTP_USER" echo -e " Webserver group......................: $HTTP_GROUP" echo "" echo -e " PHP version..........................: $PHP_VERSION" echo -e " PHP Engine...........................: $PHP_ENGINE" echo "" echo -e " Databse name.........................: $DATABASE_NAME" echo -e " Database type........................: $DATABASE_TYPE" #echo "" #echo -e " Install ColaboraOnline App...........: $INSTALL_COLABORA_ONLINE_APP" echo "" if [[ "$DATABASE_TYPE" = "mysql" ]] ; then echo -e " Mysql Credentials....................: $MYSQL_CREDENTIALS" fi echo "" echo "" echo -n " Type upper case 'YES' to continue executing with this parameters: " read OK if [[ "$OK" = "YES" ]] ; then echo "" echo "" echo -e "\033[1;32mGoing to update Nextcloud on \033[1;37m$WEBSITE \033[m" echo "" else fatal "Abort by user request - Answer as not 'YES'" fi echo "" # ----- # - Do some pre-update tasks.. # ----- echo "" echo "" echo -e "\033[37m\033[1mDo some pre-update tasks..\033[m" echo "" echononl " Create source directory.." if [[ ! -d "${SRC_BASE_DIR}" ]]; then mkdir ${SRC_BASE_DIR} > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi else echo_skipped fi # - downloud nextcloud source # - echononl " Download file 'nextcloud-${VERSION}.tar.bz2'.." if [[ -f "${SRC_BASE_DIR}/nextcloud-${VERSION}.tar.bz2" ]]; then echo_skipped else wget -P ${SRC_BASE_DIR} https://download.nextcloud.com/server/releases/nextcloud-${VERSION}.tar.bz2 > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi fi echononl " Delete existing dir '${SRC_BASE_DIR}/nextcloud'.." if [ -d "${SRC_BASE_DIR}/nextcloud" ]; then rm -rf ${SRC_BASE_DIR}/nextcloud if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi else echo_skipped fi # - Entpacken # - echononl " Untar/Unpack nextcloud-${VERSION}.tar.bz2" bunzip2 < ${SRC_BASE_DIR}/nextcloud-${VERSION}.tar.bz2 | tar -C ${SRC_BASE_DIR} -xf - > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Deaktiviere Cronjobs # - _backup_crontab_file=/tmp/crontab_root.${backup_date} echononl " Backup Crontab to '$_backup_crontab_file'" crontab -l > $_backup_crontab_file 2> $log_file if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi echononl " Remove crontab for root.." crontab -r > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Stop Apache Webserver # - echo "" echononl " Stop Apache Webserver.." if $IS_HTTPD_RUNNING ; then if $SYSTEMD_EXISTS ; then systemctl stop apache2 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi else /etc/init.d/apache2 stop if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi fi else echo_skipped fi # - Stop Nginx Webservice # - echo "" echononl " Stop Nginx Webserver.." if $NGINX_IS_ACTIVE ; then if $SYSTEMD_EXISTS ; then systemctl stop apache2 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi else /etc/init.d/apache2 stop if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi fi else echo_skipped fi echo "" # - Backup Database # - echononl " Backup MySQL database '$DATABASE_NAME'.." if [[ "$DATABASE_TYPE" = 'mysql' ]]; then #mysqldump $MYSQL_CREDENTIALS --opt $DATABASE_NAME > \ mysqldump $MYSQL_CREDENTIALS --single-transaction $DATABASE_NAME > \ ${WEB_BASE_DIR}/${DATABASE_NAME}-v${PRIOR_VERSION}.${backup_date}.sql 2> $log_file if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi elif [[ "$DATABASE_TYPE" = 'postgres' ]]; then PGPASSWORD=$PSQL_PASS \ pg_dump $DATABASE_NAME -h $PSQL_SERVER -U $PSQL_USER \ -f ${WEB_BASE_DIR}/${DATABASE_NAME}-v${PRIOR_VERSION}.${backup_date}.sql 2> $log_file if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi fi echo # - Erstelle Web-Verzeichnis für die neue OwnCloud Version # - echononl " Create (new) dir '${WEB_BASE_DIR}/nextcloud-${VERSION}'.." mkdir "${WEB_BASE_DIR}/nextcloud-${VERSION}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Interrupted by user." fi mkdir ${WEB_BASE_DIR}/nextcloud-${VERSION} > $log_file 2>&1 # - Kopiere Verzeichnis "config" in das neue Installationsverzeichnis # - echononl " Copy old config into '${WEB_BASE_DIR}/nextcloud-${VERSION}'.." cp -a ${CURRENT_INSTALL_DIR}/config $INSTALL_DIR/ > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Synchronisiere neues Installationsverzeichnis mit # - den extrahierten Dateien # - echononl " Sync downloaded (new) nextlcoud int '${INSTALL_DIR}'.." rsync -a ${SRC_BASE_DIR}/nextcloud/ ${INSTALL_DIR}/ > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi echononl " Set actual date on directory '${INSTALL_DIR}'.." touch -t `date +%Y%m%d%H%M.%S` ${INSTALL_DIR} > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi # - Kopiere Daten Verzeichnis (hardlinks - harte Dateiverweise) # - echononl " Copy (hardlink) old data directory to '$DATA_DIR'.." cp -al ${CURRENT_DATA_DIR} $DATA_DIR > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Set Permissions on new install directory # - echononl " Change permissions on '${INSTALL_DIR}'.." chown -R ${HTTP_USER}:${HTTP_GROUP} ${INSTALL_DIR} if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Set Permissions on new data directory # - echononl " Change permissions on '${DATA_DIR}'.." chown -R ${HTTP_USER}:${HTTP_GROUP} ${DATA_DIR} > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Backup old data directory # - echononl " Backup old data directory" _old_data_dir="$(realpath ${WEB_BASE_DIR}/data)" mv "$_old_data_dir" "${_old_data_dir}.$backup_date" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi # - Delete symlink for old data directory # - echononl " Remove symlink from old data dir 'data-${PRIOR_VERSION}'.." rm ${WEB_BASE_DIR}/data > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Set symlink for new data directory # - echononl " Set symlink for new data dir 'data-${VERSION}'.." ln -s data-${VERSION} ${WEB_BASE_DIR}/data > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Set Parameter 'datadirectory' to '${DATA_DIR}' .." # - echononl " Set Parameter 'datadirectory' to '${DATA_DIR}'" perl -i -n -p -e "s#^(\s*'datadirectory').*#\1 => '${DATA_DIR}',#" ${INSTALL_DIR}/config/config.php > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi # - Backup old installation directory # - echononl " Backup old installation directory" _old_install_dir="$(realpath ${WEB_BASE_DIR}/nextcloud)" mv "$_old_install_dir" "${_old_install_dir}.$backup_date" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi # - Remove symlink from old installation directory # - echononl " Remove symlink from old installation directory" rm ${WEB_BASE_DIR}/nextcloud > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Set symlink (documentroot) for new installation directory # - echononl " Set symlink (documentroot) for new installation directory" ln -s nextcloud-${VERSION} ${WEB_BASE_DIR}/nextcloud > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi # - Update Nextcloud # - echo "" echo " Update Nextcloud" su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ upgrade" -s /bin/bash $HTTP_USER if [[ $? -eq 0 ]]; then info "Updating nextcloud core was successfully.." else fatal "$(cat $log_file)" fi ## ----- ## - (Re)install/(Re)enable some more nextcloud apps ## ----- # #echo "" #echo "" #echo -e "\033[37m\033[1m(Re)install/(Re)enable some more nextcloud apps..\033[m" #echo "" # # ## - Install and enable nextcloud app 'calendar' ## - #_app="calendar" # #echononl "Install nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # if grep -q -E "${_app}\s+already\s+installed" $log_file ; then # echo_skipped # warn "$(cat $log_file)" # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi #fi # #echononl "Eanable nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." #fi # # #blank_line # # ## - Install and enable nextcloud app 'contacts' ## - #_app="contacts" # #echononl "Install nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # if grep -q -E "${_app}\s+already\s+installed" $log_file ; then # echo_skipped # warn "$(cat $log_file)" # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi #fi # #echononl "Enable nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." #fi # # #blank_line # # ## - Install and enable nextcloud app 'notes' ## - #_app="notes" # #echononl "Install nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # if grep -q -E "${_app}\s+already\s+installed" $log_file ; then # echo_skipped # warn "$(cat $log_file)" # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi #fi # #echononl "Eanable nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." #fi # # #blank_line # # ## - Install and enable nextcloud app 'tasks' ## - #_app="tasks" # #echononl "Install nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1 # #if [[ $? -eq 0 ]]; then # echo_ok #else # if grep -q -E "${_app}\s+already\s+installed" $log_file ; then # echo_skipped # warn "$(cat $log_file)" # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi #fi # #echononl "Eanable nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." #fi # # #blank_line # # # #if $INSTALL_COLABORA_ONLINE_APP ; then # # - Install and enable nextcloud app 'richdocuments' # # - # _app="richdocuments" # # echononl "Install nextcloud app '$_app'.." # sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1 # if [[ $? -eq 0 ]]; then # echo_ok # else # if grep -q -E "${_app}\s+already\s+installed" $log_file ; then # echo_skipped # warn "$(cat $log_file)" # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi # fi # # echononl "Eanable nextcloud app '$_app'.." # sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1 # if [[ $? -eq 0 ]]; then # echo_ok # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi # # # echononl "Configure nextcloud app '$_app'.." # if [[ -z "$WOPI_URL" ]] ; then # echo_skipped # error "No Wopi URL given (variable 'WOPI_URL')." # else # sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:app:set richdocuments wopi_url --value="$WOPI_URL" >> $log_file 2>&1 # if [[ $? -eq 0 ]]; then # echo_ok # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi # fi #fi # # #blank_line # # ## - Install and enable nextcloud app 'bruteforcesettings' ## - #_app="bruteforcesettings" # #echononl "Install nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # if grep -q -E "${_app}\s+already\s+installed" $log_file ; then # echo_skipped # warn "$(cat $log_file)" # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi #fi # #echononl "Eanable nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1 # #if [[ $? -eq 0 ]]; then # echo_ok #else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." #fi # # ## - Install and enable nextcloud app 'announcementcenter' ## - #_app="announcementcenter" # #echononl "Install nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1 #if [[ $? -eq 0 ]]; then # echo_ok #else # if grep -q -E "${_app}\s+already\s+installed" $log_file ; then # echo_skipped # warn "$(cat $log_file)" # else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." # fi #fi # #echononl "Eanable nextcloud app '$_app'.." #sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1 # #if [[ $? -eq 0 ]]; then # echo_ok #else # echo_failed # error "$(cat $log_file)" # # echononl "continue anyway [yes/no]: " # read OK # OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" # while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do # echononl "Wrong entry! - repeat [yes/no]: " # read OK # done # [[ $OK = "yes" ]] || fatal "Interrupted by user." #fi # ----- # - Doing some post-update tasks # ----- echo "" echo "" echo -e "\033[37m\033[1mDoing some post-update tasks..\033[m" echo "" echononl " Restart PHP engine.." if [[ "$PHP_ENGINE" = "FPM" ]]; then if $SYSTEMD_EXISTS ; then systemctl restart php-${PHP_VERSION}-fpm > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Interrupted by user." fi else /etc/init.d/php-${PHP_VERSION}-fpm restart > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Interrupted by user." fi fi else echo_skipped fi # - Start Apache Webserver # - echo "" echononl " Start Apache Webserver.." if $IS_HTTPD_RUNNING ; then if $SYSTEMD_EXISTS ; then systemctl start apache2 > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Interrupted by user." fi else /etc/init.d/apache2 start > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Interrupted by user." fi fi else echo_skipped warn "The webserver was not running, so it will be keept down!" fi # - Start NGINX Webservise # - echo "" echononl " Start Nginx Webserver.." if $NGINX_IS_ACTIVE ; then if $SYSTEMD_EXISTS ; then systemctl start nginx > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Interrupted by user." fi else /etc/init.d/nginx start > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Interrupted by user." fi fi else echo_skipped warn "The NGINX is not configured as active - so nothing to do." fi _redis_cli_bin="$(which redis-cli)" if [[ -z "$_redis_cli_bin" ]]; then if [[ -x "/usr/local/bin/redis-cli" ]]; then _redis_cli_bin="/usr/local/bin/redis-cli" fi fi echononl " Flush redis cache.." if [[ -x "$_redis_cli_bin" ]]; then $_redis_cli_bin flushall > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi else echo_skipped fi echononl " Restart redis server.." if $SYSTEMD_EXISTS ; then systemctl restart redis-server > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi else /etc/init.d/redis-server restart > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi fi blank_line clean_up 0 cd $WEB_BASE_DIR ------------------------------------------------------------------------ ## - Alternativly enable maintenance mode ## - su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ maintenance:mode --on" -s /bin/bash $HTTP_USER ## - Deactivate third party apps ## - ## - for _app in $THIRD_PARTY_APPS ; do ## - #su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ app:disable $_app" -s /bin/bash $HTTP_USER ## - su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/nextcloud/occ app:disable $_app" -s /bin/bash $HTTP_USER ## - done for _app in $THIRD_PARTY_APPS ; do #su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ app:disable $_app" -s /bin/bash $HTTP_USER su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/nextcloud/occ app:disable $_app" -s /bin/bash $HTTP_USER done ## - ## - Enable third party apps ## - ## - ## - for _app in $THIRD_PARTY_APPS ; do ## - su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ app:enable $_app" -s /bin/bash $HTTP_USER ## - done for _app in $THIRD_PARTY_APPS ; do su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ app:enable $_app" -s /bin/bash $HTTP_USER done ------------------------------------------------------------------------ https://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html while IFS= read -r -d '' n; do #if [[ "$n" == "mb" ]]; then # continue #fi su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/console.php files:scan --path `basename $n`" -s /bin/bash $HTTP_USER done < <(find $WEB_BASE_DIR/data/ -mindepth 1 -maxdepth 1 -type d -print0) su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/console.php files:scan --all" -s /bin/bash $HTTP_USER su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ maintenance:repair" -s /bin/bash $HTTP_USER