Compare commits

..

19 Commits

Author SHA1 Message Date
793b1b1e1c update_nextcloud.sh: use realpath for data dirctory. 2025-06-20 22:05:33 +02:00
b6fd1ab6a3 add-new-account.sh: supprt blank sign in account name. 2025-05-02 18:24:48 +02:00
d60a7d5937 update_nextcloud.sh: restart notify_push service if present.. 2025-04-22 17:40:21 +02:00
9346c73f39 A realy smal change on script output. 2025-04-20 02:11:27 +02:00
23edc5828c Add script 'add-new-account.sh'. 2025-04-20 02:07:01 +02:00
73f2f79324 snippets/get-cloud-instance-to-update.sh: a really smal change - remove a blank sign.. 2025-03-30 18:24:15 +02:00
78a10d9169 Add script 'remove-old-nc-installations.sh'. 2025-03-30 18:23:24 +02:00
9893bd4371 restore_nextcloud.sh: some changes in error handling. 2025-03-29 03:06:33 +01:00
00cce38bf1 Add script 'correct-cloud-database-row-format.sh'. 2025-03-28 01:55:32 +01:00
4abff5e4fa update_nextcloud.sh: run 'Migrating the mimetypes' job after update. 2024-10-19 01:43:03 +02:00
6882e48d80 Add 'script occ_migrate_mimetipes.sh'. 2024-08-25 00:35:22 +02:00
ab1256f14b update_nextcloud.sh: some changes in script output. 2024-03-31 03:01:42 +02:00
a9fb3067df update_nextcloud.sh: start the cronjon manually only on demand. 2023-12-23 02:28:46 +01:00
b5a0204dec Some minor changes on script output. 2023-12-18 01:50:28 +01:00
ebdccd5c44 occ_maintenance.sh: some minor changes to the script output. 2023-08-05 00:42:42 +02:00
588eb68502 fix error determin configuration file. 2023-08-04 01:39:40 +02:00
2f8d771420 Merge branch 'master' of https://git.oopen.de/script/nextcloud 2023-08-04 01:28:53 +02:00
bea755c670 occ_maintenance.sh: fix error determin configuration file. 2023-08-04 01:28:23 +02:00
2c37b04ddf Some post installations on update and restore scripts. 2023-08-03 10:43:06 +02:00
13 changed files with 2418 additions and 104 deletions

745
add-new-account.sh Executable file
View File

