commit e02fdeffe37f195ce62962c84f2f989b417c20c4 Author: Christoph Date: Mon Feb 11 03:50:45 2019 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7029d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +BAK/* +.*.swp +*.tar.bz2 +*.tar.gz +/nextcloud* +/log_* +/conf/*.conf diff --git a/conf/install_nextcloud.conf.sample b/conf/install_nextcloud.conf.sample new file mode 100644 index 0000000..8bff92a --- /dev/null +++ b/conf/install_nextcloud.conf.sample @@ -0,0 +1,109 @@ +# --- +# - Configuration file for script 'update_nextcloud.sh' +# --- + + +# - SRC_BASE_DIR +# - +# - Source directory for downloading nextcloud +# - +# - Default: SRC_BASE_DIR="/usr/local/src/nextcloud" +# - +#SRC_BASE_DIR="/usr/local/src/nextcloud" + + +# - WEB_DIRS_ROOT +# - +# - Default: WEB_DIRS_ROOT="/var/www" +# - +#WEB_DIRS_ROOT="/var/www" + + +# - Webservers user +# - +# - The script wil determin the webservers user, so you don't need to +# - configure it here. +# - +# - Setting this value take precedence over the scripts determined value. +# +#HTTP_USER= + +# - Webservers group +# - +# - The script wil determin the webservers group, so you don't need to +# - configure it here. +# - +# - Setting this value take precedence over the scripts determined value. +# - +#HTTP_GROUP= + + +# - PHP engine +# - +# - Possible values: 'FPM' 'FCGI' 'MOD-PHP' +# - +# - Note: at time only FPM is supported!! +# - +# - Default: PHP_ENGINE="FPM" +# - +#PHP_ENGINE="FPM" + +# - PHP main version +# - +# - Examples: +# - PHP_VERSION=5.6 +# - PHP_VERSION=7.1 +# - +# - only needed, if PHP_ENGINE ist set to 'FPM' +# - +#PHP_VERSION= + + +# - DATABASE_TYPE +# - +# - Setting this value is required! +# - +# - Possible values: 'mysql' 'postgres' +# - +# - Defaults: DATABASE_TYPE="mysql" +#DATABASE_TYPE="mysql" + +# - DATABASE_NAME +# - +# - Setting this value is required! +# - +DATABASE_NAME="" + +# - DATABASE_HOST +# - +# - Database Host +# - +# - Default: DATABASE_HOST="localhost" +# - +DATABASE_HOST="localhost" + +# - Credentials to access Database +# - +DATABASE_USER="" +DATABASE_PASS="" + +# - Credentials to access MySQL/MariaDB Database +# - +# - Example +# - mysql_credential_args="--login-path=local" +# - mysql_credential_args="--defaults-file=/etc/mysql/debian.cnf" (Debian default) +# - mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf" +# - +# - Default: MYSQL_CREDENTIALS="--login-path=local" +#MYSQL_CREDENTIALS="--login-path=local" + + +# - Third Party modules of your NextCloud instance +# - +# - This Parameter is currently not in use +# - +# - Possible values are app-names like 'calendar' , 'contacts' , .. +# - +# - Takes a space seperated list +# - +#THIRD_PARTY_APPS="calendar contacts tasks notes richdocuments" diff --git a/install_nextcloud.sh b/install_nextcloud.sh new file mode 100755 index 0000000..1109203 --- /dev/null +++ b/install_nextcloud.sh @@ -0,0 +1,3093 @@ +#!/usr/bin/env bash + + +script_name="$(basename $(realpath $0))" +working_dir="$(dirname $(realpath $0))" + +conf_file="${working_dir}/conf/${script_name%%.*}.conf" + +declare -a unsorted_website_arr+ +declare -a website_arr + +err_log="$(mktemp)" + +backup_date=$(date +%Y-%m-%d-%H%M) + + +# ============= +# --- Some functions +# ============= + +clean_up() { + + if [[ -f "$_backup_crontab_file" ]]; then + + echo "" >> $log_file + echo "# - (Re)Install previously saved crontab from '$_backup_crontab_file'" >> $log_file + echo "# -" >> $log_file + echononl "(Re)Install previously saved crontab from '$_backup_crontab_file'.." + + echo "crontab $_backup_crontab_file" >> $log_file + crontab $_backup_crontab_file >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$log_file'." + fi + + fi + + # Perform program exit housekeeping + rm -f $err_log + 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[80G[ \033[32mdone\033[m ]" + else + echo " [ done ]" + fi +} +echo_ok() { + if $terminal ; then + echo -e "\033[80G[ \033[32mok\033[m ]" + else + echo " [ ok ]" + fi +} +echo_warning() { + if $terminal ; then + echo -e "\033[80G[ \033[33m\033[1mwarn\033[m ]" + else + echo " [ warning ]" + fi +} +echo_failed(){ + if $terminal ; then + echo -e "\033[80G[ \033[1;31mfailed\033[m ]" + else + echo ' [ failed! ]' + fi +} +echo_skipped() { + if $terminal ; then + echo -e "\033[80G[ \033[37mskipped\033[m ]" + else + echo " [ skipped ]" + fi +} +fatal (){ + echo "" + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFatal\033[m ]: $*" + echo "" + echo -e " \033[31m\033[1m Script will be interrupted..\033[m\033[m" + else + echo "fatal: $*" + echo "Script will be interrupted.." + fi + echo "" + clean_up 1 +} + +error(){ + echo "" + if $terminal ; then + echo -e " [ \033[31m\033[1mFehler\033[m ]: $*" + else + echo "Error: $*" + fi + echo "" +} + +warn (){ + echo "" + if $terminal ; then + echo -e " [ \033[33m\033[1mWarning\033[m ]: $*" + else + echo "Warning: $*" + fi + echo "" +} + +info (){ + echo "" + if $terminal ; then + echo -e " [ \033[32m\033[1mInfo\033[m ]: $*" + else + echo "Info: $*" + fi + echo "" +} + +## - 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 +} + +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + +blank_line() { + if $terminal ; then + echo "" + fi +} + + + + +# ---------- +# - Jobhandling +# ---------- + +# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM +# - +trap clean_up SIGHUP SIGINT SIGTERM + + +# ---------- +# - Some checks .. +# ---------- + +if [[ -n "$1" ]]; then + DEFAULT_WEBSITE="$1" + if [[ -n "$2" ]]; then + DEFAULT_VERSION="$2" + fi +fi + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + +# -Is systemd supported on this system? +# - +systemd_supported=false +systemd=$(which systemd) +systemctl=$(which systemctl) + +if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then + systemd_supported=true +fi + +clear + + +# ---------- +# Read Configurations from $conf_file +# ---------- + + +# - Give your default values here +# - + +DEFAULT_SRC_BASE_DIR="$working_dir" +DEFAULT_ADMIN_USER="admin" +DEFAULT_WEB_DIRS_ROOT="/var/www" +DEFAULT_PHP_ENGINE="FPM" +DEFAULT_DATABASE_TYPE="mysql" +DEFAULT_DATABASE_HOST="localhost" + + +if [[ -f "$conf_file" ]]; then + source "$conf_file" +else + warn "No configuration file '$conf_file' present.\n\n Loading default values.." +fi + +[[ -z "$SRC_BASE_DIR" ]] && SRC_BASE_DIR="$DEFAULT_SRC_BASE_DIR" + +[[ -z "$WEB_DIRS_ROOT" ]] && WEB_DIRS_ROOT=$DEFAULT_WEB_DIRS_ROOT + +[[ -z "$PHP_ENGINE" ]] && PHP_ENGINE="$DEFAULT_PHP_ENGINE" + +[[ -z "$DATABASE_TYPE" ]] && DATABASE_TYPE="$DEFAULT_DATABASE_TYPE" +[[ -z "$DATABASE_HOST" ]] && DATABASE_HOST="$DEFAULT_DATABASE_HOST" + +[[ -z "$ADMIN_USER" ]] && ADMIN_USER="$DEFAULT_ADMIN_USER" + + + +# ========== +# - Begin Main Script +# ========== + +# ---------- +# - Headline +# ---------- + +if $terminal ; then + echo "" + echo -e "\033[1m----------\033[m" + echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m" + echo -e "\033[1m----------\033[m" +fi + + +echo "" +echo " Insert the name of the website containing the nextcloud instance .." +echo "" +if [[ -n "$WEBSITE" ]] ;then + DEFAULT_WEBSITE="$WEBSITE" +fi +WEBSITE= + +if [[ -n "$DEFAULT_WEBSITE" ]]; then + + echononl "\033[1mWebsite Name [${DEFAULT_WEBSITE}]:\033[m " + read WEBSITE + if [[ "X$WEBSITE" = "X" ]]; then + WEBSITE="$DEFAULT_WEBSITE" + fi +else + echononl "\033[1mWebsite Name:\033[m " + read WEBSITE + while [[ "X$WEBSITE" = "X" ]]; do + echo -e "\n \033[33m\033[1mName of website is required!\033[m\n" + echononl "\033[1mWebsite Name:\033[m " + read WEBSITE + done +fi +DEFAULT_WEB_BASE_DIR="${WEB_DIRS_ROOT}/$WEBSITE" + +if [[ ! -d "${WEB_DIRS_ROOT}/$WEBSITE" ]] ; then + echo "" + echo -e " \033[32m--\033[m" + echo "" + echo " Insert Website Base Directory." + echo "" + echo "" + WEB_BASE_DIR= + echononl "\033[1mWebsite Base Directory:\033[m " + read WEB_BASE_DIR + + while [[ "X$WEB_BASE_DIR" = "X" ]] ; do + echo -e "\n \033[33m\033[1mWebsites Base Directory is required!\033[m\n" + echononl "\033[1mWebsites Base Directory:\033[m " + read WEB_BASE_DIR + done + +else + WEB_BASE_DIR="${WEB_DIRS_ROOT}/$WEBSITE" +fi + +if [[ ! -d "${WEB_BASE_DIR}" ]]; then + fatal "Website '$WEBSITE' seems not to be existent at this server.\n\n \033[37m\033[1mCreate Website first!\033[m" +fi + + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert (new) Nextcloud version number." +echo "" +echo "" +if [[ -n "$VERSION" ]] ;then + DEFAULT_VERSION="$VERSION" +fi +VERSION= + +if [[ -n "$DEFAULT_VERSION" ]]; then + + echononl "\033[1mNextcloud version number [${DEFAULT_VERSION}]:\033[m " + read VERSION + if [[ "X$VERSION" = "X" ]]; then + VERSION="$DEFAULT_VERSION" + fi +else + echononl "\033[1mNextcloud version number:\033[m " + read VERSION + while [[ "X$VERSION" = "X" ]]; do + echo -e "\n \033[33m\033[1mNextcloud version number is required!\033[m\n" + echononl "\033[1mNextcloud version number:\033[m " + read VERSION + done +fi +log_dir="${SRC_BASE_DIR}/log_nextcloud-${VERSION}" + + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert admin username for the new Nextcloud installation." +echo "" +echo "" +if [[ -n "$ADMIN_USER" ]] ;then + DEFAULT_ADMIN_USER="$ADMIN_USER" +fi +ADMIN_USER= + +if [[ -n "$DEFAULT_ADMIN_USER" ]]; then + + echononl "\033[1mAdmin user name [${DEFAULT_ADMIN_USER}]:\033[m " + read ADMIN_USER + if [[ "X$ADMIN_USER" = "X" ]]; then + ADMIN_USER="$DEFAULT_ADMIN_USER" + fi +else + echononl "\033[1mAdmin user name:\033[m " + read ADMIN_USER + while [[ "X$ADMIN_USER" = "X" ]]; do + echo -e "\n \033[33m\033[1mAdmin user name is required!\033[m\n" + echononl "\033[1mAdmin user name:\033[m " + read ADMIN_USER + done +fi + + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert Password for admin user." +echo "" +echo "" +_ADMIN_PASSWD_1="X" +_ADMIN_PASSWD_2="Y" +while [[ "$_ADMIN_PASSWD_1" != "$_ADMIN_PASSWD_2" ]] ; do + + echononl "\033[1mPassword for admin user:\033[m " + read -s _ADMIN_PASSWD_1 + + blank_line + + if [[ "X$_ADMIN_PASSWD_1" = "X" ]]; then + echo -e "\n \033[33m\033[1mPassword for admin user is required!\033[m\n" + continue + fi + + echononl "\033[1mRepeat password:\033[m " + read -s _ADMIN_PASSWD_2 + + if [[ "$_ADMIN_PASSWD_1" != "$_ADMIN_PASSWD_2" ]]; then + echo -e "\n\n \033[33m\033[1mPasswords did not match!\033[m\n" + else + ADMIN_PASS="$_ADMIN_PASSWD_1" + fi + +done + + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert Type of PHP engine." +echo "" +echo "" +PHP_ENGINE= +echononl "\033[1mPHP engine [$DEFAULT_PHP_ENGINE]:\033[m " +read PHP_ENGINE +if [[ "X$PHP_ENGINE" = "X" ]]; then + PHP_ENGINE="$DEFAULT_PHP_ENGINE" +fi + +echononl "Determin main PHP Version.." +_php_version="$(php --version 2> /dev/null | head -1 | awk '{print$2}')" +if [[ -n "$_php_version" ]] ; then + DEFAULT_PHP_VERSION="$(echo $_php_version | cut -d '.' -f1,2)" + if [[ -n "$DEFAULT_PHP_VERSION" ]]; then + echo_ok + else + echo_failed + fi +else + echo_failed +fi + +if [[ "$PHP_ENGINE" = "FPM" ]] ; then + echo "" + echo -e " \033[32m--\033[m" + echo "" + echo " Insert PHP (Main) Version." + echo "" + echo " Examples:" + echo " 7.1" + echo " 7.3" + echo "" + PHP_VERSION= + + if [[ -n "$DEFAULT_PHP_VERSION" ]] ;then + echononl "\033[1mPHP Version [${DEFAULT_PHP_VERSION}]:\033[m " + read PHP_VERSION + + if [[ -z "$(trim $PHP_VERSION)" ]]; then + PHP_VERSION="$DEFAULT_PHP_VERSION" + fi + + else + + echononl "\033[1mPHP Version:\033[m " + read PHP_VERSION + + while [[ "X$PHP_VERSION" = "X" ]] ; do + echo -e "\n \033[33m\033[1mPHP version number is required!\033[m\n" + echononl "\033[1mPHP Version:\033[m " + read PHP_VERSION + done + fi +fi + +if [[ ! -d "/usr/local/php-$PHP_VERSION" ]]; then + fatal "No Installation of PHP Version $PHP_VERSION found..\n\n \033[37m\033[1mInstall PHP version $PHP_VERSION first!\033[m" +fi + + + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert Database type (mysql or postgres)." +echo "" +echo "" +DATABASE_TYPE= +echononl "\033[1mDatabase Type [${DEFAULT_DATABASE_TYPE}]:\033[m " +read DATABASE_TYPE +if [[ "X$DATABASE_TYPE" = "X" ]]; then + DATABASE_TYPE="$DEFAULT_DATABASE_TYPE" +fi + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert Database name." +echo "" +echo "" +if [[ -n "$DATABASE_NAME" ]] ;then + DEFAULT_DATABASE_NAME="$DATABASE_NAME" +fi +DATABASE_NAME= + +if [[ -n "$DEFAULT_DATABASE_NAME" ]]; then + + echononl "\033[1mDatabase Name [${DEFAULT_DATABASE_NAME}]:\033[m " + read DATABASE_NAME + if [[ "X$DATABASE_NAME" = "X" ]]; then + DATABASE_NAME="$DEFAULT_DATABASE_NAME" + fi +else + echononl "\033[1mDatabase Name:\033[m " + read DATABASE_NAME + while [[ "X$DATABASE_NAME" = "X" ]]; do + echo -e "\n \033[33m\033[1mDatabase Name is required!\033[m\n" + echononl "\033[1mDatabase Name:\033[m " + read DATABASE_NAME + done +fi + + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert Database host." +echo "" +echo "" +DATABASE_HOST= +echononl "\033[1mDatabase Host [${DEFAULT_DATABASE_HOST}]\033[m " +read DATABASE_HOST +if [[ "X$DATABASE_HOST" = "X" ]]; then + DATABASE_HOST="$DEFAULT_DATABASE_HOST" +fi + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert Database user." +echo "" +echo "" +if [[ -n "$DATABASE_USER" ]] ;then + DEFAULT_DATABASE_USER="$DATABASE_USER" +fi +DATABASE_USER= + +if [[ -n "$DEFAULT_DATABASE_USER" ]]; then + + echononl "\033[1mDatabase User [${DEFAULT_DATABASE_USER}]:\033[m " + read DATABASE_USER + if [[ "X$DATABASE_USER" = "X" ]]; then + DATABASE_USER="$DEFAULT_DATABASE_USER" + fi +else + echononl "\033[1mDatabase User:\033[m " + read DATABASE_USER + while [[ "X$DATABASE_USER" = "X" ]]; do + echo -e "\n \033[33m\033[1mDatabase User is required!\033[m\n" + echononl "\033[1mDatabase User:\033[m " + read DATABASE_USER + done +fi + +echo "" +echo -e " \033[32m--\033[m" +echo "" +echo " Insert Database password." +echo "" +echo "" +if [[ -n "$DATABASE_PASS" ]] ;then + DEFAULT_DATABASE_PASS="$DATABASE_PASS" +fi +DATABASE_PASS= + +if [[ -n "$DEFAULT_DATABASE_PASS" ]]; then + + echononl "\033[1mDatabase Password [${DEFAULT_DATABASE_PASS}]:\033[m " + read DATABASE_PASS + if [[ "X$DATABASE_PASS" = "X" ]]; then + DATABASE_PASS="$DEFAULT_DATABASE_PASS" + fi +else + echononl "\033[1mDatabase Password:\033[m " + read DATABASE_PASS + while [[ "X$DATABASE_PASS" = "X" ]]; do + echo -e "\n \033[33m\033[1mDatabase Password is required!\033[m\n" + echononl "\033[1mDatabase Password:\033[m " + read DATABASE_PASS + done +fi + + +# ---------- +# Some checks +# ---------- + +# - 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 + + +DATA_DIR=${WEB_BASE_DIR}/data-${VERSION} +INSTALL_DIR=${WEB_BASE_DIR}/nextcloud-${VERSION} + + +echo "" +echo "" +echo -e "\033[32m--\033[m" +echo -e "\033[1;32mStarting Nextcloud Installation for \033[1;37m${WEBSITE}\033[m" +echo -e "\033[32m--\033[m" +echo "" +echo " Nextcloud verion.....................: $VERSION" +echo " Nextcloud installation directory.....: $INSTALL_DIR" +echo " Nextcloud data directory.............: $DATA_DIR" +echo "" +echo " Admin user name......................: $ADMIN_USER" +echo " Passord for admin user...............: $ADMIN_PASS" +echo "" +echo " Website..............................: $WEBSITE" +echo "" +echo " Web base directory...................: $WEB_BASE_DIR" +echo "" +echo " Source directory for source archiv...: $SRC_BASE_DIR" +echo "" +echo " Webserver user.......................: $HTTP_USER" +echo " Webserver group......................: $HTTP_GROUP" +echo "" +echo " PHP version..........................: $PHP_VERSION" +echo " PHP Engine...........................: $PHP_ENGINE" +echo "" +echo " Databse name.........................: $DATABASE_NAME" +echo " Database type........................: $DATABASE_TYPE" +echo " Database user........................: $DATABASE_USER" +echo " Database password....................: $DATABASE_PASS" +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 install \033[1;37mNextcloud $VERSION\033[1;32m at \033[1;37m$(hostname -f)\033[m" + echo "" +else + fatal "Abort by user request - Answer as not 'YES'" +fi + + +echo "" + +# - Create log directory" +# - +if [[ -d "${log_dir}" ]] ; then + echononl "Backup existent log directory .." + mv "${log_dir}" "${log_dir}.$backup_date" + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fatal "Cannot backup log directory '${log_dir}'!" + fi +fi + +echononl "Create log directory '${log_dir}' .." +mkdir "${log_dir}" > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + fatal "Cannot create log directory '${log_dir}'!" +fi +log_file="${log_dir}/main.log" + + +:> $log_file +echo "# - Starte Nextcloud Installation mit folgenden Parametern:" >> ${log_dir}/main.log +echo "# -" >> $log_file +echo "# - Nextcloud verion.....................: $VERSION" >> $log_file +echo "# - Nextcloud installation directory.....: $INSTALL_DIR" >> $log_file +echo "# - Nextcloud data directory.............: $DATA_DIR" >> $log_file +echo "# -" >> $log_file +echo "# - Admin user name......................: $ADMIN_USER" >> $log_file +echo "# - Passord for admin user...............: $ADMIN_PASS" >> $log_file +echo "# -" >> $log_file +echo "# - Website..............................: $WEBSITE" >> $log_file +echo "# -" >> $log_file +echo "# - Web base directory...................: $WEB_BASE_DIR" >> $log_file +echo "# -" >> $log_file +echo "# - Source directory for source archiv...: $SRC_BASE_DIR" >> $log_file +echo "# -" >> $log_file +echo "# - Webserver user.......................: $HTTP_USER" >> $log_file +echo "# - Webserver group......................: $HTTP_GROUP" >> $log_file +echo "# -" >> $log_file +echo "# - PHP version..........................: $PHP_VERSION" >> $log_file +echo "# - PHP Engine...........................: $PHP_ENGINE" >> $log_file +echo "# -" >> $log_file +echo "# - Databse name.........................: $DATABASE_NAME" >> $log_file +echo "# - Database type........................: $DATABASE_TYPE" >> $log_file +echo "# - Database user........................: $DATABASE_USER" >> $log_file +echo "# - Database password....................: $DATABASE_PASS" >> $log_file +echo "" >> $log_file +echo "" >> $log_file + + +echo "VERSION=$VERSION" >> $log_file +echo "INSTALL_DIR=$INSTALL_DIR" >> $log_file +echo "DATA_DIR=$DATA_DIR" >> $log_file +echo "ADMIN_USER=$ADMIN_USER" >> $log_file +echo "ADMIN_PASS=$ADMIN_PASS" >> $log_file +echo "WEBSITE=$WEBSITE" >> $log_file +echo "WEB_BASE_DIR=$WEB_BASE_DIR" >> $log_file +echo "SRC_BASE_DIR=$SRC_BASE_DIR" >> $log_file +echo "HTTP_USER=$HTTP_USER" >> $log_file +echo "HTTP_GROUP=$HTTP_GROUP" >> $log_file +echo "PHP_VERSION=$PHP_VERSION" >> $log_file +echo "PHP_ENGINE=$PHP_ENGINE" >> $log_file +echo "DATABASE_NAME=$DATABASE_NAME" >> $log_file +echo "DATABASE_TYPE=$DATABASE_TYPE" >> $log_file +echo "DATABASE_USER=$DATABASE_USER" >> $log_file +echo "DATABASE_PASS=$DATABASE_PASS" >> $log_file + +echo "" >> $log_file +echo "" >> $log_file + + +# ----- +# - Doing some pre-installation tasks +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mDoing some pre-installation tasks..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Doing some pre-installation tasks" >> $log_file +echo "# -----" >> $log_file + + +# - Deaktiviere Cronjobs +# - +_backup_crontab_file=/tmp/crontab_root.${backup_date} + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Backup Crontab to '$_backup_crontab_file'" >> $log_file +echononl "Backup Crontab to '$_backup_crontab_file'" + +echo "crontab -l > $_backup_crontab_file" >> $log_file +crontab -l > $_backup_crontab_file 2>> $log_file + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 "Interupted by user" +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Remove crontab for root" >> $log_file +echononl "Remove crontab for root.." + +echo "crontab -r" >> $log_file +crontab -r >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 "Interupted by user" + +fi + + +# - Stop Apache Webserver +# - +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Stop Apache Webserver" >> $log_file +echononl "Stop Apache Webserver.." +if $systemd_supported ; then + + echo "systemctl stop apache2" >> $log_file + systemctl stop apache2 >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 "Interupted by user" + + fi +else + + echo "/etc/init.d/apache2 stop" >> $log_file + /etc/init.d/apache2 stop >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 "Interupted by user" + + fi +fi + + +# ----- +# - Some checks +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mDoing some checks..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Doing some checks" >> $log_file +echo "# -----" >> $log_file + +checks_all_is_fine=true + + +# - Check if database exists and is empty +# - + +if [[ "$DATABASE_TYPE" = "mysql" ]] ; then + if [[ ! "$(mysqlshow -h $DATABASE_HOST -u $DATABASE_USER -p$DATABASE_PASS $DATABASE_NAME 2>/dev/null)" ]] ; then + fatal "Cannot connect database \033[1m$DATABASE_NAME\033[m!" + fi + + _tables="$(mysql -h $DATABASE_HOST -u $DATABASE_USER -p$DATABASE_PASS $DATABASE_NAME -N -s -e 'SHOW TABLES' 2>/dev/null)" + if [[ -n "$_tables" ]] ; then + warn "Database \033[1m$DATABASE_NAME\033[m is NOT empty but this is an initial instalation!" + + checks_all_is_fine=false + + echo "" >> $log_file + echo "# - Backup database '$DATABASE_NAME'" >> $log_file + echo "# -" >> $log_file + echononl "Backup database '$DATABASE_NAME' .." + + echo "mysqldump -h $DATABASE_HOST -u $DATABASE_NAME -p$DATABASE_PASS --opt $DATABASE_NAME > ${WEB_BASE_DIR}/${DATABASE_NAME}.${backup_date}.sql" >> $log_file + mysqldump -h $DATABASE_HOST -u $DATABASE_NAME -p$DATABASE_PASS --opt $DATABASE_NAME > ${WEB_BASE_DIR}/${DATABASE_NAME}.${backup_date}.sql 2>> $log_file + + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "For more informations see log output at '$log_file'." + clean_up 1 + fi + + echo "" >> $log_file + echo "# - Drop tables of database '$DATABASE_NAME'" >> $log_file + echo "# -" >> $log_file + echononl "Drop tables of database '$DATABASE_NAME'" + + _failed=false + declare -a _tables_not_deleted=() + for _table in $_tables ; do + + echo "mysql -h $DATABASE_HOST -u $DATABASE_NAME -p$DATABASE_PASS $DATABASE_NAME -N -s -e \"DROP TABLE \\\`$_table\\\`\"" >> $log_file + mysql -h $DATABASE_HOST -u $DATABASE_NAME -p$DATABASE_PASS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $log_file 2>&1 + + if [[ $? -ne 0 ]] ; then + _failed=true + _tables_not_deleted+=("$_table") + fi + done + + if $_failed ; then + echo_failed + error ""For more informations see log output at '$log_file'."" + clean_up 1 + else + echo_ok + fi + + fi + +elif [[ "$DATABASE_TYPE" = "postgres" ]] ; then + count="$(su - postgres -c "psql -q -A -t -l" | grep -c -e "^$DATABASE_NAME")" + + if [[ $count -eq 0 ]]; then + warn "Cannot find database \033[1m$DATABASE_NAME\033[m!\n\n \033[1mCreate database first." + + checks_all_is_fine=false + + echo "" >> $log_file + echo "# - Create ROLE for user '$DATABASE_USER'" >> $log_file + echo "# -" >> $log_file + echononl "Create ROLE for user \033[1m$DATABASE_USER\033[m .." + echo "echo \"CREATE ROLE $DATABASE_USER WITH LOGIN NOCREATEDB NOCREATEROLE NOSUPERUSER ENCRYPTED PASSWORD '$DATABASE_PASS'\" | su - postgres -c \"psql\"" >> $log_file +EOF + echo "CREATE ROLE $DATABASE_USER WITH LOGIN NOCREATEDB NOCREATEROLE NOSUPERUSER ENCRYPTED PASSWORD '$DATABASE_PASS'" | su - postgres -c "psql" > $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error ""For more informations see log output at '$log_file'."" + clean_up 1 + fi + + echo "" >> $log_file + echo "# - Create database '$DATABASE_NAME'" >> $log_file + echo "# -" >> $log_file + echononl "Create database \033[1m$DATABASE_NAME\033[m .." + echo "su - postgres -c \"createdb -E utf8 -O $DATABASE_USER $DATABASE_NAME\"" >> $log_file 2>&1 + su - postgres -c "createdb -E utf8 -O $DATABASE_USER $DATABASE_NAME" >> $log_file 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "For more informations see log output at '$log_file'." + clean_up 1 + fi + else + : + fi +fi + +##!# - Backup Database +##!# - +##!echononl " Backup MySQL database '$DATABASE_NANE'.." +##!if [[ "$DATABASE_TYPE" = 'mysql' ]]; then +##! mysqldump $MYSQL_CREDENTIALS --opt $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 postfix-${backup_date}.sql +##! if [[ $? -eq 0 ]]; then +##! echo_ok +##! else +##! echo_failed +##! fatal "$(cat $log_file)" +##! fi +##!fi + + +# - Backup old installation directory +# - +if [[ -d "$INSTALL_DIR" ]] ; then + + warn "Nextcloud's installation directory \033[1m$INSTALL_DIR\033[m already exists!" + + checks_all_is_fine=false + + echo "" >> $log_file + echo "# - Backup existing installation directory '${INSTALL_DIR}'" >> $log_file + echo "# -" >> $log_file + echononl "Backup existing installation directory '${INSTALL_DIR}'.." + + echo "mv \"$INSTALL_DIR\" \"${INSTALL_DIR}.$backup_date\"" >> $log_file + mv "$INSTALL_DIR" "${INSTALL_DIR}.$backup_date" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 "Interupted by user" + + fi +fi + + +# - Backup old data directory +# - +if [[ -d "$DATA_DIR" ]] ; then + + warn "Nextcloud's data directory \033[1m$DATA_DIR\033[m already exists" + + checks_all_is_fine=false + + echo "" >> $log_file + echo "# - Backup existing data directory '${DATA_DIR}'" >> $log_file + echo "# -" >> $log_file + echononl "Backup existing data directory '${DATA_DIR}'.. + " + echo "mv \"$DATA_DIR\" \"${DATA_DIR}.$backup_date\"" >> $log_file + mv "$DATA_DIR" "${DATA_DIR}.$backup_date" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 "Abbruch durch User" + + fi +fi + +if $checks_all_is_fine ; then + info "All is fine.." +fi + + +# ----- +# - Download/Unpack sources +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mDownload/Unpack sources..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Download/Unpack sources" >> $log_file +echo "# -----" >> $log_file + + +echononl "Create source directory '${DATA_DIR}'.." +if [[ ! -d "${SRC_BASE_DIR}" ]]; then + + echo "" >> $log_file + echo "# - Create source directory '${DATA_DIR}'" >> $log_file + echo "# -" >> $log_file + + echo "mkdir \"${SRC_BASE_DIR}\"" >> $log_file + mkdir "${SRC_BASE_DIR}" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$log_file'." + clean_up 1 + 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 + + echo "" >> $log_file + echo "# - Download file 'nextcloud-${VERSION}.tar.bz2'" >> $log_file + echo "# -" >> $log_file + + echo "wget -P ${SRC_BASE_DIR} https://download.nextcloud.com/server/releases/nextcloud-${VERSION}.tar.bz2" >> $log_file 2>&1 + 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 + error "For more informations see log output at '$log_file'." + clean_up 1 + fi +fi + +echononl "Delete existing dir '${SRC_BASE_DIR}/nextcloud'.." +if [[ -d "${SRC_BASE_DIR}/nextcloud" ]]; then + + echo "" >> $log_file + echo "# - Delete existing dir '${SRC_BASE_DIR}/nextcloud'.." >> $log_file + echo "# -" >> $log_file + + echo "rm -rf \"${SRC_BASE_DIR}/nextcloud\"" >> $log_file + rm -rf "${SRC_BASE_DIR}/nextcloud" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$log_file'." + clean_up 1 + fi +else + echo_skipped +fi + +# - Entpacken +# - +echo "" >> $log_file +echo "# - Untar/Unpack 'nextcloud-${VERSION}.tar.bz2'" >> $log_file +echo "# -" >> $log_file +echononl "Untar/Unpack 'nextcloud-${VERSION}.tar.bz2'.." + +echo "bunzip2 < \"${SRC_BASE_DIR}/nextcloud-${VERSION}.tar.bz2\" | tar -C ${SRC_BASE_DIR} -xf -" >> $log_file +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 + error "For more informations see log output at '$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 ny user." + +fi + + +# ----- +# - Create needed directories +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mCreate needed directories..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Create needed directories" >> $log_file +echo "# -----" >> $log_file + + +# - Create Installation Directory +# - +echo "" >> $log_file +echo "# - Create (new) installation dir '${INSTALL_DIR}'" >> $log_file +echo "# -" >> $log_file +echononl "Create (new) installation dir '${INSTALL_DIR}'.." + +echo "mkdir \"$INSTALL_DIR\"" >> $log_file +mkdir "$INSTALL_DIR" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." + +fi + +# - Create data directory +# - +echo "" >> $log_file +echo "# - Create (new) data dir '${DATA_DIR}'" >> $log_file +echo "# -" >> $log_file +echononl "Create (new) data dir '${DATA_DIR}'.." + +echo "mkdir \"$DATA_DIR\"" >> $log_file +mkdir "$DATA_DIR" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Set Permissions on new data directory +# - +echo "" >> $log_file +echo "# - Change permissions on '${DATA_DIR}'" >> $log_file +echo "# -" >> $log_file +echononl "Change permissions on '${DATA_DIR}'.." + +echo "chown -R \"${HTTP_USER}\":\"${HTTP_GROUP}\" \"${DATA_DIR}\"" >> $log_file +chown -R "${HTTP_USER}":"${HTTP_GROUP}" "${DATA_DIR}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + + 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 ny user." +fi + + +# - Create log directory +# - +echononl "Create (new) data dir '${WEB_BASE_DIR}/logs'.." + +if [[ ! -d "${WEB_BASE_DIR}/logs" ]] ; then + + echo "" >> $log_file + echo "# - Create log directory '${WEB_BASE_DIR}'/logs" >> $log_file + echo "# -" >> $log_file + + echo "mkdir \"${WEB_BASE_DIR}/logs\"" >> $log_file + mkdir "${WEB_BASE_DIR}/logs" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi +else + echo_skipped +fi + + +# - Set Permissions on log data directory +# - +echo "" >> $log_file +echo "# - Change permissions on '${WEB_BASE_DIR}/logs'" >> $log_file +echo "# -" >> $log_file +echononl "Change permissions on '${WEB_BASE_DIR}/logs'.." + +echo "chown \"${HTTP_USER}\":\"${HTTP_GROUP}\" \"${WEB_BASE_DIR}/logs\"" >> $log_file +chown "${HTTP_USER}":"${HTTP_GROUP}" "${WEB_BASE_DIR}/logs" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + + 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 ny user." +fi + + +# ----- +# - Base Installation of nextcloud +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mBase Installation of nextcloud..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Base Installation of nextcloud" >> $log_file +echo "# -----" >> $log_file + +# - Synchronisiere neues Installationsverzeichnis mit +# - den extrahierten Dateien +# - +echo "" >> $log_file +echo "# - Sync (new) nextlcoud to '${INSTALL_DIR}''" >> $log_file +echo "# -" >> $log_file +echononl "Sync (new) nextlcoud to '${INSTALL_DIR}'.." + +echo "rsync -a \"${SRC_BASE_DIR}/nextcloud/\" \"${INSTALL_DIR}/\"" >> $log_file +rsync -a "${SRC_BASE_DIR}/nextcloud/" "${INSTALL_DIR}/" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +echo "" >> $log_file +echo "# - Set actual date on directory '${INSTALL_DIR}'" >> $log_file +echo "# -" >> $log_file +echononl "Set actual date on directory '${INSTALL_DIR}'.." + +echo "touch -t \"$(date +%Y%m%d%H%M.%S)\" \"${INSTALL_DIR}\"" >> $log_file +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 "For more informations see log output at '$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 ny user." +fi + + +# - Set Permissions on new install directory +# - +echo "" >> $log_file +echo "# - Change permissions on '${INSTALL_DIR}'" >> $log_file +echo "# -" >> $log_file +echononl "Change permissions on '${INSTALL_DIR}'.." + +echo "chown -R ${HTTP_USER}:${HTTP_GROUP} \"${INSTALL_DIR}\"" >> $log_file +chown -R "${HTTP_USER}":"${HTTP_GROUP}" "${INSTALL_DIR}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Set Permissions on new data directory +# - +echo "" >> $log_file +echo "# - Change permissions on '${DATA_DIR}'" >> $log_file +echo "# -" >> $log_file +echononl "Change permissions on '${DATA_DIR}'.." + +echo "chown -R \"${HTTP_USER}\":\"${HTTP_GROUP}\" \"${DATA_DIR}\"" >> $log_file +chown -R "${HTTP_USER}":"${HTTP_GROUP}" "${DATA_DIR}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + + +# - Delete symlink for old data directory +# - +echononl "Delete symlink '${WEB_BASE_DIR}/data' if exists.." +if [[ -h "${WEB_BASE_DIR}/data" ]]; then + + echo "" >> $log_file + echo "# - Delete symlink '${WEB_BASE_DIR}/data'" >> $log_file + echo "# -" >> $log_file + + echo "rm \"${WEB_BASE_DIR}/data\"" >> $log_file + rm "${WEB_BASE_DIR}/data" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi +else + echo_skipped +fi + + +if [[ -f "${WEB_BASE_DIR}/data" ]] || [[ -d "${WEB_BASE_DIR}/data" ]] ; then + warn "File or Directory '${WEB_BASE_DIR}/data' exists." + + echo "" >> $log_file + echo "# - Backup directory '${WEB_BASE_DIR}/data'" >> $log_file + echo "# -" >> $log_file + echononl "Backup directory '${WEB_BASE_DIR}/data'.." + + echo "mv \"${WEB_BASE_DIR}/data\" \"${WEB_BASE_DIR}/data.$backup_date\"" >> $log_file + mv "${WEB_BASE_DIR}/data" "${WEB_BASE_DIR}/data.$backup_date" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi +else + echo_skipped +fi + + +# - Set symlink for new data directory +# - +echo "" >> $log_file +echo "# - Set symlink for new data dir 'data-${VERSION}'" >> $log_file +echo "# -" >> $log_file +echononl "Set symlink for new data dir 'data-${VERSION}'.." + +echo "\"ln -s data-${VERSION}\" \"${WEB_BASE_DIR}/data\"" >> $log_file +ln -s "data-${VERSION}" "${WEB_BASE_DIR}/data" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Delete symlink for old installation directory +# - +echononl "Delete symlink '${WEB_BASE_DIR}/nextcloud' if exists.." +if [[ -h "${WEB_BASE_DIR}/nextcloud" ]]; then + + echo "" >> $log_file + echo "# - Delete symlink '${WEB_BASE_DIR}/nextcloud'" >> $log_file + echo "# -" >> $log_file + + echo "rm \"${WEB_BASE_DIR}/nextcloud\"" >> $log_file + rm "${WEB_BASE_DIR}/nextcloud" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi +else + echo_skipped +fi + +if [[ -f "${WEB_BASE_DIR}/nextcloud" ]] || [[ -d "${WEB_BASE_DIR}/nextcloud" ]] ; then + warn "File or Directory '${WEB_BASE_DIR}/nextcloud' exists." + + echo "" >> $log_file + echo "# - Backup directory '${WEB_BASE_DIR}/nextcloud'" >> $log_file + echo "# -" >> $log_file + echononl "Backup directory '${WEB_BASE_DIR}/nextcloud'.." + + echo "mv \"${WEB_BASE_DIR}/nextcloud\" \"${WEB_BASE_DIR}/nextcloud.$backup_date\"" >> $log_file + mv "${WEB_BASE_DIR}/nextcloud" "${WEB_BASE_DIR}/nextcloud.$backup_date" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi +else + echo_skipped +fi + + +# - Set symlink for new installation directory +# - +echo "" >> $log_file +echo "# - Set symlink for new installation dir 'nextcloud-${VERSION}'" >> $log_file +echo "# -" >> $log_file +echononl "Set symlink for new installation dir 'nextcloud-${VERSION}'.." + +echo "\"ln -s nextcloud-${VERSION}\" \"${WEB_BASE_DIR}/nextcloud\"" >> $log_file +ln -s "nextcloud-${VERSION}" "${WEB_BASE_DIR}/nextcloud" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Delete symlink for 'htdocs' directory +# - +echononl "Delete symlink '${WEB_BASE_DIR}/htdocs' if exists.." +if [[ -h "${WEB_BASE_DIR}/htdocs" ]]; then + + echo "" >> $log_file + echo "# - Delete symlink '${WEB_BASE_DIR}/htdocs'" >> $log_file + echo "# -" >> $log_file + + echo "rm \"${WEB_BASE_DIR}/htdocs\"" >> $log_file + rm "${WEB_BASE_DIR}/htdocs" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi +else + echo_skipped +fi + +if [[ -f "${WEB_BASE_DIR}/htdocs" ]] || [[ -d "${WEB_BASE_DIR}/htdocs" ]] ; then + warn "File or Directory '${WEB_BASE_DIR}/htdocs' exists." + + echo "" >> $log_file + echo "# - Backup directory '${WEB_BASE_DIR}/htdocs'" >> $log_file + echo "# -" >> $log_file + echononl "Backup directory '${WEB_BASE_DIR}/htdocs'.." + + echo "mv \"${WEB_BASE_DIR}/htdocs\" \"${WEB_BASE_DIR}/htdocs.$backup_date\"" >> $log_file + mv "${WEB_BASE_DIR}/htdocs" "${WEB_BASE_DIR}/htdocs.$backup_date" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi +else + echo_skipped +fi + + +# - Set symlink for htdocs directory +# - +echo "" >> $log_file +echo "# - Set symlink for htdocs directory" >> $log_file +echo "# -" >> $log_file +echononl "Set symlink for htdocs directory.." + +echo "\"ln -s nextcloud\" \"${WEB_BASE_DIR}/htdocs\"" >> $log_file +ln -s "nextcloud" "${WEB_BASE_DIR}/htdocs" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + + +# ----- +# - Configuration tasks on the new Nextcloud Installation +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mConfiguration tasks on the new Nextcloud Installation..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Configuration tasks on the new Nextcloud Installation" >> $log_file +echo "# -----" >> $log_file + +# - Create base configuration +# - +echo "" >> $log_file +echo "# - Create base configuration (file 'config/config.php')" >> $log_file +echo "# -" >> $log_file +echononl "Create base configuration (file 'config/config.php')" + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" maintenance:install \\ + --database="${DATABASE_TYPE}" \\ + --database-name="${DATABASE_NAME}" \\ + --database-host="${DATABASE_HOST}" \\ + --database-user="${DATABASE_USER}" \\ + --database-pass="${DATABASE_PASS}" \\ + --database-table-prefix="" \\ + --admin-user="${ADMIN_USER}" --admin-pass="${ADMIN_PASS}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" maintenance:install \ + --database="${DATABASE_TYPE}" \ + --database-name="${DATABASE_NAME}" \ + --database-host="${DATABASE_HOST}" \ + --database-user="${DATABASE_USER}" \ + --database-pass="${DATABASE_PASS}" \ + --database-table-prefix="" \ + --admin-user="${ADMIN_USER}" --admin-pass="${ADMIN_PASS}" \ + --data-dir="${DATA_DIR}">> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +blank_line + +# - Some columns in the database are missing a conversion to big int. Due to the +# - fact that changing column types on big tables could take some time they were +# - not changed automatically. By running 'occ db:convert-filecache-bigint' those +# - pending changes could be applied manually. This operation needs to be made +# - while the instance is offline. +# - +# - For further details read the documentation page about this. +# - +# - filecache.mtime +# - filecache.storage_mtime +# - +echo "" >> $log_file +echo "# - Convert some database columns to 'big int'" >> $log_file +echo "# -" >> $log_file +echononl "Convert some database columns to 'big int'" + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" db:convert-filecache-bigint" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" -n db:convert-filecache-bigint >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +blank_line + + +# - Activate and Enable (default) encryption module +# - +echo "" >> $log_file +echo "# - Eabable the (default) encryption module" >> $log_file +echo "# -" >> $log_file +echononl "Eabable the (default) encryption module.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:enable encryption" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable encryption >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# - Enable encryption" >> $log_file +echo "# -" >> $log_file +echononl "Enable encryption.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" encryption:enable" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" encryption:enable >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + + + +# - Adjust 'trusted_domains' +# - +_parameter="overwrite.cli.url" +_value="${WEBSITE}" +_type="string" +echo "" >> $log_file +echo "# - Add '${WEBSITE}' to trusted domains" >> $log_file +echo "# -" >> $log_file +echononl "Add '${WEBSITE}' to trusted domains.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set trusted_domains 1 \\ + --value="${_value} --type="${_type}"" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set trusted_domains 1 \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust 'overwrite.cli.url' +# - +_parameter="overwrite.cli.url" +_value="${WEBSITE}" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value} --type="${_type}"" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +## - # - Adjust 'trashbin_retention_obligation' +## - # - +## - _parameter="trashbin_retention_obligation" +## - _value="auto, 7" +## - _type="string" +## - echo "" >> $log_file +## - echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +## - echo "# -" >> $log_file +## - echononl "Adjust configuration parameter '$_parameter'.." +## - +## - cat <> $log_file +## - sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ +## - --value="https://${_value}" --type="${string}" +## - EOF +## - sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ +## - --value="${_value}" --type="${string}" >> $log_file 2>&1 +## - +## - if [[ $? -eq 0 ]]; then +## - echo_ok +## - else +## - echo_failed +## - error "For more informations see log output at '$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 ny user." +## - fi + + +# - Adjust 'logtimezone' +# - +_parameter="logtimezone" +_value="Europe/Berlin" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="https://${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust parameter 'log_type' +# - +# - Defaults to none +# - +_parameter="log_type" +_value="file" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust parameter 'logfile' +# - +# - Defaults to none +# - +_parameter="logfile" +_value="${WEB_BASE_DIR}/logs/cloud.log" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust parameter 'loglevel' +# - +# - Defaults to none +# - +_parameter="loglevel" +_value=4 +_type="integer" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +blank_line + + +# - Adjust 'filelocking.enabled' +# - +# - Prevents concurrent processes from accessing the same files at the same time. +# - Can help prevent side effects that would be caused by concurrent operations. +# - Mainly relevant for very large installations with many users working with +# - shared files. +# - +# - Defaults to true +# - +_parameter="filelocking.enabled" +_value="true" +_type="boolean" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust 'memcache.locking' +# - +# - Memory caching backend for file locking +# - +# - Defaults to none +# - +_parameter="memcache.locking" +_value="\\OC\\Memcache\\Redis" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust 'memcache.local' +# - +# - Memory caching backend for locally stored data +# - +# - Defaults to none +# - +_parameter="memcache.local" +_value="\\OC\\Memcache\\APCu" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust 'memcache.distributed' +# - +# - Memory caching backend for locally stored data +# - +# - Defaults to none +# - +_parameter="memcache.distributed" +_value="\\OC\\Memcache\\Redis" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust parameter 'redis' 'port' +# - +# - Connection details for redis to use for memory caching +# - +# - Defaults to none +# - +_parameter="redis" +_array_index="port" +_value=0 +_type="integer" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter' '$_array_index'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter' '$_array_index'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" "$_array_index" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" "$_array_index" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust parameter 'redis' 'host' +# - +# - Connection details for redis to use for memory caching +# - +# - Defaults to none +# - +_parameter="redis" +_array_index="host" +_value="/var/run/redis/redis.sock" +_type="string" +echo "" >> $log_file +echo "# - Adjust configuration parameter '$_parameter' '$_array_index'" >> $log_file +echo "# -" >> $log_file +echononl "Adjust configuration parameter '$_parameter' '$_array_index'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" "$_array_index" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" "$_array_index" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +# - Adjust parameter 'redis' 'timeout' +# - +# - Connection details for redis to use for memory caching +# - +# - Defaults to none +# - +_parameter="redis" +_array_index="timeout" +_value=0 +_type="integer" +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Adjust configuration parameter '$_parameter' '$_array_index'" >> $log_file +echononl "Adjust configuration parameter '$_parameter' '$_array_index'.." + +cat <> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" "$_array_index" \\ + --value="${_value}" --type="${_type}" +EOF +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:system:set "$_parameter" "$_array_index" \ + --value="${_value}" --type="${_type}" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +blank_line + + +echo "" >> $log_file +echo "# - Set background jobs to 'Cron'" >> $log_file +echo "# -" >> $log_file +echononl "Set background jobs to 'Cron'" + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" background:cron" >> $log_file 2>&1 +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" background:cron >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# - Create cronjob for nextcloud instance '${WEBSITE}'" >> $log_file +echo "# -" >> $log_file +echononl "Create cronjob for nextcloud instance '${WEBSITE}'" + +if [[ ! -f "$_backup_crontab_file" ]]; then + crontab -l > "$_backup_crontab_file" +fi + +if ! grep -q -E "${WEB_BASE_DIR}/htdocs/cron.php" "$_backup_crontab_file" 2> /dev/null ; then + echo "" >> "$_backup_crontab_file" + echo "# - Background job for nextcloud instance '${WEBSITE}'" >> "$_backup_crontab_file" + echo "# -" >> "$_backup_crontab_file" + echo "*/15 * * * * sudo -u \"$HTTP_USER\" /usr/local/php/bin/php -f ${WEB_BASE_DIR}/htdocs/cron.php" >> "$_backup_crontab_file" + + echo_ok +else + echo_skipped +fi + + + + +# ----- +# - Install/Enable some more nextcloud apps +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mInstall/Enable some more nextcloud apps..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Install/Enable some more nextcloud apps" >> $log_file +echo "# -----" >> $log_file + + +# - Install and enable nextcloud app 'calendar' +# - +_app="calendar" +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Install nextcloud app '$_app'" >> $log_file +echononl "Install nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:install \"$_app\"" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Eanable nextcloud app '$_app'" >> $log_file +echononl "Eanable nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:enable \"$_app\"" >> $log_file +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 "For more informations see log output at '$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 ny user." +fi + + +blank_line + + +# - Install and enable nextcloud app 'contacts' +# - +_app="contacts" +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Install nextcloud app '$_app'" >> $log_file +echononl "Install nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:install \"$_app\"" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Eanable nextcloud app '$_app'" >> $log_file +echononl "Eanable nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:enable \"$_app\"" >> $log_file +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 "For more informations see log output at '$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 ny user." +fi + + +blank_line + + +# - Install and enable nextcloud app 'notes' +# - +_app="notes" +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Install nextcloud app '$_app'" >> $log_file +echononl "Install nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:install \"$_app\"" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Eanable nextcloud app '$_app'" >> $log_file +echononl "Eanable nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:enable \"$_app\"" >> $log_file +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 "For more informations see log output at '$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 ny user." +fi + + +blank_line + + +# - Install and enable nextcloud app 'tasks' +# - +_app="tasks" +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Install nextcloud app '$_app'" >> $log_file +echononl "Install nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:install \"$_app\"" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Eanable nextcloud app '$_app'" >> $log_file +echononl "Eanable nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:enable \"$_app\"" >> $log_file +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 "For more informations see log output at '$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 ny user." +fi + + +blank_line + + +# - Install and enable nextcloud app 'richdocuments' +# - +_app="richdocuments" +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Install nextcloud app '$_app'" >> $log_file +echononl "Install nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:install \"$_app\"" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Eanable nextcloud app '$_app'" >> $log_file +echononl "Eanable nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:enable \"$_app\"" >> $log_file +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 "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Configure nextcloud app '$_app'" >> $log_file +echononl "Configure nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" config:app:set richdocuments wopi_url --value=\"https://co-01.oopen.de/\"" >> $log_file + +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:app:set richdocuments wopi_url --value="https://co-01.oopen.de/" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + + +blank_line + + +# - Install and enable nextcloud app 'bruteforcesettings' +# - +_app="bruteforcesettings" +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Install nextcloud app '$_app'" >> $log_file +echononl "Install nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:install \"$_app\"" >> $log_file +sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" >> $log_file 2>&1 + +if [[ $? -eq 0 ]]; then + echo_ok +else + echo_failed + error "For more informations see log output at '$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 ny user." +fi + +echo "" >> $log_file +echo "# -" >> $log_file +echo "# - Eanable nextcloud app '$_app'" >> $log_file +echononl "Eanable nextcloud app '$_app'.." + +echo "sudo -u \"$HTTP_USER\" \"$php_binary\" \"${INSTALL_DIR}/occ\" app:enable \"$_app\"" >> $log_file +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 "For more informations see log output at '$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 ny user." +fi + + + +# ----- +# - Doing some post-installation tasks +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mDoing some post-installation tasks..\033[m" +echo "" + +echo "" >> $log_file +echo "" >> $log_file +echo "# -----" >> $log_file +echo "# - Doing some post-installation tasks" >> $log_file +echo "# -----" >> $log_file + + +echo "" >> $log_file +echo "# - Restart PHP engine" >> $log_file +echo "# -" >> $log_file +echononl "Restart PHP engine.." + +if [[ "$PHP_ENGINE" = "FPM" ]]; then + if $systemd_supported ; then + + echo "systemctl restart \"php-${PHP_VERSION}-fpm\"" >> $log_file + systemctl restart "php-${PHP_VERSION}-fpm" >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi + else + + echo "/etc/init.d/php-${PHP_VERSION}-fpm restart" >> $log_file + /etc/init.d/php-${PHP_VERSION}-fpm restart >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi + fi +else + echo_skipped +fi + +# - Start Apache Webserver +# - +echononl "Start Apache Webserver.." +if $IS_HTTPD_RUNNING ; then + + echo "" >> $log_file + echo "# - Restart Apache Webserver" >> $log_file + echo "# -" >> $log_file + + if $systemd_supported ; then + + echo "systemctl start apache2" >> $log_file + systemctl start apache2 >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi + else + + echo "/etc/init.d/apache2 start" >> $log_file + /etc/init.d/apache2 start >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "For more informations see log output at '$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 ny user." + fi + fi +else + echo_skipped + warn "The webserver was not running, so it will be keept down!" +fi + + +# - Flush and restart redis service +# - +_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 + + echo "" >> $log_file + echo "# - Flush redis cache" >> $log_file + echo "# -" >> $log_file + + echo "$_redis_cli_bin flushall" >> $log_file + $_redis_cli_bin flushall >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + + echo "" >> $log_file + echo "# - Restart redis service" >> $log_file + echo "# -" >> $log_file + echononl "Restart redis service.." + + if $systemd_supported ; then + + echo "systemctl restart redis-server" >> $log_file + systemctl restart redis-server >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fi + else + + echo "/etc/init.d/redis-server restart" >> $log_file + /etc/init.d/redis-server restart >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fi + fi + + else + echo_failed + fi +else + echo_skipped + warn "No 'redis' services found at '$(hostname -f)'!" +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