diff --git a/conf/hostname.conf.sample b/conf/hostname.conf.sample index 8eee749..f3916e1 100644 --- a/conf/hostname.conf.sample +++ b/conf/hostname.conf.sample @@ -17,6 +17,15 @@ WEBSITE="" #THIRD_PARTY_APPS="calendar contacts notes richdocuments" +# - Extra Apps +# - +# - Possible values are app-names like 'calendar' , 'contacts' , .. +# - +# - a blank separated list enclosed in brackets +# - +#EXTRA_APPS="(calendar contacts deck notes richdocuments tasks)" + + # - Source directory for tar archives of Nextcloud # - # - Defaults to '/usr/local/src/nextcloud' diff --git a/install_apps.sh b/install_apps.sh new file mode 100755 index 0000000..6c78905 --- /dev/null +++ b/install_apps.sh @@ -0,0 +1,812 @@ +#!/usr/bin/env bash + +CUR_IFS=$IFS + +script_name="$(basename $(realpath $0))" +script_dir="$(dirname $(realpath $0))" + +conf_dir="${script_dir}/conf" +snippet_dir="${script_dir}/snippets" + +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 .." + + 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 "" +} + +## - 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 +} + +ensure_nc_app() { + + local APP_ID="$1" + + echononl " Install nextcloud app '$APP_ID'.." + + # 1. Prüfen, ob die App überhaupt installiert ist + # + # ${OCC_CMD[@]} expandiert jedes Element des Arrays als eigenes Argument. + # + if ! "${OCC_CMD[@]}" app:list 2>/dev/null | grep -q " - ${APP_ID}:"; then + + "${OCC_CMD[@]}" app:install "$APP_ID" > $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + + echo -e "\ncommand was: ${OCC_CMD[@]} app:install \"${APP_ID}\"" + + 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 + echo_skipped + fi + + echononl " Enable App '${APP_ID}'.." + # 2. Prüfen, ob die App aktiviert ist (nur 'Enabled'-Block betrachten) + local ENABLED_BLOCK + ENABLED_BLOCK="$("${OCC_CMD[@]}" app:list 2>/dev/null \ + | awk 'BEGIN{flag=0} /Enabled:/ {flag=1; next} /Disabled:/ {flag=0} flag')" + + if echo "$ENABLED_BLOCK" | grep -q " - ${APP_ID}:"; then + echo_skipped + else + "${OCC_CMD[@]}" app:enable "${APP_ID}" > $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + + echo -e "\ncommand was: ${OCC_CMD[@]} app:install \"${APP_ID}\"" + + 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 + +} + + + +# ---------- +# - 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) +#done < <(find "${conf_dir}" -maxdepth 1 -type f -name "create_missing_indices_*.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[*]}")) + + +# - Reset IFS +# - +IFS=$CUR_IFS + + +# ============= +# --- 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 "Add missing columns" +echo -e "\033[32m-----\033[m" + +# Which cloud instance (website) would you like to update +# +source ${snippet_dir}/get-cloud-instance-to-update.sh + + +# - Reset IFS +# - +IFS=$CUR_IFS + + +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" +DEFAULT_PHP_ENGINE="FPM" + + +if [[ -z ${WEBSITE} ]] ; then + WEBSITE="$DEFAULT_WEBSITE" +fi + +DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE" + +[[ -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 + +if [[ -z "${EXTRA_APPS}" ]]; then + fatal "No list of extra apps (parameter EXTRA_APPS) found!" +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 + +NGINX_IS_ENABLED=false +APACHE2_IS_ENABLED=false + +# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP.. +# +source ${snippet_dir}/get-webservice-environment.sh + +# Check PHP Version +# +source ${snippet_dir}/get-php-major-version.sh + + +# Get full qualified PHP command +# +source ${snippet_dir}/get-path-of-php-command.sh + + +CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" +CURRENT_VERSION="$(basename $CURRENT_INSTALL_DIR | cut -d"-" -f2)" + +# OCC_CMD Kommando als Array definieren. +# +# Ausführen des Kommandos: +# +# ${OCC_CMD[@]} +# +# ${OCC_CMD[@]} ist die einzig sichere Art, ein Array als Kommando aufzurufen. Jedes Element +# des Arrays als eigenes Argument. +# +OCC_CMD=(sudo -u "$HTTP_USER" "$PHP_BIN" -f "${CURRENT_INSTALL_DIR}/occ") + +echo "" +echo -e "\033[1;32mStarting Script $script_name for \033[1;37m${WEBSITE}\033[m" +echo "" +echo -e " Website to update....................: $WEBSITE" +echo "" +echo -e " Nextcloud version....................: $CURRENT_VERSION" +echo "" +echo -e " Extra apps...........................: ${EXTRA_APPS[@]}" +echo "" +echo -e " Web base directory...................: $WEB_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 " PHP Command..........................: $PHP_BIN" + +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 "" + +# - 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 $APACHE2_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl stop apache2 + 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 stop + 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 +else + echo_skipped +fi + +# - Stop Nginx Webservice +# - +echo "" +echononl " Stop Nginx Webserver.." +if $NGINX_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl stop nginx + 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 stop + 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 +fi + +echo "" + +# - Backup Database +# - +echononl " Backup MySQL database '$DATABASE_NAME'.." +if [[ "$DATABASE_TYPE" = 'mysql' ]]; then + mysqldump $MYSQL_CREDENTIALS --max_allowed_packet=128M --single-transaction $DATABASE_NAME > \ + ${WEB_BASE_DIR}/${DATABASE_NAME}-v${CURRENT_VERSION}.${backup_date}.sql 2> $log_file + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + + blank_line + echo -e "\t[ \033[33m\033[1mCommand\033[m ]: \033[37m\033[1mmysqldump $MYSQL_CREDENTIALS \\ +\t --max_allowed_packet=128M --single-transaction $DATABASE_NAME > \\ +\t ${WEB_BASE_DIR}/${DATABASE_NAME}-v${PRIOR_VERSION}.${backup_date}.sql\033[m" + + 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 "Abbruch durch User" + blank_line + + 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${CURRENT_VERSION}.${backup_date}.sql 2> $log_file + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fatal "$(cat $log_file)" + fi +fi + +echo + + +# ----- +# - Main part of the script +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mMain part of the script\033[m" +echo "" + +declare -i index=1 +for APP in "${EXTRA_APPS[@]}"; do + [[ ${index} -gt 1 ]] && blank_line + ensure_nc_app "$APP" + (( index++ )) +done + + + +# ----- +# - 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 $APACHE2_IS_ENABLED ; then + 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 +else + echo_skipped +fi + + +# - Start NGINX Webservise +# - +echo "" +echononl " Start Nginx Webserver.." +if $NGINX_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; 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 +else + echo_skipped +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 diff --git a/remove-app_api.sh b/remove-app_api.sh new file mode 100755 index 0000000..13d8d9b --- /dev/null +++ b/remove-app_api.sh @@ -0,0 +1,750 @@ +#!/usr/bin/env bash + +CUR_IFS=$IFS + +script_name="$(basename $(realpath $0))" +script_dir="$(dirname $(realpath $0))" + +conf_dir="${script_dir}/conf" +snippet_dir="${script_dir}/snippets" + +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 .." + + 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 "" +} + +## - 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) +#done < <(find "${conf_dir}" -maxdepth 1 -type f -name "create_missing_indices_*.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[*]}")) + + +# - Reset IFS +# - +IFS=$CUR_IFS + + +# ============= +# --- 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 "Add missing columns" +echo -e "\033[32m-----\033[m" + +# Which cloud instance (website) would you like to update +# +source ${snippet_dir}/get-cloud-instance-to-update.sh + + +# - Reset IFS +# - +IFS=$CUR_IFS + + +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" +DEFAULT_PHP_ENGINE="FPM" + + +if [[ -z ${WEBSITE} ]] ; then + WEBSITE="$DEFAULT_WEBSITE" +fi + +DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE" + +[[ -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 + +NGINX_IS_ENABLED=false +APACHE2_IS_ENABLED=false + +# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP.. +# +source ${snippet_dir}/get-webservice-environment.sh + +# Check PHP Version +# +source ${snippet_dir}/get-php-major-version.sh + + +# Get full qualified PHP command +# +source ${snippet_dir}/get-path-of-php-command.sh + + +CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)" +CURRENT_VERSION="$(basename $CURRENT_INSTALL_DIR | cut -d"-" -f2)" + +echo "" +echo -e "\033[1;32mStarting Script $script_name for \033[1;37m${WEBSITE}\033[m" +echo "" +echo -e " Website to update....................: $WEBSITE" +echo "" +echo -e " Nextcloud version....................: $CURRENT_VERSION" +echo "" +echo -e " Web base directory...................: $WEB_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 " PHP Command..........................: $PHP_BIN" + +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 "" + +# - 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 $APACHE2_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl stop apache2 + 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 stop + 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 +else + echo_skipped +fi + +# - Stop Nginx Webservice +# - +echo "" +echononl " Stop Nginx Webserver.." +if $NGINX_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; then + if $SYSTEMD_EXISTS ; then + systemctl stop nginx + 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 stop + 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 +fi + +echo "" + +# - Backup Database +# - +echononl " Backup MySQL database '$DATABASE_NAME'.." +if [[ "$DATABASE_TYPE" = 'mysql' ]]; then + mysqldump $MYSQL_CREDENTIALS --max_allowed_packet=128M --single-transaction $DATABASE_NAME > \ + ${WEB_BASE_DIR}/${DATABASE_NAME}-v${CURRENT_VERSION}.${backup_date}.sql 2> $log_file + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + + blank_line + echo -e "\t[ \033[33m\033[1mCommand\033[m ]: \033[37m\033[1mmysqldump $MYSQL_CREDENTIALS \\ +\t --max_allowed_packet=128M --single-transaction $DATABASE_NAME > \\ +\t ${WEB_BASE_DIR}/${DATABASE_NAME}-v${PRIOR_VERSION}.${backup_date}.sql\033[m" + + 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 "Abbruch durch User" + blank_line + + 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${CURRENT_VERSION}.${backup_date}.sql 2> $log_file + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fatal "$(cat $log_file)" + fi +fi + +echo + + +# ----- +# - Main part of the script +# ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mMain part of the script\033[m" +echo "" + + +echononl " Check if app_api has registered apps .." +EX_APPS_COUNT=$( + sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app_api:app:list 2>/dev/null \ + | grep -v "No registered apps" \ + | grep -E '^[[:space:]]*[a-zA-Z0-9_-]+[[:space:]]' \ + | wc -l +) + +DAEMONS_COUNT=$( + sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app_api:daemon:list 2>/dev/null \ + | grep -v "No registered daemon configs" \ + | grep -E '^[[:space:]]*[a-zA-Z0-9_-]+[[:space:]]' \ + | wc -l +) +echo_done + + +echononl " Disable 'app_api'.." +if [ "${EX_APPS_COUNT}" -eq 0 ] && [ "${DAEMONS_COUNT}" -eq 0 ]; then + + sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:disable app_api > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fatal "$(cat $log_file)" + fi +else + echo_skipped +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 $APACHE2_IS_ENABLED ; then + 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 +else + echo_skipped +fi + + +# - Start NGINX Webservise +# - +echo "" +echononl " Start Nginx Webserver.." +if $NGINX_IS_ENABLED ; then + if $IS_HTTPD_RUNNING ; 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 +else + echo_skipped +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 diff --git a/restore_nextcloud.sh b/restore_nextcloud.sh index 21226ae..c58b058 100755 --- a/restore_nextcloud.sh +++ b/restore_nextcloud.sh @@ -609,7 +609,6 @@ if [[ "$DATABASE_TYPE" = 'mysql' ]]; then mysql $MYSQL_CREDENTIALS $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 @@ -617,30 +616,50 @@ if [[ "$DATABASE_TYPE" = 'mysql' ]]; then echo_failed error "\n\n$(cat $log_file)" - if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then - echo "" - echo "Tables NOT deleted:" - for _table in "${_tables_not_deleted[@]}" ; do - echo " $_table" - done - echo "" - fi - - - 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 + _tables_not_deleted=() + _failed=false + _TABLES="$(mysql $MYSQL_CREDENTIALS $DATABASE_NAME -N -s -e "show tables" 2> $log_file)" + echononl " Try again dropping tables from database '$DATABASE_NAME' .." + for _table in $_TABLES ; do + mysql $MYSQL_CREDENTIALS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $log_file 2>&1 + if [[ $? -ne 0 ]] ; then + _failed=true + _tables_not_deleted+=("$_table") + fi done - [[ $OK = "yes" ]] || fatal "Abbruch durch User" - blank_line + if $_failed ; then + + echo_failed + error "\n\n$(cat $log_file)" + + if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then + echo "" + echo "Tables NOT deleted:" + for _table in "${_tables_not_deleted[@]}" ; do + echo " $_table" + done + echo "" + fi + + + 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" + blank_line else echo_ok fi + else + echo_ok + fi + fi fi diff --git a/update_nextcloud.sh b/update_nextcloud.sh index 0411e85..7b2359e 100755 --- a/update_nextcloud.sh +++ b/update_nextcloud.sh @@ -192,17 +192,87 @@ blank_line() { fi } +ensure_nc_app() { + + local APP_ID="$1" + + echononl " Install nextcloud app '$APP_ID'.." + + # 1. Prüfen, ob die App überhaupt installiert ist + # + # ${OCC_CMD[@]} expandiert jedes Element des Arrays als eigenes Argument. + # + if ! "${OCC_CMD[@]}" app:list 2>/dev/null | grep -q " - ${APP_ID}:"; then + + "${OCC_CMD[@]}" app:install "$APP_ID" > $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + + echo -e "\ncommand was: ${OCC_CMD[@]} app:install \"${APP_ID}\"" + + 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 + echo_skipped + fi + + echononl " Enable App '${APP_ID}'.." + # 2. Prüfen, ob die App aktiviert ist (nur 'Enabled'-Block betrachten) + local ENABLED_BLOCK + ENABLED_BLOCK="$("${OCC_CMD[@]}" app:list 2>/dev/null \ + | awk 'BEGIN{flag=0} /Enabled:/ {flag=1; next} /Disabled:/ {flag=0} flag')" + + if echo "$ENABLED_BLOCK" | grep -q " - ${APP_ID}:"; then + echo_skipped + else + "${OCC_CMD[@]}" app:enable "${APP_ID}" > $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + + echo -e "\ncommand was: ${OCC_CMD[@]} app:install \"${APP_ID}\"" + + 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 + +} # ---------- -# - Jobhandling +# - 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 @@ -226,7 +296,7 @@ IFS=$CUR_IFS # ============= -# --- Some +# --- Some # ============= # - Support systemd ? @@ -363,6 +433,10 @@ if [[ ! -d ${WEB_BASE_DIR} ]] ; then fatal "Web base directory not found (parameter 'WEB_BASE_DIR')" fi +if [[ -z "${EXTRA_APPS}" ]]; then + fatal "No list of extra apps (parameter EXTRA_APPS) found!" +fi + [[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE if [[ "$DATABASE_TYPE" != "postgres" ]] && [[ "$DATABASE_TYPE" != "mysql" ]]; then @@ -413,6 +487,18 @@ DATA_DIR="$(realpath "${WEB_BASE_DIR}/data")" OLD_DATA_DIR="$(dirname "${DATA_DIR}")/data-${PRIOR_VERSION}.${backup_date}" +# OCC_CMD Kommando als Array definieren. +# +# Ausführen des Kommandos: +# +# ${OCC_CMD[@]} +# +# ${OCC_CMD[@]} ist die einzig sichere Art, ein Array als Kommando aufzurufen. Jedes Element +# des Arrays als eigenes Argument. +# +OCC_CMD=(sudo -u "$HTTP_USER" "$PHP_BIN" -f "$INSTALL_DIR/occ") + + #_CURRENT_DATA_DIR="$(grep datadirectory "${CURRENT_INSTALL_DIR}/config/config.php" 2> /dev/null \ @@ -451,7 +537,7 @@ echo "" echo -e " Databse name.........................: $DATABASE_NAME" echo -e " Database type........................: $DATABASE_TYPE" #echo "" -#echo -e " Install ColaboraOnline App...........: $INSTALL_COLABORA_ONLINE_APP" +#echo -e " Install ColaboraOnline App...........: $INSTALL_COLABORA_ONLINE_APP" echo "" if [[ "$DATABASE_TYPE" = "mysql" ]] ; then echo -e " Mysql Credentials....................: $MYSQL_CREDENTIALS" @@ -460,7 +546,7 @@ echo "" if [[ "$VERSION" = "$PRIOR_VERSION" ]] ; then warn "The new version (\033[1m${VERSION}\033[m) is the same as the current version (\033[1m${PRIOR_VERSION}\033[m). - + \033[1mYou have to reinstall some apps manually!\033[m" fi @@ -821,8 +907,8 @@ else [[ $OK = "yes" ]] || fatal "Interrupted by user." fi -# - Synchronisiere neues Installationsverzeichnis mit -# - den extrahierten Dateien +# - 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 @@ -941,7 +1027,7 @@ blank_line # - echo "" echo -e " Update Nextcloud\n" -su -c"${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ upgrade" -s /bin/bash $HTTP_USER +su -c"${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ upgrade" -s /bin/bash $HTTP_USER echo "" if [[ $? -eq 0 ]]; then info "Updating nextcloud core was successfully.." @@ -1012,7 +1098,7 @@ if $(systemctl list-units --full -all | grep -Fq "notify_push") ; then fi - echononl " Enable Nextcloud App 'notify_pushi'.." + echononl " Enable Nextcloud App 'notify_push'.." if $( sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:list --enabled \ | grep -q notify @@ -1030,7 +1116,7 @@ if $(systemctl list-units --full -all | grep -Fq "notify_push") ; then fi - echononl " Setup Nextcloud App 'notify_pushi'.." + echononl " Setup Nextcloud App 'notify_push'.." script -q -c "sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ notify_push:setup" /dev/null <<< $'\n' \ > $log_file 2>&1 if [[ $? -eq 0 ]]; then @@ -1040,10 +1126,22 @@ if $(systemctl list-units --full -all | grep -Fq "notify_push") ; then fatal "$(cat $log_file)" fi + blank_line + fi -# -# + +# ----- +# - Reinstall estra apps +# ----- + +declare -i index=1 +for APP in "${EXTRA_APPS[@]}"; do + [[ ${index} -gt 1 ]] && blank_line + ensure_nc_app "$APP" + (( index++ )) +done + ## - Install and enable nextcloud app 'calendar' ## - #_app="calendar" @@ -1420,6 +1518,39 @@ echo "" echo -e "\033[37m\033[1mDoing some post-update tasks..\033[m" echo "" +echononl " Check if app_api has registered apps .." +EX_APPS_COUNT=$( + sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app_api:app:list 2>/dev/null \ + | grep -v "No registered apps" \ + | grep -E '^[[:space:]]*[a-zA-Z0-9_-]+[[:space:]]' \ + | wc -l +) + +DAEMONS_COUNT=$( + sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app_api:daemon:list 2>/dev/null \ + | grep -v "No registered daemon configs" \ + | grep -E '^[[:space:]]*[a-zA-Z0-9_-]+[[:space:]]' \ + | wc -l +) +echo_done + + +echononl " Disable 'app_api'.." +if [ "${EX_APPS_COUNT}" -eq 0 ] && [ "${DAEMONS_COUNT}" -eq 0 ]; then + + sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:disable app_api > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + fatal "$(cat $log_file)" + fi +else + echo_skipped +fi + + + # - Add missing columns # - echononl " Add missing columns .."