@ -0,0 +1,745 @@
#!/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
declare -a unsorted_account_arr
declare -a account_arr
declare -a unsorted_group_arr
declare -a group_arr
log_file="$(mktemp)"
backup_date=$(date +%Y-%m-%d-%H%M)
# =============
# --- Some functions
# =============
clean_up() {
if [[ -f "$_backup_crontab_file" ]]; then
echononl "(Re)Install previously saved crontab from '$_backup_crontab_file'.."
crontab $_backup_crontab_file >> $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
# Perform program exit housekeeping
rm -f $log_file
blank_line
exit $1
}
is_number() {
return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1);
# - also possible
# -
#[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1
#return $([[ ! -z "${1##*[!0-9]*}" ]])
}
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
echo_done() {
if $terminal ; then
echo -e "\033[75G[ \033[32mdone\033[m ]"
else
echo " [ done ]"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[75G[ \033[32mok\033[m ]"
else
echo " [ ok ]"
fi
}
echo_warning() {
if $terminal ; then
echo -e "\033[75G[ \033[33m\033[1mwarn\033[m ]"
else
echo " [ warning ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
else
echo ' [ failed! ]'
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[75G[ \033[37mskipped\033[m ]"
else
echo " [ skipped ]"
fi
}
fatal (){
echo ""
echo ""
if $terminal ; then
echo -e "\t[ \033[31m\033[1mFatal\033[m ]: \033[37m\033[1m$*\033[m"
echo ""
echo -e "\t\033[31m\033[1m Script will be interrupted..\033[m\033[m"
else
echo "fatal: $*"
echo "Script will be interrupted.."
fi
clean_up 1
}
error(){
echo ""
if $terminal ; then
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
else
echo "Error: $*"
fi
echo ""
}
warn (){
echo ""
if $terminal ; then
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
else
echo "Warning: $*"
fi
echo ""
}
info (){
echo ""
if $terminal ; then
echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
else
echo "Info: $*"
fi
echo ""
}
detect_os_1 () {
if $(which lsb_release > /dev/null 2>&1) ; then
os_dist="$(lsb_release -i | awk '{print tolower($3)}')"
os_version="$(lsb_release -r | awk '{print tolower($2)}')"
os_codename="$(lsb_release -c | awk '{print tolower($2)}')"
if [[ "$os_dist" = "debian" ]]; then
if $(echo "$os_version" | grep -q '\.') ; then
os_version=$(echo "$os_version" | cut --delimiter='.' -f1)
fi
fi
elif [[ -e "/etc/os-release" ]]; then
. /etc/os-release
os_dist=$ID
os_version=${VERSION_ID}
fi
# remove whitespace from os_dist and os_version
os_dist="${os_dist// /}"
os_version="${os_version// /}"
}
# - Remove leading/trailling whitespaces
# -
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
## - 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
}
random_char() {
local chars="$1"
echo -n "${chars:RANDOM%${#chars}:1}"
}
# Funktion zur Generierung eines zufälligen Strings mit den angegebenen Anforderungen
generate_random_string() {
local length="$1"
# Überprüfen, ob die Länge größer als 8 ist
if [[ "$length" -le 8 ]]; then
echo "Fehler: Die Länge muss größer als 8 Zeichen sein."
return 1
fi
# Zeichenmengen
# not allowed: 0ODl18B
local lower="abcdefghijkmnopqrstuvwxyz"
#local upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local upper="ACEFGHIJKLMNPQRSTUVWXYZ"
#local digits="0123456789"
local digits="2345679"
#local special="!@#$%^&*()_+-=[]{}|;:,.<>?/"
local special="__+---///...."
# Generiere mindestens ein Zeichen aus jeder Kategorie
local random_string=$(random_char "$lower")
random_string+=$(random_char "$upper")
random_string+=$(random_char "$digits")
random_string+=$(random_char "$special")
random_string+=$(random_char "$special")
# Fülle den Rest der Zeichenkette mit zufälligen Zeichen aus allen Kategorien
local all_chars="$lower$upper$digits$special"
for (( i=${#random_string}; i<length; i++ )); do
random_string+=$(random_char "$all_chars")
done
# Mische die Zeichenkette, um die Reihenfolge der Zeichen zufällig zu machen
random_string=$(echo "$random_string" | fold -w1 | shuf | tr -d '\n')
# Ausgabe des generierten Strings
echo "$random_string"
}
validate_email() {
local email=$1
local pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
if [[ $email =~ $pattern ]]; then
return 0 # Erfolg - E-Mail ist gültig
else
return 1 # Fehler - E-Mail ist ungültig
fi
}
blank_line() {
if $terminal ; then
echo ""
fi
}
# ----------
# - Jobhandling
# ----------
# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM
# -
trap clean_up SIGHUP SIGINT SIGTERM
## -
while IFS='' read -r -d '' _conf_file ; do
source $_conf_file
if [[ -n "$WEBSITE" ]] ; then
unsorted_website_arr+=("${WEBSITE}:$_conf_file")
fi
WEBSITE=""
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
if [[ ${#unsorted_website_arr} -eq 0 ]]; then
fatal "No configuration files found in '${script_dir}/conf' or no website configured!"
fi
# - Sort array
# -
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
# - 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 -e "Add a new User to NC - \033[1mIts possible to assign existing group(s)\033[m"
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
fatal "No website given (parameter '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_DATA_DIR=`realpath ${WEB_BASE_DIR}/data`
CURRENT_VERSION=`basename $CURRENT_INSTALL_DIR | cut -d"-" -f2`
blank_line
echononl " Get list of current accounts.."
# Methode 1: mapfile (empfohlen)
#
mapfile -t unsorted_account_arr < <(su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ user:list" -s /bin/bash $HTTP_USER 2> ${log_file} | awk -F'[:[:space:]]+' '{print $3}' 2>> ${log_file} )
# Oder Methode 2: while-Schleife
#
#while IFS= read -r line; do
# unsorted_account_arr+=("$(echo "$line" | awk -F'[:[:space:]]+' '{print $3}' 2>> ${log_file})")
#done <<< "$(su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ user:list" -s /bin/bash $HTTP_USER 2> ${log_file})"
if [[ $? -gt 0 ]] || [[ -s "${log_file}" ]] ; then
echo_failed
error "$(cat $log_file)\n"
else
echo_ok
fi
echononl " Get list of current groups.."
mapfile -t unsorted_group_arr < <(su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ group:list" -s /bin/bash $HTTP_USER 2> ${log_file} | awk '/^\s*-\s[^:]+:$/{gsub(/^\s*-\s|:$/, ""); print}' 2>> ${log_file} )
#su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ user:list" -s /bin/bash $HTTP_USER | \
# | awk -F'[:[:space:]]+' '{print $3}'
echo ""
echo ""
echo -e "\033[32m-----\033[m"
echo ""
echo -e " Which \033[1muser\033[m would you like to add?"
echo ""
NEW_ACCOUNT=
while [[ -z "$(trim ${NEW_ACCOUNT})" ]] ; do
echononl " New NC accoun name: "
read NEW_ACCOUNT
if containsElement "${NEW_ACCOUNT}" "${unsorted_account_arr[@]}" ; then
echo -e "\n\t\033[33m\033[1mAccount \033[m\033[1m${NEW_ACCOUNT}\033[33m already exists! \033[m- Try again\n"
NEW_ACCOUNT=""
#echononl " New NC accoun name: "
continue
fi
if [[ -z "$(trim ${NEW_ACCOUNT})" ]] ; then
echo -e "\n\t\033[33m\033[1mAccount name must be given.\033[m\n"
fi
done
echo ""
echo ""
echo -e "\033[32m-----\033[m"
echo ""
echo -e " Enter the display name for the account \033[1m${NEW_ACCOUNT}\033[m"
echo ""
echo -e " Type \033[33mNone\033[m to not assign a display name"
echo ""
DISPLAY_NAME=
while [[ -z "$(trim ${DISPLAY_NAME})" ]] ; do
echononl " Display name for he account \033[1m${DISPLAY_NAME}\033[m: "
read DISPLAY_NAME
if [[ "${DISPLAY_NAME,,}" = "none" ]] ; then
DISPLAY_NAME=""
break
fi
if [[ -z "$(trim ${DISPLAY_NAME})" ]] ; then
echo -e "\n\t\033[33m\033[1mEntry must not be empty. Type \033[m\033[1mNone\033[33m for not assigning a display name.\033[m\n"
fi
done
blank_line
blank_line
echo -e " Present groups on NC Cloud instance \033[1m${WEBSITE}\033[m\n"
echo -en "\033[33m"
printf " %s\n" "${unsorted_group_arr[@]}"
echo -en "\033[m"
blank_line
echo ""
echo ""
echo -e "\033[32m-----\033[m"
echo ""
echo -e " Which groups should the new account belong to?"
echo ""
echo " - enter a list separated by spaces"
echo -e " - or type \033[33mNone\033[m to not assign the account to any group"
echo ""
ASSIGNED_GROUPS=
while [[ -z "$(trim ${ASSIGNED_GROUPS})" ]] ; do
echononl " Groups to which the new account should belong: "
read ASSIGNED_GROUPS
if [[ "${ASSIGNED_GROUPS,,}" = "none" ]] ; then
ASSIGNED_GROUPS=""
break
fi
if [[ -z "$(trim ${ASSIGNED_GROUPS})" ]] ; then
echo -e "\n\t\033[33m\033[1mEntry must not be empty. Type \033[m\033[1mNone\033[33m for not assigning a group.\033[m\n"
continue
fi
IFS=' ' read -ra assigned_groups_arr <<< "${ASSIGNED_GROUPS}"
for _group in "${assigned_groups_arr[@]}" ; do
if ! containsElement "${_group}" "${unsorted_group_arr[@]}" ; then
echo -e "\n\t\033[33m\033[1m No group \033[m\033[1m${_group}\033[33m present!\033[m - Try again..\n"
ASSIGNED_GROUPS=""
break
fi
done
# - Sort array
# -
IFS=$'\n' assigned_groups_arr=($(sort <<<"${assigned_groups_arr[*]}"))
done
echo ""
echo ""
echo -e "\033[32m-----\033[m"
echo ""
echo -e " Enter a password for the new account \033[1m${NEW_ACCOUNT}\033[m"
echo ""
echo " Some random genaerated Passwords:"
echo ""
for ((i=0; i<=9; i++)); do
echo -en " $i: "
echo -e "\033[33m$(generate_random_string 12)\033[m"
done
echo ""
_PW1="X"
_PW2="Y"
while [ "$_PW1" != "$_PW2" ]
do
echononl "Password: "
#read -s _PW1
read _PW1
echo
if [ "X$_PW1" = "X" ]; then
echo -e "\n\t\033[33m\033[1mA password is required!\033[m\n"
continue
fi
echononl "Repeat the password: "
#read -s _PW2
read _PW2
echo
if [ "$_PW1" != "$_PW2" ];then
echo -e "\n\t\033[33m\033[1mpassword entries are NOT identical!\033[m\n"
else
PASSWORD=$_PW1
fi
done
regex_email="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
echo ""
echo ""
echo -e "\033[32m-----\033[m"
echo ""
echo -e " Enter an e-mail address for the new account \033[1m${NEW_ACCOUNT}\033[m"
echo ""
echo -e " Type \033[33mNone\033[m to not assign an e-mail address"
echo ""
E_MAIL=
while [[ -z "$(trim ${E_MAIL})" ]] ; do
echononl " E-Mail address for the new account \033[1m${E_MAIL}\033[m: "
read E_MAIL
if [[ "${E_MAIL,,}" = "none" ]] ; then
E_MAIL=""
break
fi
if [[ ! "${E_MAIL,,}" =~ ${regex_email} ]]; then
echo -e "\n\t\033[m\033[1m${E_MAIL}\033[33m is not a valid e-mail address\033[m - Try again..\n"
E_MAIL=""
continue
fi
if [[ -z "$(trim ${E_MAIL})" ]] ; then
echo -e "\n\t\033[33m\033[1mEntry must not be empty. Type \033[m\033[1mNone\033[33m for not assigning an e-mail address.\033[m\n"
fi
done
echo ""
echo ""
echo ""
echo -e "\033[1;32mStarting Script for \033[1;37m${WEBSITE}\033[m"
echo ""
echo -e " Cloud instance to be changed.........: ${WEBSITE}"
echo ""
echo -e " Current version of nextcloud.........: $CURRENT_VERSION"
echo ""
echo ""
echo -e " New Account..........................: ${NEW_ACCOUNT}"
if [[ -z "${DISPLAY_NAME}" ]] ; then
echo -e " Display Name.........................: \033[33mNone\033[m"
else
echo -e " Display Name.........................: ${DISPLAY_NAME}"
fi
if [[ -z "${E_MAIL}" ]] ; then
echo -e " E-Mail Address.......................: \033[33mNone\033[m"
else
echo -e " E-Mail Address.......................: ${E_MAIL}"
fi
echo ""
echo -e " Password.............................: ${PASSWORD}"
echo ""
if [[ -z "${ASSIGNED_GROUPS}" ]] ; then
echo -e " Group(s) assigned to the new account.: \033[33mNone\033[m"
else
declare -i index=0
for _group in "${assigned_groups_arr[@]}" ; do
if [[ ${index} -lt 1 ]] ; then
echo -e " Group(s) assigned to the new account.: \033[33m${_group}\033[m"
else
echo -e " \033[33m${_group}\033[m"
fi
(( index++ ))
done
fi
echo ""
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 -e " Databse name.........................: $DATABASE_NAME"
echo -e " Database type........................: $DATABASE_TYPE"
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 create new account \033[1;37m${NEW_ACCOUNT}\033[1;32m on \033[1;37m${WEBSITE}\033[m"
echo ""
else
fatal "Abort by user request - Answer as not 'YES'"
fi
# -----
# - Main part of the script
# -----
echo ""
echo ""
echo -e "\033[37m\033[1mMain part of the script\033[m"
echo ""
occ_arg_string="user:add --password-from-env"
echononl " Create Parametwer String.."
[[ -n "${DISPLAY_NAME}" ]] && occ_arg_string="${occ_arg_string} --display-name='${DISPLAY_NAME}'"
if [[ ${#assigned_groups_arr[@]} -gt 0 ]] ; then
for _group in "${assigned_groups_arr[@]}" ; do
occ_arg_string="${occ_arg_string} --group='${_group}'"
done
fi
[[ -n "${E_MAIL}" ]] && occ_arg_string="${occ_arg_string} --email=${E_MAIL}"
occ_arg_string="${occ_arg_string} '${NEW_ACCOUNT}'"
echo_done
# - Create new account
# -
echononl " Create new account \033[1;37m${NEW_ACCOUNT}\033[m on \033[1;37m${WEBSITE} \033[m"..""
su -c "OC_PASS='${PASSWORD}' ${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ ${occ_arg_string}" -s /bin/bash ${HTTP_USER} \
> $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
blank_line
echo -e "\033[37m\033[1mCommand output was:\033[m"
blank_line
cat ${log_file}
blank_line
echo -e "Password set to '${PASSWORD}'"
else
echo_failed
blank_line
echo ""
echo -e "\033[37m\033[1mCommandline was:\033[m"
echo -e "
su -c \"OC_PASS='${PASSWORD}' ${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ ${occ_arg_string}\" -s /bin/bash ${HTTP_USER}
"
blank_line
error "\n\n$(cat $log_file)"
fi
blank_line
clean_up 0

View File

@ -520,7 +520,7 @@ echo -e "\033[37m\033[1mMain part of the script\033[m"
echo ""
# - Create missing indices
# - Add missing primary keys ..
# -
echononl " Add missing primary keys .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ db:add-missing-primary-keys" -s /bin/bash $HTTP_USER > $log_file 2>&1

View File

@ -0,0 +1,14 @@
#"/usr/bin/env bash
read -p "Enter Database Name: " DB_NAME
echo
mysql -e "
SELECT CONCAT('ALTER TABLE \`', TABLE_NAME, '\` ROW_FORMAT=DYNAMIC;')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '$DB_NAME'
AND ENGINE = 'InnoDB';
" -B -N | while read -r sql; do
mysql -e "$sql" "$DB_NAME"
done

View File

@ -133,13 +133,11 @@ error(){
}
warn (){
echo ""
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
else
echo " [ Warning ]: $*"
echo ""
fi
echo ""
}
info (){
@ -174,6 +172,14 @@ blank_line() {
}
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ----------
# - Jobhandling
@ -214,6 +220,17 @@ if [[ -z "$WEBSITE" ]] ; then
#
source ${snippet_dir}/get-cloud-instance-to-update.sh
else
while IFS='' read -r -d '' _conf_file ; do
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
conf_file="${_conf_file}"
break
fi
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
# conf_file="${conf_dir}/${WEBSITE}.conf"
fi
@ -227,7 +244,7 @@ DEFAULT_HTTP_GROUP="www-data"
DEFAULT_PHP_ENGINE='FPM'
echo ""
echononl " Include Configuration file.."
echononl " Include Configuration file '$(basename "${conf_file}")'.."
if [[ ! -f $conf_file ]]; then
echo_failed
fatal "Missing configuration file '$conf_file'."
@ -264,14 +281,6 @@ else
SYSTEMD_EXISTS=true
fi
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
#clear
if $terminal ; then

View File

@ -140,13 +140,11 @@ error(){
}
warn (){
echo ""
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
else
echo " [ Warning ]: $*"
echo ""
fi
echo ""
}
info (){
@ -181,6 +179,14 @@ blank_line() {
}
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ----------
# - Jobhandling
@ -221,6 +227,15 @@ if [[ -z "$WEBSITE" ]] ; then
#
source ${snippet_dir}/get-cloud-instance-to-update.sh
else
while IFS='' read -r -d '' _conf_file ; do
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
conf_file="${_conf_file}"
break
fi
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
# conf_file="${conf_dir}/${WEBSITE}.conf"
fi
@ -234,7 +249,7 @@ DEFAULT_HTTP_GROUP="www-data"
DEFAULT_PHP_ENGINE='FPM'
echo ""
echononl " Include Configuration file.."
echononl " Include Configuration file '$(basename "${conf_file}")'.."
if [[ ! -f $conf_file ]]; then
echo_failed
fatal "Missing configuration file '$conf_file'."
@ -271,14 +286,6 @@ else
SYSTEMD_EXISTS=true
fi
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
#clear
if $terminal ; then

View File

@ -139,13 +139,11 @@ error(){
}
warn (){
echo ""
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
else
echo " [ Warning ]: $*"
echo ""
fi
echo ""
}
info (){
@ -181,6 +179,14 @@ blank_line() {
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ----------
# - Jobhandling
# ----------
@ -220,7 +226,17 @@ if [[ -z "$WEBSITE" ]] ; then
#
source ${snippet_dir}/get-cloud-instance-to-update.sh
#fatal "No website ios given on commandline - Missing Parameter '-s <website>'"
else
while IFS='' read -r -d '' _conf_file ; do
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
conf_file="${_conf_file}"
break
fi
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
# conf_file="${conf_dir}/${WEBSITE}.conf"
fi
@ -233,16 +249,15 @@ DEFAULT_HTTP_USER="www-data"
DEFAULT_HTTP_GROUP="www-data"
DEFAULT_PHP_ENGINE='FPM'
echo ""
echononl " Include Configuration file.."
blank_line
echononl " Include Configuration file '$(basename "${conf_file}")'.."
if [[ ! -f $conf_file ]]; then
echo_failed
echo_skipped
fatal "Missing configuration file '$conf_file'."
else
source $conf_file
echo_ok
fi
echo ""
DEFAULT_WEB_BASE_DIR="/var/www/${WEBSITE}"
[[ -n "$WEB_BASE_DIR" ]] || WEB_BASE_DIR=$DEFAULT_WEB_BASE_DIR
@ -271,19 +286,9 @@ else
SYSTEMD_EXISTS=true
fi
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
#clear
if $terminal ; then
echo ""
echo ""
echo ""
echo -e "\033[32m-----\033[m"
echo -e "Trigger a set of occ comands on system \033[1m${WEB_BASE_DIR}\033[m"

View File

@ -139,13 +139,11 @@ error(){
}
warn (){
echo ""
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
else
echo " [ Warning ]: $*"
echo ""
fi
echo ""
}
info (){
@ -180,6 +178,14 @@ blank_line() {
}
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ----------
# - Jobhandling
@ -220,7 +226,16 @@ if [[ -z "$WEBSITE" ]] ; then
#
source ${snippet_dir}/get-cloud-instance-to-update.sh
#fatal "No website ios given on commandline - Missing Parameter '-s <website>'"
else
while IFS='' read -r -d '' _conf_file ; do
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
conf_file="${_conf_file}"
break
fi
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
# conf_file="${conf_dir}/${WEBSITE}.conf"
fi
@ -234,7 +249,7 @@ DEFAULT_HTTP_GROUP="www-data"
DEFAULT_PHP_ENGINE='FPM'
echo ""
echononl " Include Configuration file.."
echononl " Include Configuration file '$(basename "${conf_file}")'.."
if [[ ! -f $conf_file ]]; then
echo_failed
fatal "Missing configuration file '$conf_file'."
@ -271,14 +286,6 @@ else
SYSTEMD_EXISTS=true
fi
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
#clear
if $terminal ; then

730
occ_migrate_mimetipes.sh Executable file
View File

@ -0,0 +1,730 @@
#!/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 ""
# - Add missing columns
# -
echononl " Migrating the mimetypes .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ maintenance:repair --include-expensive" -s /bin/bash $HTTP_USER > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
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

View File

@ -139,13 +139,11 @@ error(){
}
warn (){
echo ""
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
else
echo " [ Warning ]: $*"
echo ""
fi
echo ""
}
info (){
@ -180,6 +178,14 @@ blank_line() {
}
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ----------
# - Jobhandling
@ -221,6 +227,17 @@ if [[ -z "$WEBSITE" ]] ; then
#
source ${snippet_dir}/get-cloud-instance-to-update.sh
else
while IFS='' read -r -d '' _conf_file ; do
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
conf_file="${_conf_file}"
break
fi
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
# conf_file="${conf_dir}/${WEBSITE}.conf"
fi
@ -234,7 +251,7 @@ DEFAULT_HTTP_GROUP="www-data"
DEFAULT_PHP_ENGINE='FPM'
echo ""
echononl " Include Configuration file.."
echononl " Include Configuration file.. '$(basename "${conf_file}")'"
if [[ ! -f $conf_file ]]; then
echo_failed
fatal "Missing configuration file '$conf_file'."
@ -271,14 +288,6 @@ else
SYSTEMD_EXISTS=true
fi
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
#clear
if $terminal ; then

453
remove-old-nc-installations.sh Executable file
View File

@ -0,0 +1,453 @@
#!/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 from '$_backup_crontab_file'.."
crontab $_backup_crontab_file >> $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
# Perform program exit housekeeping
rm -f $log_file
blank_line
exit $1
}
is_number() {
return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1);
# - also possible
# -
#[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1
#return $([[ ! -z "${1##*[!0-9]*}" ]])
}
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
echo_done() {
if $terminal ; then
echo -e "\033[75G[ \033[32mdone\033[m ]"
else
echo " [ done ]"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[75G[ \033[32mok\033[m ]"
else
echo " [ ok ]"
fi
}
echo_warning() {
if $terminal ; then
echo -e "\033[75G[ \033[33m\033[1mwarn\033[m ]"
else
echo " [ warning ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
else
echo ' [ failed! ]'
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[75G[ \033[37mskipped\033[m ]"
else
echo " [ skipped ]"
fi
}
echo_wait(){
if $terminal ; then
echo -en "\033[75G[ \033[5m\033[1m..\033[m ]"
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)
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 "Clean up NC Installation"
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_HTTP_USER="www-data"
DEFAULT_HTTP_USER="www-data"
if [[ -z ${WEBSITE} ]] ; then
fatal "No website given (parameter 'WEBSITE')"
fi
DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE"
DEFAULT_PHP_ENGINE="FPM"
[[ -n "$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
# - Get available backup versions
# -
for _dir in $(ls -d ${WEB_BASE_DIR}/nextcloud-*) ; do
if [[ "$(basename "$_dir")" =~ ^nextcloud-[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4} ]]; then
_version="$(echo "$_dir"| grep -o -E "[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}")"
_backup_date="$(echo "$_dir"| grep -o -E "[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{4}")"
if [[ -d "${WEB_BASE_DIR}/nextcloud-${_version}.${_backup_date}" ]] \
&& [[ -d "${WEB_BASE_DIR}/data-${_version}.${_backup_date}" ]] \
&& [[ -f "${WEB_BASE_DIR}/${DATABASE_NAME}-v${_version}.${_backup_date}.sql" ]]; then
nextcloud_version_arr+=("$(basename "${_dir}"):${_version}:${_backup_date}")
fi
fi
done
if [[ ${#nextcloud_version_arr[@]} -lt 1 ]] ; then
info "No old version present!"
clean_up 0
fi
echo ""
echo ""
echo -e "\033[37m\033[1mGoing to delete the folowing old NC installations:..\033[m"
echo ""
for _backup_version in ${nextcloud_version_arr[@]} ; do
IFS=':' read -a _arr <<< ${_backup_version}
echo " [$i] Version ${_arr[1]} from ${_arr[2]}"
((i++))
done
echo ""
echo -en "\t\033[33mType upper case 'YES' to continue with deleting ALL old NC installations\033[m: "
read OK
if [[ "$OK" = "YES" ]] ; then
echo ""
echo ""
echo ""
echo -e "\033[1;32mGoing to delete ALL old NC installations including data directories on \033[1;37m$WEBSITE \033[m"
else
fatal "Abort by user request - Answer as not 'YES'"
fi
for _backup_version in ${nextcloud_version_arr[@]} ; do
IFS=':' read -a _arr <<< ${_backup_version}
echo ""
echo ""
echo -e "\033[37m\033[1mGoing to delete the NC Version ${_arr[1]} saved on ${_arr[2]}..\033[m"
echo ""
echononl " Delete SQL file '${DATABASE_NAME}-v${_arr[1]}.${_arr[2]}.sql'"
if [[ -f "${WEB_BASE_DIR}/${DATABASE_NAME}-v${_arr[1]}.${_arr[2]}.sql" ]]; then
rm -f "${WEB_BASE_DIR}/${DATABASE_NAME}-v${_arr[1]}.${_arr[2]}.sql" > ${log_file} 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "\n\n$(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
else
echo_skipped
warn "SQL file '${DATABASE_NAME}-v${_arr[1]}.${_arr[2]}.sql' not found!"
fi
echononl " Delete data directory 'data-${_arr[1]}.${_arr[2]}'"
if [[ -d "${WEB_BASE_DIR}/data-${_arr[1]}.${_arr[2]}" ]]; then
rm -rf "${WEB_BASE_DIR}/data-${_arr[1]}.${_arr[2]}" > ${log_file} 2>&1
echo_wait
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "\n\n$(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
else
echo_skipped
warn "Data directory '${WEB_BASE_DIR}/data-${_arr[1]}.${_arr[2]}' not found!"
fi
echononl " Delete NC install directory 'nextcloud-${_arr[1]}.${_arr[2]}'"
if [[ -d "${WEB_BASE_DIR}/nextcloud-${_arr[1]}.${_arr[2]}" ]]; then
rm -rf "${WEB_BASE_DIR}/nextcloud-${_arr[1]}.${_arr[2]}" > ${log_file} 2>&1
echo_wait
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "\n\n$(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
else
echo_skipped
warn "NC install directory directory '${WEB_BASE_DIR}/nextcloud-${_arr[1]}.${_arr[2]}' not found!"
fi
done
clean_up 0

View File

@ -100,7 +100,7 @@ echo_skipped() {
}
echo_wait(){
if $terminal ; then
echo -en "\033[75G[ \033[5m\033[1m...\033[m ]"
echo -en "\033[75G[ \033[5m\033[1m..\033[m ]"
fi
}
fatal (){
@ -615,7 +615,7 @@ if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
if $_failed ; then
echo_failed
error "$(cat $log_file)"
error "\n\n$(cat $log_file)"
if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then
echo ""
@ -625,9 +625,21 @@ if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
done
echo ""
fi
else
echo_ok
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
fi
@ -727,7 +739,7 @@ fi
# - Restore Database
# -
echononl " Restore Database - \033[5m\033[1mmay take a long time\033[m"
echononl " Restore Database \033[5m\033[1mmay take a long time\033[m"
echo_wait
if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
mysql $MYSQL_CREDENTIALS $DATABASE_NAME < \
@ -784,8 +796,90 @@ fi
echo ""
echo ""
echo -e "\033[37m\033[1mDoing some post-script tasks..\033[m"
echo ""
# - Add missing columns
# -
echononl " Add missing columns .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ db:add-missing-columns" -s /bin/bash $HTTP_USER > $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
# - Create missing indices
# -
echononl " Add missing indices .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ db:add-missing-indices" -s /bin/bash $HTTP_USER > $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
# - Add missing primary keys ..
# -
echononl " Add missing primary keys .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ db:add-missing-primary-keys" -s /bin/bash $HTTP_USER > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interrupted by user."
fi
echononl " Run cronjob manually.."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/cron.php" -s /bin/bash $HTTP_USER > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interrupted by user."
fi
blank_line
echononl " Restart PHP engine.."
if [[ "$PHP_ENGINE" = "FPM" ]]; then
if $SYSTEMD_EXISTS ; then

View File

@ -6,7 +6,7 @@ if [[ ${#website_arr[@]} -eq 1 ]] ; then
conf_file=${_arr[1]}
WEBSITE=${_arr[0]}
echo ""
echo -e "Update site \033[1m ${_arr[0]}"
echo -e "Update site \033[1m${_arr[0]}"
echo ""
else
echo ""

View File

@ -99,6 +99,12 @@ echo_skipped() {
echo " [ skipped ]"
fi
}
echo_wait(){
if $terminal ; then
echo -en "\033[75G[ \033[5m\033[1m..\033[m ]"
fi
}
fatal (){
echo ""
echo ""
@ -401,14 +407,10 @@ source ${snippet_dir}/get-path-of-php-command.sh
INSTALL_DIR="${WEB_BASE_DIR}/nextcloud-${VERSION}"
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
#PRIOR_VERSION="$(basename $CURRENT_INSTALL_DIR | cut -d"-" -f2)"
PRIOR_VERSION="$(sudo -u $HTTP_USER /usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ --version | cut -d' ' -f2)"
PRIOR_VERSION="$(sudo -u $HTTP_USER ${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ --version | cut -d' ' -f2)"
#DATA_DIR=${WEB_BASE_DIR}/data-${VERSION}
#CURRENT_DATA_DIR="$(realpath ${WEB_BASE_DIR}/data-$PRIOR_VERSION)"
DATA_DIR=${WEB_BASE_DIR}/data
OLD_DATA_DIR=${WEB_BASE_DIR}/data-${PRIOR_VERSION}
DATA_DIR="$(realpath "${WEB_BASE_DIR}/data")"
OLD_DATA_DIR="$(dirname "${DATA_DIR}")/data-${PRIOR_VERSION}.${backup_date}"
@ -662,7 +664,7 @@ if $NGINX_IS_ENABLED ; then
fi
fi
echo ""
blank_line
# - Backup Database
# -
@ -701,11 +703,18 @@ elif [[ "$DATABASE_TYPE" = 'postgres' ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
fi
fi
error "$(cat $log_file)"
echo
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
# - Backup old installation directory
@ -717,8 +726,19 @@ if [[ $? -eq 0 ]]; then
else
echo_failed
error "$(cat $log_file)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interrupted by user."
fi
blank_line
# - Remove symlink from old installation directory
# -
@ -728,7 +748,16 @@ if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
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
@ -760,7 +789,16 @@ if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
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
# - Kopiere Verzeichnis "config" in das neue Installationsverzeichnis
@ -816,13 +854,22 @@ fi
# - Backup Daten Verzeichnis (hardlinks - harte Dateiverweise)
# -
echononl " Copy (hardlink) data directory to '${OLD_DATA_DIR}.$backup_date'.."
cp -al "${DATA_DIR}" "${OLD_DATA_DIR}.${backup_date}" > $log_file 2>&1
echononl " Copy (hardlink) data directory to '${OLD_DATA_DIR}'.."
cp -al "${DATA_DIR}" "${OLD_DATA_DIR}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
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
@ -834,7 +881,16 @@ if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
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
# - Set Permissions on new data directory
@ -845,7 +901,16 @@ if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
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
@ -858,20 +923,66 @@ if [[ $? -eq 0 ]]; then
else
echo_failed
error "$(cat $log_file)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interrupted by user."
fi
blank_line
# - Update Nextcloud
# -
echo ""
echo " Update Nextcloud"
su -c"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ upgrade" -s /bin/bash $HTTP_USER
echo -e " Update Nextcloud\n"
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.."
else
fatal "$(cat $log_file)"
error "Updating nextcloud core failed!"
echo -e " Command was:"
echo -e " \033[33msu -c\"${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ upgrade\" -s /bin/bash $HTTP_USER\033[m"
echo ""
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
# Set maintenace mode to 'off'.. !!
#
blank_line
echononl " Set maintenace mode to 'off'.."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ maintenance:mode --off" -s /bin/bash $HTTP_USER > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interrupted by user."
fi
blank_line
## -----
@ -1258,8 +1369,126 @@ fi
echo ""
echo ""
echo -e "\033[37m\033[1mDoing some post-update tasks..\033[m"
echo ""
# - Add missing columns
# -
echononl " Add missing columns .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ db:add-missing-columns" -s /bin/bash $HTTP_USER > $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
# - Create missing indices
# -
echononl " Add missing indices .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ db:add-missing-indices" -s /bin/bash $HTTP_USER > $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
# - Add missing primary keys ..
# -
echononl " Add missing primary keys .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ db:add-missing-primary-keys" -s /bin/bash $HTTP_USER > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interrupted by user."
fi
echononl " Migrating the mimetypes .."
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ maintenance:repair --include-expensive" -s /bin/bash $HTTP_USER > $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
#echo ""
#echo " Would you like to run the cronjob manually - it may take a realy long time! "
#echo ""
#echononl " Run cronjob manually [yes/no]: "
#read OK
#OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
#while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
# echononl "Wrong entry! - repeat [yes/no]: "
# read OK
# OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
#done
#if [[ $OK = "yes" ]] ; then
#
# echononl " Run cronjob manually.. (can take a very long time)"
# echo_wait
# su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/cron.php" -s /bin/bash $HTTP_USER > $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
blank_line
echononl " Restart PHP engine.."
if [[ "$PHP_ENGINE" = "FPM" ]]; then
if $SYSTEMD_EXISTS ; then
@ -1444,6 +1673,18 @@ else
fi
fi
echononl " Restart notify_push service .."
if $(systemctl list-units --full -all | grep -Fq "notify_push") ; then
systemctl restart notify_push > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "\n\n$(cat $log_file)"
fi
fi
blank_line
clean_up 0