Compare commits
35 Commits
fb0a3dff2d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 09b9273a8d | |||
| b1f7186090 | |||
| 7efb678dfb | |||
| 3a652d14a1 | |||
| c97c7e4163 | |||
| 187310ecb9 | |||
| 793b1b1e1c | |||
| b6fd1ab6a3 | |||
| d60a7d5937 | |||
| 9346c73f39 | |||
| 23edc5828c | |||
| 73f2f79324 | |||
| 78a10d9169 | |||
| 9893bd4371 | |||
| 00cce38bf1 | |||
| 4abff5e4fa | |||
| 6882e48d80 | |||
| ab1256f14b | |||
| a9fb3067df | |||
| b5a0204dec | |||
| ebdccd5c44 | |||
| 588eb68502 | |||
| 2f8d771420 | |||
| bea755c670 | |||
| 2c37b04ddf | |||
| d84294cf0b | |||
| 1df7bb124b | |||
| 14f062908f | |||
| 588cf5ca2e | |||
| 17eaf8e278 | |||
| a335d51975 | |||
| 08a9bc984d | |||
| f244232347 | |||
| c0ea4fa6d4 | |||
| c97ca479b8 |
9
README.integrity-check
Normal file
9
README.integrity-check
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# see:
|
||||||
|
# https://docs.nextcloud.com/server/31/admin_manual/issues/code_signing.html
|
||||||
|
# https://docs.nextcloud.com/server/31/admin_manual/issues/code_signing.html#fixing-invalid-code-integrity-messages
|
||||||
|
# https://docs.nextcloud.com/server/31/admin_manual/issues/code_signing.html#rescans
|
||||||
|
|
||||||
|
# Error Message (/index.php/settings/admin/overview) was:
|
||||||
|
#
|
||||||
|
# Some files have not passed the integrity check. List of invalid files...,
|
||||||
|
# Rescan... . For more details see the documentation.
|
||||||
745
add-new-account.sh
Executable file
745
add-new-account.sh
Executable 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
|
||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -216,34 +217,9 @@ echo -e "\033[32m-----\033[m"
|
|||||||
echo "Add missing columns"
|
echo "Add missing columns"
|
||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
# Which cloud instance (website) would you like to update
|
||||||
WEBSITE=
|
#
|
||||||
_OK=false
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo ""
|
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -309,166 +285,18 @@ fi
|
|||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
|
|
||||||
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
@@ -488,6 +316,8 @@ echo -e " Webserver group......................: $HTTP_GROUP"
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
||||||
@@ -693,7 +523,7 @@ echo ""
|
|||||||
# - Add missing columns
|
# - Add missing columns
|
||||||
# -
|
# -
|
||||||
echononl " Add missing columns .."
|
echononl " Add missing columns .."
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ db:add-missing-columns" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
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
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -216,34 +217,9 @@ echo -e "\033[32m-----\033[m"
|
|||||||
echo "Create missing indices"
|
echo "Create missing indices"
|
||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
# Which cloud instance (website) would you like to update
|
||||||
WEBSITE=
|
#
|
||||||
_OK=false
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo ""
|
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -306,169 +282,23 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
|
|
||||||
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
@@ -488,6 +318,8 @@ echo -e " Webserver group......................: $HTTP_GROUP"
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
||||||
@@ -693,7 +525,7 @@ echo ""
|
|||||||
# - Create missing indices
|
# - Create missing indices
|
||||||
# -
|
# -
|
||||||
echononl " Add missing indices .."
|
echononl " Add missing indices .."
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ db:add-missing-indices" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
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
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -216,34 +217,9 @@ echo -e "\033[32m-----\033[m"
|
|||||||
echo "Create missing indices"
|
echo "Create missing indices"
|
||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
# Which cloud instance (website) would you like to update
|
||||||
WEBSITE=
|
#
|
||||||
_OK=false
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo ""
|
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -309,166 +285,18 @@ fi
|
|||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
|
|
||||||
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
@@ -488,6 +316,8 @@ echo -e " Webserver group......................: $HTTP_GROUP"
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
||||||
@@ -690,10 +520,10 @@ echo -e "\033[37m\033[1mMain part of the script\033[m"
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
# - Create missing indices
|
# - Add missing primary keys ..
|
||||||
# -
|
# -
|
||||||
echononl " Add missing primary keys .."
|
echononl " Add missing primary keys .."
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ db:add-missing-primary-keys" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
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
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -254,34 +255,9 @@ echo -e "\033[32m-----\033[m"
|
|||||||
echo -e "Add User to Group - \033[1mBoth, User and Group has to exist\033[m"
|
echo -e "Add User to Group - \033[1mBoth, User and Group has to exist\033[m"
|
||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
# Which cloud instance (website) would you like to update
|
||||||
WEBSITE=
|
#
|
||||||
_OK=false
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo ""
|
|
||||||
echo "Cloud instance that you want to change?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -344,169 +320,23 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud`
|
CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud`
|
||||||
CURRENT_DATA_DIR=`realpath ${WEB_BASE_DIR}/data`
|
CURRENT_DATA_DIR=`realpath ${WEB_BASE_DIR}/data`
|
||||||
@@ -566,6 +396,8 @@ echo ""
|
|||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
|
echo ""
|
||||||
echo -e " Databse name.........................: $DATABASE_NAME"
|
echo -e " Databse name.........................: $DATABASE_NAME"
|
||||||
echo -e " Database type........................: $DATABASE_TYPE"
|
echo -e " Database type........................: $DATABASE_TYPE"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -604,7 +436,7 @@ echo ""
|
|||||||
# -
|
# -
|
||||||
echononl " Add user \033[37m\033[1m$USER\033[m to group \033[37m\033[1m$GROUP\033[m .."
|
echononl " Add user \033[37m\033[1m$USER\033[m to group \033[37m\033[1m$GROUP\033[m .."
|
||||||
|
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ group:adduser '$GROUP' '$USER'" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ group:adduser '$GROUP' '$USER'" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@@ -612,7 +444,7 @@ else
|
|||||||
blank_line
|
blank_line
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[37m\033[1mcommandline was:\033[m"
|
echo -e "\033[37m\033[1mcommandline was:\033[m"
|
||||||
echo "su -c \"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ group:adduser '$GROUP' '$USER'\" -s /bin/bash $HTTP_USER"
|
echo "su -c \"${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ group:adduser '$GROUP' '$USER'\" -s /bin/bash $HTTP_USER"
|
||||||
blank_line
|
blank_line
|
||||||
warn "Despite errors, it is possible that the user \033[37m\033[1m$USER\033[m was added to the group \033[37m\033[1m$GROUP\033[m"
|
warn "Despite errors, it is possible that the user \033[37m\033[1m$USER\033[m was added to the group \033[37m\033[1m$GROUP\033[m"
|
||||||
fatal "$(cat $log_file)"
|
fatal "$(cat $log_file)"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -225,33 +226,9 @@ echo "Create missing indices"
|
|||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -316,177 +293,24 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then
|
|
||||||
PHP_BIN="/usr/local/php-${PHP_VERSION}/bin/php"
|
|
||||||
elif [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -225,32 +226,9 @@ echo -e "Add User to Group - \033[1mBoth, User and Group has to exist\033[m"
|
|||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Cloud instance that you want to change?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -316,177 +294,24 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then
|
|
||||||
PHP_BIN="/usr/local/php-${PHP_VERSION}/bin/php"
|
|
||||||
elif [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
@@ -509,6 +334,8 @@ echo ""
|
|||||||
echo -e " Webserver user.......................: $HTTP_USER"
|
echo -e " Webserver user.......................: $HTTP_USER"
|
||||||
echo -e " Webserver group......................: $HTTP_GROUP"
|
echo -e " Webserver group......................: $HTTP_GROUP"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -550,7 +377,7 @@ echo ""
|
|||||||
# -
|
# -
|
||||||
echononl " Check, if we can disable legacy encryption - Checking for old files.."
|
echononl " Check, if we can disable legacy encryption - Checking for old files.."
|
||||||
|
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ encryption:scan:legacy-format" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ encryption:scan:legacy-format" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
info "Output of command \033[37m\033[1mocc encryption:scan:legacy-format\033[m was:\n\n$(cat $log_file)"
|
info "Output of command \033[37m\033[1mocc encryption:scan:legacy-format\033[m was:\n\n$(cat $log_file)"
|
||||||
@@ -559,7 +386,7 @@ else
|
|||||||
blank_line
|
blank_line
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[37m\033[1mcommandline was:\033[m"
|
echo -e "\033[37m\033[1mcommandline was:\033[m"
|
||||||
echo "su -c \"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ encryption:scan:legacy-format\" -s /bin/bash $HTTP_USER"
|
echo "su -c \"${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ encryption:scan:legacy-format\" -s /bin/bash $HTTP_USER"
|
||||||
error "Output of command \033[37m\033[1mocc encryption:scan:legacy-format\033[m was:\n\n$(cat $log_file)"
|
error "Output of command \033[37m\033[1mocc encryption:scan:legacy-format\033[m was:\n\n$(cat $log_file)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,18 @@ WEBSITE="<site-name-of-cloud-instance>"
|
|||||||
#THIRD_PARTY_APPS="calendar contacts notes richdocuments"
|
#THIRD_PARTY_APPS="calendar contacts notes richdocuments"
|
||||||
|
|
||||||
|
|
||||||
|
# - Extra Apps
|
||||||
|
# -
|
||||||
|
# - Possible values are app-names like 'calendar' , 'contacts' , ..
|
||||||
|
# -
|
||||||
|
# - a blank separated list enclosed in brackets
|
||||||
|
# -
|
||||||
|
# - Note:
|
||||||
|
# - Don't use quotes !!
|
||||||
|
# -
|
||||||
|
#EXTRA_APPS=(calendar contacts deck notes richdocuments tasks)
|
||||||
|
|
||||||
|
|
||||||
# - Source directory for tar archives of Nextcloud
|
# - Source directory for tar archives of Nextcloud
|
||||||
# -
|
# -
|
||||||
# - Defaults to '/usr/local/src/nextcloud'
|
# - Defaults to '/usr/local/src/nextcloud'
|
||||||
@@ -101,9 +113,10 @@ DATABASE_NAME="ownCloud_test"
|
|||||||
# - Credentials to access MySQL/MariaDB Database
|
# - Credentials to access MySQL/MariaDB Database
|
||||||
# -
|
# -
|
||||||
# - Example
|
# - Example
|
||||||
# - mysql_credential_args="--login-path=local"
|
# - MYSQL_CREDENTIALS="--login-path=local"
|
||||||
# - mysql_credential_args="--defaults-file=/etc/mysql/debian.cnf" (Debian default)
|
# - MYSQL_CREDENTIALS="--defaults-file=/etc/mysql/debian.cnf" (Debian default)
|
||||||
# - mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
# - MYSQL_CREDENTIALS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||||
|
# - MYSQL_CREDENTIALS="-S/run/mysqld/mysqld.sock"
|
||||||
# -
|
# -
|
||||||
MYSQL_CREDENTIALS="--login-path=local"
|
MYSQL_CREDENTIALS="--login-path=local"
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -225,33 +226,9 @@ echo "Create missing indices"
|
|||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -316,176 +293,24 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then
|
|
||||||
PHP_BIN="/usr/local/php-${PHP_VERSION}/bin/php"
|
|
||||||
elif [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
|
|||||||
14
correct-cloud-database-row-format.sh
Executable file
14
correct-cloud-database-row-format.sh
Executable 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
|
||||||
812
install_apps.sh
Executable file
812
install_apps.sh
Executable file
@@ -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
|
||||||
@@ -4,6 +4,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -132,13 +133,11 @@ error(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
warn (){
|
warn (){
|
||||||
echo ""
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
|
||||||
else
|
|
||||||
echo " [ Warning ]: $*"
|
|
||||||
fi
|
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
info (){
|
info (){
|
||||||
@@ -173,6 +172,14 @@ blank_line() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# - Running in a terminal?
|
||||||
|
# -
|
||||||
|
if [[ -t 1 ]] ; then
|
||||||
|
terminal=true
|
||||||
|
else
|
||||||
|
terminal=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
# - Jobhandling
|
# - Jobhandling
|
||||||
@@ -196,16 +203,68 @@ while getopts hs: opt ; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "$WEBSITE" ]] ; then
|
if [[ -z "$WEBSITE" ]] ; then
|
||||||
fatal "No website ios given on commandline - Missing Parameter '-s <website>'"
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# - Sort array
|
||||||
|
# -
|
||||||
|
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
||||||
|
|
||||||
|
# Which cloud instance (website) would you like to update
|
||||||
|
#
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
WEB_BASE_DIR="/var/www/${WEBSITE}"
|
|
||||||
|
# - Reset IFS
|
||||||
|
# -
|
||||||
|
IFS=$CUR_IFS
|
||||||
|
|
||||||
|
DEFAULT_SRC_BASE_DIR="/usr/local/src/nextcloud"
|
||||||
|
DEFAULT_HTTP_USER="www-data"
|
||||||
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
DEFAULT_PHP_ENGINE='FPM'
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echononl " Include Configuration file '$(basename "${conf_file}")'.."
|
||||||
|
if [[ ! -f $conf_file ]]; then
|
||||||
|
echo_failed
|
||||||
|
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
|
||||||
|
|
||||||
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
||||||
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
||||||
|
|
||||||
|
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
||||||
|
|
||||||
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
||||||
|
|
||||||
@@ -222,14 +281,6 @@ else
|
|||||||
SYSTEMD_EXISTS=true
|
SYSTEMD_EXISTS=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - Running in a terminal?
|
|
||||||
# -
|
|
||||||
if [[ -t 1 ]] ; then
|
|
||||||
terminal=true
|
|
||||||
else
|
|
||||||
terminal=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
#clear
|
#clear
|
||||||
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
@@ -249,112 +300,24 @@ fi
|
|||||||
DEFAULT_HTTP_USER="www-data"
|
DEFAULT_HTTP_USER="www-data"
|
||||||
DEFAULT_HTTP_GROUP="www-data"
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
# Check PHP Version
|
||||||
|
#
|
||||||
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
# Get full qualified PHP command
|
||||||
# -
|
#
|
||||||
httpd_binary="`which httpd`"
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -139,13 +140,11 @@ error(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
warn (){
|
warn (){
|
||||||
echo ""
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
|
||||||
else
|
|
||||||
echo " [ Warning ]: $*"
|
|
||||||
fi
|
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
info (){
|
info (){
|
||||||
@@ -180,6 +179,14 @@ blank_line() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# - Running in a terminal?
|
||||||
|
# -
|
||||||
|
if [[ -t 1 ]] ; then
|
||||||
|
terminal=true
|
||||||
|
else
|
||||||
|
terminal=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
# - Jobhandling
|
# - Jobhandling
|
||||||
@@ -216,38 +223,19 @@ if [[ -z "$WEBSITE" ]] ; then
|
|||||||
# -
|
# -
|
||||||
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
else
|
||||||
echo ""
|
while IFS='' read -r -d '' _conf_file ; do
|
||||||
echo -e "\tFalsche Eingabe !"
|
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
|
||||||
echo ""
|
conf_file="${_conf_file}"
|
||||||
echononl " Eingabe: "
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
|
||||||
|
# conf_file="${conf_dir}/${WEBSITE}.conf"
|
||||||
|
|
||||||
WEBSITE="$_WEBSITE"
|
|
||||||
|
|
||||||
|
|
||||||
#fatal "No website ios given on commandline - Missing Parameter '-s <website>'"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -255,14 +243,33 @@ fi
|
|||||||
# -
|
# -
|
||||||
IFS=$CUR_IFS
|
IFS=$CUR_IFS
|
||||||
|
|
||||||
|
DEFAULT_SRC_BASE_DIR="/usr/local/src/nextcloud"
|
||||||
|
DEFAULT_HTTP_USER="www-data"
|
||||||
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
DEFAULT_PHP_ENGINE='FPM'
|
||||||
|
|
||||||
WEB_BASE_DIR="/var/www/${WEBSITE}"
|
echo ""
|
||||||
|
echononl " Include Configuration file '$(basename "${conf_file}")'.."
|
||||||
|
if [[ ! -f $conf_file ]]; then
|
||||||
|
echo_failed
|
||||||
|
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
|
||||||
|
|
||||||
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
||||||
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
||||||
|
|
||||||
|
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
||||||
|
|
||||||
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
||||||
|
|
||||||
@@ -279,14 +286,6 @@ else
|
|||||||
SYSTEMD_EXISTS=true
|
SYSTEMD_EXISTS=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - Running in a terminal?
|
|
||||||
# -
|
|
||||||
if [[ -t 1 ]] ; then
|
|
||||||
terminal=true
|
|
||||||
else
|
|
||||||
terminal=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
#clear
|
#clear
|
||||||
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
@@ -306,112 +305,24 @@ fi
|
|||||||
DEFAULT_HTTP_USER="www-data"
|
DEFAULT_HTTP_USER="www-data"
|
||||||
DEFAULT_HTTP_GROUP="www-data"
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
# Check PHP Version
|
||||||
|
#
|
||||||
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
# Get full qualified PHP command
|
||||||
# -
|
#
|
||||||
httpd_binary="`which httpd`"
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -138,13 +139,11 @@ error(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
warn (){
|
warn (){
|
||||||
echo ""
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
|
||||||
else
|
|
||||||
echo " [ Warning ]: $*"
|
|
||||||
fi
|
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
info (){
|
info (){
|
||||||
@@ -180,6 +179,14 @@ blank_line() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# - Running in a terminal?
|
||||||
|
# -
|
||||||
|
if [[ -t 1 ]] ; then
|
||||||
|
terminal=true
|
||||||
|
else
|
||||||
|
terminal=false
|
||||||
|
fi
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
# - Jobhandling
|
# - Jobhandling
|
||||||
# ----------
|
# ----------
|
||||||
@@ -215,37 +222,21 @@ if [[ -z "$WEBSITE" ]] ; then
|
|||||||
# -
|
# -
|
||||||
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
else
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
while IFS='' read -r -d '' _conf_file ; do
|
||||||
echo ""
|
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
|
||||||
echononl " Eingabe: "
|
conf_file="${_conf_file}"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
|
||||||
|
|
||||||
WEBSITE="$_WEBSITE"
|
# conf_file="${conf_dir}/${WEBSITE}.conf"
|
||||||
|
|
||||||
#fatal "No website ios given on commandline - Missing Parameter '-s <website>'"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -253,13 +244,32 @@ fi
|
|||||||
# -
|
# -
|
||||||
IFS=$CUR_IFS
|
IFS=$CUR_IFS
|
||||||
|
|
||||||
WEB_BASE_DIR="/var/www/${WEBSITE}"
|
DEFAULT_SRC_BASE_DIR="/usr/local/src/nextcloud"
|
||||||
|
DEFAULT_HTTP_USER="www-data"
|
||||||
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
DEFAULT_PHP_ENGINE='FPM'
|
||||||
|
|
||||||
|
blank_line
|
||||||
|
echononl " Include Configuration file '$(basename "${conf_file}")'.."
|
||||||
|
if [[ ! -f $conf_file ]]; then
|
||||||
|
echo_skipped
|
||||||
|
fatal "Missing configuration file '$conf_file'."
|
||||||
|
else
|
||||||
|
source $conf_file
|
||||||
|
echo_ok
|
||||||
|
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
|
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
||||||
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
||||||
|
|
||||||
|
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
||||||
|
|
||||||
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
||||||
|
|
||||||
@@ -276,19 +286,9 @@ else
|
|||||||
SYSTEMD_EXISTS=true
|
SYSTEMD_EXISTS=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - Running in a terminal?
|
|
||||||
# -
|
|
||||||
if [[ -t 1 ]] ; then
|
|
||||||
terminal=true
|
|
||||||
else
|
|
||||||
terminal=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
#clear
|
#clear
|
||||||
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
echo -e "Trigger a set of occ comands on system \033[1m${WEB_BASE_DIR}\033[m"
|
echo -e "Trigger a set of occ comands on system \033[1m${WEB_BASE_DIR}\033[m"
|
||||||
@@ -309,112 +309,24 @@ fi
|
|||||||
DEFAULT_HTTP_USER="www-data"
|
DEFAULT_HTTP_USER="www-data"
|
||||||
DEFAULT_HTTP_GROUP="www-data"
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
# Check PHP Version
|
||||||
|
#
|
||||||
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
# Get full qualified PHP command
|
||||||
# -
|
#
|
||||||
httpd_binary="`which httpd`"
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -138,13 +139,11 @@ error(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
warn (){
|
warn (){
|
||||||
echo ""
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
|
||||||
else
|
|
||||||
echo " [ Warning ]: $*"
|
|
||||||
fi
|
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
info (){
|
info (){
|
||||||
@@ -179,6 +178,14 @@ blank_line() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# - Running in a terminal?
|
||||||
|
# -
|
||||||
|
if [[ -t 1 ]] ; then
|
||||||
|
terminal=true
|
||||||
|
else
|
||||||
|
terminal=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
# - Jobhandling
|
# - Jobhandling
|
||||||
@@ -215,37 +222,20 @@ if [[ -z "$WEBSITE" ]] ; then
|
|||||||
# -
|
# -
|
||||||
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
else
|
||||||
echo ""
|
while IFS='' read -r -d '' _conf_file ; do
|
||||||
echo -e "\tFalsche Eingabe !"
|
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
|
||||||
echo ""
|
conf_file="${_conf_file}"
|
||||||
echononl " Eingabe: "
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
|
||||||
|
|
||||||
WEBSITE="$_WEBSITE"
|
# conf_file="${conf_dir}/${WEBSITE}.conf"
|
||||||
|
|
||||||
#fatal "No website ios given on commandline - Missing Parameter '-s <website>'"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -253,13 +243,33 @@ fi
|
|||||||
# -
|
# -
|
||||||
IFS=$CUR_IFS
|
IFS=$CUR_IFS
|
||||||
|
|
||||||
WEB_BASE_DIR="/var/www/${WEBSITE}"
|
DEFAULT_SRC_BASE_DIR="/usr/local/src/nextcloud"
|
||||||
|
DEFAULT_HTTP_USER="www-data"
|
||||||
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
DEFAULT_PHP_ENGINE='FPM'
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echononl " Include Configuration file '$(basename "${conf_file}")'.."
|
||||||
|
if [[ ! -f $conf_file ]]; then
|
||||||
|
echo_failed
|
||||||
|
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
|
||||||
|
|
||||||
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
||||||
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
||||||
|
|
||||||
|
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
||||||
|
|
||||||
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
||||||
|
|
||||||
@@ -276,14 +286,6 @@ else
|
|||||||
SYSTEMD_EXISTS=true
|
SYSTEMD_EXISTS=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - Running in a terminal?
|
|
||||||
# -
|
|
||||||
if [[ -t 1 ]] ; then
|
|
||||||
terminal=true
|
|
||||||
else
|
|
||||||
terminal=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
#clear
|
#clear
|
||||||
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
@@ -309,112 +311,24 @@ fi
|
|||||||
DEFAULT_HTTP_USER="www-data"
|
DEFAULT_HTTP_USER="www-data"
|
||||||
DEFAULT_HTTP_GROUP="www-data"
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
# Check PHP Version
|
||||||
|
#
|
||||||
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
# Get full qualified PHP command
|
||||||
# -
|
#
|
||||||
httpd_binary="`which httpd`"
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
|
|||||||
730
occ_migrate_mimetipes.sh
Executable file
730
occ_migrate_mimetipes.sh
Executable 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
|
||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -138,13 +139,11 @@ error(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
warn (){
|
warn (){
|
||||||
echo ""
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
|
||||||
else
|
|
||||||
echo " [ Warning ]: $*"
|
|
||||||
fi
|
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
info (){
|
info (){
|
||||||
@@ -179,6 +178,14 @@ blank_line() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# - Running in a terminal?
|
||||||
|
# -
|
||||||
|
if [[ -t 1 ]] ; then
|
||||||
|
terminal=true
|
||||||
|
else
|
||||||
|
terminal=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
# - Jobhandling
|
# - Jobhandling
|
||||||
@@ -215,37 +222,22 @@ if [[ -z "$WEBSITE" ]] ; then
|
|||||||
# -
|
# -
|
||||||
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
|
||||||
|
|
||||||
WEBSITE=
|
|
||||||
_OK=false
|
# Which cloud instance (website) would you like to update
|
||||||
echo ""
|
#
|
||||||
echo "Which site would you like to update?"
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
else
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
while IFS='' read -r -d '' _conf_file ; do
|
||||||
echo ""
|
if $(grep -E -q "WEBSITE=\"?${WEBSITE}\"?" ${_conf_file} 2> /dev/null) ; then
|
||||||
echononl " Eingabe: "
|
conf_file="${_conf_file}"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "*.conf" -print0)
|
||||||
|
|
||||||
WEBSITE="$_WEBSITE"
|
# conf_file="${conf_dir}/${WEBSITE}.conf"
|
||||||
|
|
||||||
#fatal "No website ios given on commandline - Missing Parameter '-s <website>'"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -253,13 +245,33 @@ fi
|
|||||||
# -
|
# -
|
||||||
IFS=$CUR_IFS
|
IFS=$CUR_IFS
|
||||||
|
|
||||||
WEB_BASE_DIR="/var/www/${WEBSITE}"
|
DEFAULT_SRC_BASE_DIR="/usr/local/src/nextcloud"
|
||||||
|
DEFAULT_HTTP_USER="www-data"
|
||||||
|
DEFAULT_HTTP_GROUP="www-data"
|
||||||
|
DEFAULT_PHP_ENGINE='FPM'
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echononl " Include Configuration file.. '$(basename "${conf_file}")'"
|
||||||
|
if [[ ! -f $conf_file ]]; then
|
||||||
|
echo_failed
|
||||||
|
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
|
||||||
|
|
||||||
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
||||||
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
fatal "Web base directory '$WEB_BASE_DIR' not found!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
DATA_DIR="$(realpath ${WEB_BASE_DIR}/data)"
|
||||||
|
|
||||||
|
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
||||||
|
|
||||||
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
CURRENT_VERSION="$(basename $INSTALL_DIR | cut -d"-" -f2)"
|
||||||
|
|
||||||
@@ -276,14 +288,6 @@ else
|
|||||||
SYSTEMD_EXISTS=true
|
SYSTEMD_EXISTS=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - Running in a terminal?
|
|
||||||
# -
|
|
||||||
if [[ -t 1 ]] ; then
|
|
||||||
terminal=true
|
|
||||||
else
|
|
||||||
terminal=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
#clear
|
#clear
|
||||||
|
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
@@ -312,109 +316,20 @@ DEFAULT_HTTP_GROUP="www-data"
|
|||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
# Check PHP Version
|
||||||
|
#
|
||||||
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
# Get full qualified PHP command
|
||||||
# -
|
#
|
||||||
httpd_binary="`which httpd`"
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
|
||||||
PHP_BIN="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
PHP_BIN="$(which php)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -x "$PHP_BIN" ]]; then
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
fatal "No PHP binary found!"
|
fatal "No PHP binary found!"
|
||||||
|
|||||||
782
reinstall-notify_push.sh
Executable file
782
reinstall-notify_push.sh
Executable file
@@ -0,0 +1,782 @@
|
|||||||
|
#!/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 ""
|
||||||
|
|
||||||
|
|
||||||
|
if $(systemctl list-units --full -all | grep -Fq "notify_push") ; then
|
||||||
|
echononl " Install notify_push app.."
|
||||||
|
if $(
|
||||||
|
sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:list \
|
||||||
|
| grep -q notify
|
||||||
|
) ; then
|
||||||
|
echo_skipped
|
||||||
|
else
|
||||||
|
sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:install notify_push > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
echononl " Enable Nextcloud App 'notify_pushi'.."
|
||||||
|
if $(
|
||||||
|
sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:list --enabled \
|
||||||
|
| grep -q notify
|
||||||
|
) ; then
|
||||||
|
echo_skipped
|
||||||
|
else
|
||||||
|
sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:install > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echononl " Setup Nextcloud App 'notify_pushi'.."
|
||||||
|
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
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echononl "\n Restart notify_push service .."
|
||||||
|
|
||||||
|
systemctl restart notify_push > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
error "\n\n$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
warn "Service 'notify_push' is NOT installed."
|
||||||
|
|
||||||
|
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
|
||||||
750
remove-app_api.sh
Executable file
750
remove-app_api.sh
Executable file
@@ -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
|
||||||
453
remove-old-nc-installations.sh
Executable file
453
remove-old-nc-installations.sh
Executable 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
|
||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -255,33 +256,9 @@ echo -e "Remove User from Group - \033[1mBoth, User and Group has to exist\033[m
|
|||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Cloud instance that you want to change?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -344,169 +321,24 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
|
|
||||||
CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud`
|
CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud`
|
||||||
CURRENT_DATA_DIR=`realpath ${WEB_BASE_DIR}/data`
|
CURRENT_DATA_DIR=`realpath ${WEB_BASE_DIR}/data`
|
||||||
@@ -566,6 +398,8 @@ echo ""
|
|||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e " PHP command..........................: $PHP_BIN"
|
||||||
|
echo ""
|
||||||
echo -e " Databse name.........................: $DATABASE_NAME"
|
echo -e " Databse name.........................: $DATABASE_NAME"
|
||||||
echo -e " Database type........................: $DATABASE_TYPE"
|
echo -e " Database type........................: $DATABASE_TYPE"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -604,7 +438,7 @@ echo ""
|
|||||||
# -
|
# -
|
||||||
echononl " Remove user \033[37m\033[1m$USER\033[m from group \033[37m\033[1m$GROUP\033[m .."
|
echononl " Remove user \033[37m\033[1m$USER\033[m from group \033[37m\033[1m$GROUP\033[m .."
|
||||||
|
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ group:removeuser '$GROUP' '$USER'" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ group:removeuser '$GROUP' '$USER'" -s /bin/bash $HTTP_USER > $log_file 2>&1
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@@ -612,7 +446,7 @@ else
|
|||||||
blank_line
|
blank_line
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[37m\033[1mcommandline was:\033[m"
|
echo -e "\033[37m\033[1mcommandline was:\033[m"
|
||||||
echo -e "su -c \"/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ group:removeuser '$GROUP' '$USER'\" -s /bin/bash $HTTP_USER"
|
echo -e "su -c \"${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ group:removeuser '$GROUP' '$USER'\" -s /bin/bash $HTTP_USER"
|
||||||
blank_line
|
blank_line
|
||||||
warn "Despite errors, it is possible that the user \033[37m\033[1m$USER\033[m was removed from the group \033[37m\033[1m$GROUP\033[m"
|
warn "Despite errors, it is possible that the user \033[37m\033[1m$USER\033[m was removed from the group \033[37m\033[1m$GROUP\033[m"
|
||||||
fatal "$(cat $log_file)"
|
fatal "$(cat $log_file)"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -213,37 +214,13 @@ clear
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
echo "Create missing indices"
|
echo "Replace favicon icon"
|
||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -277,10 +254,6 @@ DEFAULT_HTTP_GROUP="www-data"
|
|||||||
DEFAULT_PHP_ENGINE="FPM"
|
DEFAULT_PHP_ENGINE="FPM"
|
||||||
|
|
||||||
|
|
||||||
if [[ -z ${WEBSITE} ]] ; then
|
|
||||||
WEBSITE="$DEFAULT_WEBSITE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE"
|
DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE"
|
||||||
|
|
||||||
[[ -n "$WEB_BASE_DIR" ]] || WEB_BASE_DIR=$DEFAULT_WEB_BASE_DIR
|
[[ -n "$WEB_BASE_DIR" ]] || WEB_BASE_DIR=$DEFAULT_WEB_BASE_DIR
|
||||||
@@ -309,169 +282,28 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
|
# Get full qualified PHP command
|
||||||
|
#
|
||||||
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
|
if [[ ! -x "$PHP_BIN" ]]; then
|
||||||
|
fatal "No PHP binary found!"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " \033[32m--\033[m"
|
echo -e " \033[32m--\033[m"
|
||||||
@@ -525,6 +357,8 @@ echo -e " Webserver group......................: $HTTP_GROUP"
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
||||||
@@ -554,7 +388,7 @@ echo ""
|
|||||||
# - Create missing indices
|
# - Create missing indices
|
||||||
# -
|
# -
|
||||||
echononl " Replace Favicon Icon with \033[1m$(basename ${CUSTOM_FAVICON_PATH})\033[m .."
|
echononl " Replace Favicon Icon with \033[1m$(basename ${CUSTOM_FAVICON_PATH})\033[m .."
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ theming:config favicon ${CUSTOM_FAVICON_PATH}" \
|
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ theming:config favicon ${CUSTOM_FAVICON_PATH}" \
|
||||||
-s /bin/bash $HTTP_USER > $log_file 2>&1
|
-s /bin/bash $HTTP_USER > $log_file 2>&1
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
|
|||||||
210
replace_logo.sh
210
replace_logo.sh
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -217,33 +218,19 @@ echo "Create missing indices"
|
|||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
# Check PHP Version
|
||||||
for _site in ${website_arr[@]} ; do
|
#
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
# Get full qualified PHP command
|
||||||
echo
|
#
|
||||||
echononl " Eingabe: "
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
DEFAULT_WEBSITE="${_arr[0]}"
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -277,10 +264,6 @@ DEFAULT_HTTP_GROUP="www-data"
|
|||||||
DEFAULT_PHP_ENGINE="FPM"
|
DEFAULT_PHP_ENGINE="FPM"
|
||||||
|
|
||||||
|
|
||||||
if [[ -z ${WEBSITE} ]] ; then
|
|
||||||
WEBSITE="$DEFAULT_WEBSITE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE"
|
DEFAULT_WEB_BASE_DIR="/var/www/$WEBSITE"
|
||||||
|
|
||||||
[[ -n "$WEB_BASE_DIR" ]] || WEB_BASE_DIR=$DEFAULT_WEB_BASE_DIR
|
[[ -n "$WEB_BASE_DIR" ]] || WEB_BASE_DIR=$DEFAULT_WEB_BASE_DIR
|
||||||
@@ -309,169 +292,24 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " \033[32m--\033[m"
|
echo -e " \033[32m--\033[m"
|
||||||
@@ -525,6 +363,8 @@ echo -e " Webserver group......................: $HTTP_GROUP"
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
echo -n " Type upper case 'YES' to continue executing with this parameters: "
|
||||||
@@ -554,7 +394,7 @@ echo ""
|
|||||||
# - Create missing indices
|
# - Create missing indices
|
||||||
# -
|
# -
|
||||||
echononl " Replace Logo with \033[1m$(basename ${CUSTOM_LOGO_PATH})\033[m .."
|
echononl " Replace Logo with \033[1m$(basename ${CUSTOM_LOGO_PATH})\033[m .."
|
||||||
su -c "/usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ theming:config logo ${CUSTOM_LOGO_PATH}" \
|
su -c "${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ theming:config logo ${CUSTOM_LOGO_PATH}" \
|
||||||
-s /bin/bash $HTTP_USER > $log_file 2>&1
|
-s /bin/bash $HTTP_USER > $log_file 2>&1
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -99,7 +100,7 @@ echo_skipped() {
|
|||||||
}
|
}
|
||||||
echo_wait(){
|
echo_wait(){
|
||||||
if $terminal ; then
|
if $terminal ; then
|
||||||
echo -en "\033[75G[ \033[5m\033[1m...\033[m ]"
|
echo -en "\033[75G[ \033[5m\033[1m..\033[m ]"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
fatal (){
|
fatal (){
|
||||||
@@ -222,32 +223,9 @@ echo "Update Nextcloud"
|
|||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to restore?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
|
||||||
for _site in ${website_arr[@]} ; do
|
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -309,149 +287,23 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
PHP_VERSION="$(grep -o -E "php-?.{1}\..{1}-fpm" $VHOST_CONFIG_FILE | grep -o -E ".{1}\..{1}")"
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
fatal "PHP Version must be givven if running PHP-FPM engine (parameter 'PHP_VERSION')"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
# Get full qualified PHP command
|
||||||
# - Determin PHP binary
|
#
|
||||||
# -
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then
|
|
||||||
php_binary="/usr/local/php-${PHP_VERSION}/bin/php"
|
|
||||||
else
|
|
||||||
php_binary="$(realpath "$(which php)")"
|
|
||||||
if [[ -z "$php_binary" ]]; then
|
|
||||||
if [[ -x "/usr/local/php/bin/php" ]]; then
|
|
||||||
php_binary="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
fatal "No PHP binary present"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ ! -x "$php_binary" ]]; then
|
|
||||||
fatal "Found PHP binary '$php_binary', but this file is not executable!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -503,7 +355,7 @@ read _IN
|
|||||||
done
|
done
|
||||||
|
|
||||||
CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud`
|
CURRENT_INSTALL_DIR=`realpath ${WEB_BASE_DIR}/nextcloud`
|
||||||
CURRENT_VERSION="$(sudo -u $HTTP_USER $php_binary ${WEB_BASE_DIR}/htdocs/occ --version | cut -d' ' -f2)"
|
CURRENT_VERSION="$(sudo -u $HTTP_USER ${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ --version | cut -d' ' -f2)"
|
||||||
|
|
||||||
DATA_DIR=${WEB_BASE_DIR}/data
|
DATA_DIR=${WEB_BASE_DIR}/data
|
||||||
|
|
||||||
@@ -521,7 +373,8 @@ echo -e " Webserver user.......................: $HTTP_USER"
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
echo -e " PHP binary...........................: $php_binary"
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " Version to rstore....................: $RESTORE_VERSION"
|
echo -e " Version to rstore....................: $RESTORE_VERSION"
|
||||||
echo -e " Backup date was......................: $DATE_RESTORE_VERSION"
|
echo -e " Backup date was......................: $DATE_RESTORE_VERSION"
|
||||||
@@ -752,6 +605,21 @@ if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
|
|||||||
echononl " Drop tables from database '$DATABASE_NAME' .."
|
echononl " Drop tables from database '$DATABASE_NAME' .."
|
||||||
_failed=false
|
_failed=false
|
||||||
> $log_file
|
> $log_file
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if $_failed ; then
|
||||||
|
|
||||||
|
echo_failed
|
||||||
|
error "\n\n$(cat $log_file)"
|
||||||
|
|
||||||
|
_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
|
for _table in $_TABLES ; do
|
||||||
mysql $MYSQL_CREDENTIALS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $log_file 2>&1
|
mysql $MYSQL_CREDENTIALS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $log_file 2>&1
|
||||||
if [[ $? -ne 0 ]] ; then
|
if [[ $? -ne 0 ]] ; then
|
||||||
@@ -762,7 +630,7 @@ if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
|
|||||||
if $_failed ; then
|
if $_failed ; then
|
||||||
|
|
||||||
echo_failed
|
echo_failed
|
||||||
error "$(cat $log_file)"
|
error "\n\n$(cat $log_file)"
|
||||||
|
|
||||||
if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then
|
if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then
|
||||||
echo ""
|
echo ""
|
||||||
@@ -772,6 +640,22 @@ if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
|
|||||||
done
|
done
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
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
|
else
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
@@ -874,7 +758,7 @@ fi
|
|||||||
|
|
||||||
# - Restore Database
|
# - 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
|
echo_wait
|
||||||
if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
|
if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
|
||||||
mysql $MYSQL_CREDENTIALS $DATABASE_NAME < \
|
mysql $MYSQL_CREDENTIALS $DATABASE_NAME < \
|
||||||
@@ -931,8 +815,90 @@ fi
|
|||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[37m\033[1mDoing some post-script tasks..\033[m"
|
echo -e "\033[37m\033[1mDoing some post-script tasks..\033[m"
|
||||||
|
|
||||||
echo ""
|
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.."
|
echononl " Restart PHP engine.."
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]]; then
|
if [[ "$PHP_ENGINE" = "FPM" ]]; then
|
||||||
if $SYSTEMD_EXISTS ; then
|
if $SYSTEMD_EXISTS ; then
|
||||||
|
|||||||
36
snippets/get-cloud-instance-to-update.sh
Normal file
36
snippets/get-cloud-instance-to-update.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
WEBSITE=
|
||||||
|
_OK=false
|
||||||
|
declare -i i=0
|
||||||
|
if [[ ${#website_arr[@]} -eq 1 ]] ; then
|
||||||
|
IFS=':' read -a _arr <<< ${website_arr[0]}
|
||||||
|
conf_file=${_arr[1]}
|
||||||
|
WEBSITE=${_arr[0]}
|
||||||
|
echo ""
|
||||||
|
echo -e "Update site \033[1m${_arr[0]}"
|
||||||
|
echo ""
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo "Which site would you like to update?"
|
||||||
|
echo ""
|
||||||
|
for _site in ${website_arr[@]} ; do
|
||||||
|
IFS=':' read -a _arr <<< ${_site}
|
||||||
|
echo " [$i] ${_arr[0]}"
|
||||||
|
((i++))
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
echononl " Eingabe: "
|
||||||
|
while ! $_OK ; do
|
||||||
|
read _IN
|
||||||
|
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
||||||
|
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
||||||
|
conf_file=${_arr[1]}
|
||||||
|
WEBSITE=${_arr[0]}
|
||||||
|
_OK=true
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo -e "\tFalsche Eingabe !"
|
||||||
|
echo ""
|
||||||
|
echononl " Eingabe: "
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
7
snippets/get-path-of-php-command.sh
Normal file
7
snippets/get-path-of-php-command.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then
|
||||||
|
PHP_BIN="/usr/local/php-${PHP_VERSION}/bin/php"
|
||||||
|
elif [[ -x "$(realpath /usr/local/php/bin/php)" ]]; then
|
||||||
|
PHP_BIN="/usr/local/php/bin/php"
|
||||||
|
else
|
||||||
|
PHP_BIN="$(which php)"
|
||||||
|
fi
|
||||||
75
snippets/get-php-major-version.sh
Normal file
75
snippets/get-php-major-version.sh
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
||||||
|
if [[ -z "$PHP_VERSION" ]] ; then
|
||||||
|
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
||||||
|
if $NGINX_IS_ENABLED ; then
|
||||||
|
|
||||||
|
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
||||||
|
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif $APACHE2_IS_ENABLED ; then
|
||||||
|
|
||||||
|
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
||||||
|
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
||||||
|
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
||||||
|
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
||||||
|
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
||||||
|
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
||||||
|
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
||||||
|
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
||||||
|
fi
|
||||||
|
if [[ -z "$PHP_VERSION" ]] ; then
|
||||||
|
|
||||||
|
if $NGINX_IS_ENABLED ; then
|
||||||
|
upstream_handler="$(grep -o -E "^[^#]*fastcgi_pass\s+[^;]+" ${VHOST_CONFIG_FILE} | awk '{print$2}' )"
|
||||||
|
for _file in $(ls /etc/nginx/conf.d/) ; do
|
||||||
|
_rp_file="$(realpath "/etc/nginx/conf.d/${_file}")"
|
||||||
|
if $(grep -q -E "\s+${upstream_handler}\s*" ${_rp_file} 2> /dev/null) ; then
|
||||||
|
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" ${_rp_file} \
|
||||||
|
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$PHP_VERSION" ]] ; then
|
||||||
|
|
||||||
|
warn "Cannot determin the PHP version\! Enter it manually"
|
||||||
|
|
||||||
|
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[32m--\033[m"
|
||||||
|
echo ""
|
||||||
|
echo "Enter the PHP main version, e.g. 7.4 or 8.2 .."
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
PHP_VERSION=
|
||||||
|
while [ "X$PHP_VERSION" = "X" ]
|
||||||
|
do
|
||||||
|
echononl " PHP main version: "
|
||||||
|
read PHP_VERSION
|
||||||
|
if [ "X$PHP_VERSION" = "X" ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
||||||
|
echo ""
|
||||||
|
PHP_VERSION=
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
97
snippets/get-webservice-environment.sh
Normal file
97
snippets/get-webservice-environment.sh
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
||||||
|
|
||||||
|
NGINX_IS_ENABLED=true
|
||||||
|
|
||||||
|
# - Determin user of the webserver
|
||||||
|
# -
|
||||||
|
nginx_binary="$(which nginx)"
|
||||||
|
if [[ -z "$nginx_binary" ]] ; then
|
||||||
|
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
||||||
|
if [[ -z "$nginx_binary" ]] ; then
|
||||||
|
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
||||||
|
nginx_binary="/usr/local/nginx/bin/nginx"
|
||||||
|
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
||||||
|
nginx_binary="/usr/local/nginx/sbin/nginx"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -x "$nginx_binary" ]] ; then
|
||||||
|
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# - Is webserver running ?
|
||||||
|
# -
|
||||||
|
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
||||||
|
if [[ "X${PID}X" = "XX" ]] ;then
|
||||||
|
IS_HTTPD_RUNNING=false
|
||||||
|
else
|
||||||
|
IS_HTTPD_RUNNING=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
||||||
|
|
||||||
|
APACHE2_IS_ENABLED=true
|
||||||
|
|
||||||
|
# - Determin user of the webserver
|
||||||
|
# -
|
||||||
|
httpd_binary="`which httpd`"
|
||||||
|
if [ -z "$httpd_binary" ]; then
|
||||||
|
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
||||||
|
if [ -z "$httpd_binary" ]; then
|
||||||
|
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
||||||
|
httpd_binary="/usr/local/apache2/bin/httpd"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ -x "$httpd_binary" ];then
|
||||||
|
|
||||||
|
# - Determin websever user
|
||||||
|
# -
|
||||||
|
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
||||||
|
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
||||||
|
|
||||||
|
# - Is webserver running ?
|
||||||
|
# -
|
||||||
|
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
||||||
|
if [[ "X${PID}X" = "XX" ]] ;then
|
||||||
|
IS_HTTPD_RUNNING=false
|
||||||
|
else
|
||||||
|
IS_HTTPD_RUNNING=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
||||||
|
|
||||||
|
echononl "continue anyway [yes/no]: "
|
||||||
|
read OK
|
||||||
|
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
||||||
|
echononl "Wrong entry! - repeat [yes/nno]: "
|
||||||
|
read OK
|
||||||
|
done
|
||||||
|
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ -n "$_HTTP_USER" ]] ; then
|
||||||
|
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
||||||
|
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
||||||
|
else
|
||||||
|
HTTP_USER=$_HTTP_USER
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$_HTTP_GROUP" ]] ; then
|
||||||
|
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
||||||
|
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
||||||
|
else
|
||||||
|
HTTP_GROUP=$_HTTP_GROUP
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$HTTP_USER
|
||||||
|
fi
|
||||||
127
unban-ip-from-redis-cache.sh
Executable file
127
unban-ip-from-redis-cache.sh
Executable file
@@ -0,0 +1,127 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# nextcloud-unban.sh
|
||||||
|
# Interaktives Skript zum gezielten Entfernen von Nextcloud-Login-/Ratelimit-Keys aus Redis
|
||||||
|
# Speichert KEINE Zugangsdaten; verwendet redis-cli (muss im PATH liegen).
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
# Farben
|
||||||
|
NC="\033[0m"
|
||||||
|
BOLD="\033[1m"
|
||||||
|
GREEN="\033[32m"
|
||||||
|
YELLOW="\033[33m"
|
||||||
|
RED="\033[31m"
|
||||||
|
CYAN="\033[36m"
|
||||||
|
|
||||||
|
function header() {
|
||||||
|
echo -e "${BOLD}${CYAN}================ Nextcloud Redis Unban Helper ================${NC}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
function footer() {
|
||||||
|
echo -e "\n${BOLD}${CYAN}=============================================================${NC}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_redis() {
|
||||||
|
if ! command -v redis-cli >/dev/null 2>&1; then
|
||||||
|
echo -e "${RED}redis-cli ist nicht installiert oder nicht im PATH. Bitte installiere redis-tools oder füge redis-cli hinzu.${NC}" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
# quick ping
|
||||||
|
if ! redis-cli PING >/dev/null 2>&1; then
|
||||||
|
echo -e "${RED}Konnte Redis nicht erreichen. Stelle sicher, dass redis läuft und redis-cli Standardverbindung funktioniert.${NC}" >&2
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function read_ip() {
|
||||||
|
local prompt="$1"
|
||||||
|
local ip
|
||||||
|
while true; do
|
||||||
|
read -rp "$prompt" ip
|
||||||
|
ip="${ip// /}"
|
||||||
|
if [[ -z "$ip" ]]; then
|
||||||
|
echo -e "${YELLOW}Keine Eingabe erkannt — bitte eine IPv4- oder IPv6-Adresse eingeben.${NC}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# basic validation: at least contains digits and ':' (for IPv6) or '.' (for IPv4)
|
||||||
|
if [[ "$ip" =~ [0-9] ]] && ( [[ "$ip" == *":"* ]] || [[ "$ip" == *"."* ]] ); then
|
||||||
|
echo "$ip"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}Ungültiges Format. Bitte IPv4 (z.B. 1.2.3.4) oder IPv6 (z.B. 2003:ab:...) eingeben.${NC}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function list_keys_for_ip() {
|
||||||
|
local ip="$1"
|
||||||
|
# pattern: any key that contains the IP
|
||||||
|
redis-cli --scan --pattern "*${ip}*" | sed '/^$/d'
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirm() {
|
||||||
|
local prompt="$1"
|
||||||
|
local yn
|
||||||
|
while true; do
|
||||||
|
read -rp "$prompt [j/N]: " yn
|
||||||
|
case "$yn" in
|
||||||
|
[JjYy]*) return 0 ;;
|
||||||
|
[Nn]* | "" ) return 1 ;;
|
||||||
|
*) echo "Bitte mit j/ja oder n/nein antworten." ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- main ---
|
||||||
|
header
|
||||||
|
check_redis
|
||||||
|
|
||||||
|
echo -e "Dieses Skript sucht Redis-Keys, die deine angegebene IP enthalten (z.B. Ratelimit-Keys von Nextcloud)\n"
|
||||||
|
|
||||||
|
IP=$(read_ip "Gib die IP-Adresse ein, die du freigeben möchtest: ")
|
||||||
|
|
||||||
|
echo -e "\n${BOLD}Suche nach passenden Redis-Keys für:${NC} ${GREEN}${IP}${NC}\n"
|
||||||
|
|
||||||
|
mapfile -t KEYS < <(list_keys_for_ip "$IP") || true
|
||||||
|
|
||||||
|
if [ ${#KEYS[@]} -eq 0 ]; then
|
||||||
|
echo -e "${YELLOW}Keine Keys gefunden, die '${IP}' enthalten.${NC}\n"
|
||||||
|
if confirm "Möchtest du stattdessen alle Keys anzeigen, die das Wort 'login' enthalten?"; then
|
||||||
|
redis-cli --scan --pattern "*login*" | sed '/^$/d' || true
|
||||||
|
fi
|
||||||
|
footer
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# schöne Ausgabe
|
||||||
|
echo -e "${BOLD}Gefundene Keys:${NC} (${#KEYS[@]})\n"
|
||||||
|
for k in "${KEYS[@]}"; do
|
||||||
|
echo -e " - ${CYAN}${k}${NC}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# bestimme Länge für Box
|
||||||
|
echo
|
||||||
|
if confirm "Diese ${#KEYS[@]} Keys wirklich löschen?"; then
|
||||||
|
# Löschen
|
||||||
|
deleted=0
|
||||||
|
failed=0
|
||||||
|
for k in "${KEYS[@]}"; do
|
||||||
|
if redis-cli DEL "$k" >/dev/null 2>&1; then
|
||||||
|
((deleted++))
|
||||||
|
echo -e "${GREEN}Gelöscht:${NC} $k"
|
||||||
|
else
|
||||||
|
((failed++))
|
||||||
|
echo -e "${RED}Fehler beim Löschen:${NC} $k"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "\n${BOLD}Ergebnis:${NC} ${GREEN}$deleted gelöschte Keys${NC}, ${RED}$failed fehlgeschlagen${NC}."
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}Abgebrochen — keine Keys wurden gelöscht.${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
footer
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ script_name="$(basename $(realpath $0))"
|
|||||||
script_dir="$(dirname $(realpath $0))"
|
script_dir="$(dirname $(realpath $0))"
|
||||||
|
|
||||||
conf_dir="${script_dir}/conf"
|
conf_dir="${script_dir}/conf"
|
||||||
|
snippet_dir="${script_dir}/snippets"
|
||||||
|
|
||||||
declare -a unsorted_website_arr
|
declare -a unsorted_website_arr
|
||||||
declare -a website_arr
|
declare -a website_arr
|
||||||
@@ -98,6 +99,12 @@ echo_skipped() {
|
|||||||
echo " [ skipped ]"
|
echo " [ skipped ]"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
echo_wait(){
|
||||||
|
if $terminal ; then
|
||||||
|
echo -en "\033[75G[ \033[5m\033[1m..\033[m ]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
fatal (){
|
fatal (){
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
@@ -185,6 +192,76 @@ blank_line() {
|
|||||||
fi
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
@@ -246,32 +323,14 @@ echo "Update Nextcloud"
|
|||||||
echo -e "\033[32m-----\033[m"
|
echo -e "\033[32m-----\033[m"
|
||||||
|
|
||||||
|
|
||||||
WEBSITE=
|
# Which cloud instance (website) would you like to update
|
||||||
_OK=false
|
#
|
||||||
echo ""
|
source ${snippet_dir}/get-cloud-instance-to-update.sh
|
||||||
echo "Which site would you like to update?"
|
|
||||||
echo ""
|
|
||||||
declare -i i=0
|
# Get full qualified PHP command
|
||||||
for _site in ${website_arr[@]} ; do
|
#
|
||||||
IFS=':' read -a _arr <<< ${_site}
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
echo " [$i] ${_arr[0]}"
|
|
||||||
((i++))
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
echononl " Eingabe: "
|
|
||||||
while ! $_OK ; do
|
|
||||||
read _IN
|
|
||||||
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
|
|
||||||
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
|
|
||||||
conf_file=${_arr[1]}
|
|
||||||
_OK=true
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
echo -e "\tFalsche Eingabe !"
|
|
||||||
echo ""
|
|
||||||
echononl " Eingabe: "
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# - Reset IFS
|
# - Reset IFS
|
||||||
@@ -374,6 +433,10 @@ if [[ ! -d ${WEB_BASE_DIR} ]] ; then
|
|||||||
fatal "Web base directory not found (parameter 'WEB_BASE_DIR')"
|
fatal "Web base directory not found (parameter 'WEB_BASE_DIR')"
|
||||||
fi
|
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
|
[[ -n "$PHP_ENGINE" ]] || PHP_ENGINE=$DEFAULT_PHP_ENGINE
|
||||||
|
|
||||||
if [[ "$DATABASE_TYPE" != "postgres" ]] && [[ "$DATABASE_TYPE" != "mysql" ]]; then
|
if [[ "$DATABASE_TYPE" != "postgres" ]] && [[ "$DATABASE_TYPE" != "mysql" ]]; then
|
||||||
@@ -394,207 +457,46 @@ if [[ "$DATABASE_TYPE" = "postgres" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NGINX_IS_ENABLED=false
|
NGINX_IS_ENABLED=false
|
||||||
APACHE2_IS_ENABLED=false
|
APACHE2_IS_ENABLED=false
|
||||||
|
|
||||||
# Check if NGINX webserver is ctive
|
# Get Webservice environment as IS_HTTPD_RUNNING, HTTP_USER, HTTP_GROUP..
|
||||||
#
|
#
|
||||||
if $(systemctl -q is-enabled nginx 2> /dev/null) ; then
|
source ${snippet_dir}/get-webservice-environment.sh
|
||||||
|
|
||||||
NGINX_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
nginx_binary="$(which nginx)"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
nginx_binary="$(ps -axu | grep -E "nginx:.*master" | grep -v grep | grep -o -E "\S+/nginx")"
|
|
||||||
if [[ -z "$nginx_binary" ]] ; then
|
|
||||||
if [[ -x "/usr/local/nginx/bin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/bin/nginx"
|
|
||||||
elif [[ -x "/usr/local/nginx/sbin/nginx" ]]; then
|
|
||||||
nginx_binary="/usr/local/nginx/sbin/nginx"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -x "$nginx_binary" ]] ; then
|
|
||||||
_HTTP_USER="$($nginx_binary -T 2> /dev/null | grep -E "^\s*user\s+\S+;" | grep -o -E "\S+;$" | sed -e 's/;$//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $nginx_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
elif $(systemctl -q is-enabled apache2 2> /dev/null) ; then
|
|
||||||
|
|
||||||
APACHE2_IS_ENABLED=true
|
|
||||||
|
|
||||||
# - Determin user of the webserver
|
|
||||||
# -
|
|
||||||
httpd_binary="`which httpd`"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
|
|
||||||
if [ -z "$httpd_binary" ]; then
|
|
||||||
if [ -x "/usr/local/apache2/bin/httpd" ]; then
|
|
||||||
httpd_binary="/usr/local/apache2/bin/httpd"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [ -x "$httpd_binary" ];then
|
|
||||||
|
|
||||||
# - Determin websever user
|
|
||||||
# -
|
|
||||||
_HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
_HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
|
|
||||||
|
|
||||||
# - Is webserver running ?
|
|
||||||
# -
|
|
||||||
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
|
|
||||||
if [[ "X${PID}X" = "XX" ]] ;then
|
|
||||||
IS_HTTPD_RUNNING=false
|
|
||||||
else
|
|
||||||
IS_HTTPD_RUNNING=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
error "Neither \033[1mapache2\033[m nor \033[1mnginx\033[m is enabled on this machine"
|
|
||||||
|
|
||||||
echononl "continue anyway [yes/no]: "
|
|
||||||
read OK
|
|
||||||
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
|
|
||||||
echononl "Wrong entry! - repeat [yes/nno]: "
|
|
||||||
read OK
|
|
||||||
done
|
|
||||||
[[ $OK = "yes" ]] || fatal "Interrupted by user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_USER" ]] ; then
|
|
||||||
if [[ -n "$HTTP_USER" ]] && [[ "$_HTTP_USER" != "$HTTP_USER" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_USER}\033[m as Webservers user. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_USER}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_USER=$_HTTP_USER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "$_HTTP_GROUP" ]] ; then
|
|
||||||
if [[ -n "$HTTP_GROUP" ]] && [[ "$_HTTP_GROUP" != "$HTTP_GROUP" ]]; then
|
|
||||||
warn "The script has determined \033[1;37m${_HTTP_GROUP}\033[m as Webservers group. This\n value differs from the value given in your configuration file, \n which is \033[1;37m${HTTP_GROUP}\033[m and takes precedence."
|
|
||||||
else
|
|
||||||
HTTP_GROUP=$_HTTP_GROUP
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$HTTP_USER
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Check PHP Version
|
# Check PHP Version
|
||||||
#
|
#
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]] ; then
|
source ${snippet_dir}/get-php-major-version.sh
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
if [[ -z "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
if $NGINX_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/etc/nginx/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="$(realpath "/etc/nginx/sites-enabled/${WEBSITE}.conf")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif $APACHE2_IS_ENABLED ; then
|
|
||||||
|
|
||||||
if [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf.php-fpm"
|
|
||||||
elif [[ -f "/usr/local/apache2/conf/vhosts/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/usr/local/apache2/conf/vhosts/${WEBSITE}.conf"
|
|
||||||
elif [[ -f "/etc/apache2/sites-enabled/${WEBSITE}.conf" ]] ; then
|
|
||||||
VHOST_CONFIG_FILE="/etc/apache2/sites-enabled/${WEBSITE}.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if [[ -n "$VHOST_CONFIG_FILE" ]] ; then
|
|
||||||
PHP_VERSION="$(grep -o -E "^[^#]*php-?[[:digit:]]{1,2}\.[[:digit:]]{1}-fpm" $VHOST_CONFIG_FILE \
|
|
||||||
| grep -o -E "[[:digit:]]{1,2}\.[[:digit:]]{1}")"
|
|
||||||
fi
|
|
||||||
if [[ -z "$PHP_VERSION" ]] ; then
|
|
||||||
|
|
||||||
warn "The PHP version was not specified and cannot be determined!"
|
|
||||||
|
|
||||||
main_version_regex="^[[:digit:]]{1,2}\.[[:digit:]]{1}$"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[32m--\033[m"
|
|
||||||
echo ""
|
|
||||||
echo "Enter the PHP main version, e.g. 7.4 or 8.0 .."
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
while [ "X$PHP_VERSION" = "X" ]
|
|
||||||
do
|
|
||||||
echononl " PHP main version: "
|
|
||||||
read PHP_VERSION
|
|
||||||
if [ "X$PHP_VERSION" = "X" ]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mInput is required !!\033[m"
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
if [[ ! $PHP_VERSION =~ $main_version_regex ]] ; then
|
|
||||||
echo ""
|
|
||||||
echo -e "\033[33m\033[1mWrong entry (${PHP_VERSION}) for main PHP version !!\033[m"
|
|
||||||
echo ""
|
|
||||||
PHP_VERSION=
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
# Get full qualified PHP command
|
||||||
fi
|
#
|
||||||
fi
|
source ${snippet_dir}/get-path-of-php-command.sh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# - Determin PHP binary
|
|
||||||
# -
|
|
||||||
if [[ -x "/usr/local/php-${PHP_VERSION}/bin/php" ]] ; then
|
|
||||||
php_binary="/usr/local/php-${PHP_VERSION}/bin/php"
|
|
||||||
else
|
|
||||||
php_binary="$(realpath "$(which php)")"
|
|
||||||
if [[ -z "$php_binary" ]]; then
|
|
||||||
if [[ -x "/usr/local/php/bin/php" ]]; then
|
|
||||||
php_binary="/usr/local/php/bin/php"
|
|
||||||
else
|
|
||||||
fatal "No PHP binary present"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ ! -x "$php_binary" ]]; then
|
|
||||||
fatal "Found PHP binary '$php_binary', but this file is not executable!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
INSTALL_DIR="${WEB_BASE_DIR}/nextcloud-${VERSION}"
|
INSTALL_DIR="${WEB_BASE_DIR}/nextcloud-${VERSION}"
|
||||||
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
CURRENT_INSTALL_DIR="$(realpath ${WEB_BASE_DIR}/nextcloud)"
|
||||||
|
|
||||||
#PRIOR_VERSION="$(basename $CURRENT_INSTALL_DIR | cut -d"-" -f2)"
|
PRIOR_VERSION="$(sudo -u $HTTP_USER ${PHP_BIN} ${WEB_BASE_DIR}/htdocs/occ --version | cut -d' ' -f2)"
|
||||||
PRIOR_VERSION="$(sudo -u $HTTP_USER /usr/local/php/bin/php ${WEB_BASE_DIR}/htdocs/occ --version | cut -d' ' -f2)"
|
|
||||||
|
|
||||||
#DATA_DIR=${WEB_BASE_DIR}/data-${VERSION}
|
DATA_DIR="$(realpath "${WEB_BASE_DIR}/data")"
|
||||||
#CURRENT_DATA_DIR="$(realpath ${WEB_BASE_DIR}/data-$PRIOR_VERSION)"
|
OLD_DATA_DIR="$(dirname "${DATA_DIR}")/data-${PRIOR_VERSION}.${backup_date}"
|
||||||
|
|
||||||
DATA_DIR=${WEB_BASE_DIR}/data
|
|
||||||
OLD_DATA_DIR=${WEB_BASE_DIR}/data-${PRIOR_VERSION}
|
# 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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -629,7 +531,8 @@ echo -e " Webserver user.......................: $HTTP_USER"
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e " PHP version..........................: $PHP_VERSION"
|
echo -e " PHP version..........................: $PHP_VERSION"
|
||||||
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
echo -e " PHP Engine...........................: $PHP_ENGINE"
|
||||||
echo -e " PHP binary...........................: $php_binary"
|
echo ""
|
||||||
|
echo -e " PHP Command..........................: $PHP_BIN"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " Databse name.........................: $DATABASE_NAME"
|
echo -e " Databse name.........................: $DATABASE_NAME"
|
||||||
echo -e " Database type........................: $DATABASE_TYPE"
|
echo -e " Database type........................: $DATABASE_TYPE"
|
||||||
@@ -847,7 +750,7 @@ if $NGINX_IS_ENABLED ; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
blank_line
|
||||||
|
|
||||||
# - Backup Database
|
# - Backup Database
|
||||||
# -
|
# -
|
||||||
@@ -886,11 +789,18 @@ elif [[ "$DATABASE_TYPE" = 'postgres' ]]; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
echo_failed
|
||||||
fatal "$(cat $log_file)"
|
error "$(cat $log_file)"
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
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
|
# - Backup old installation directory
|
||||||
@@ -902,8 +812,19 @@ if [[ $? -eq 0 ]]; then
|
|||||||
else
|
else
|
||||||
echo_failed
|
echo_failed
|
||||||
error "$(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
|
fi
|
||||||
|
|
||||||
|
blank_line
|
||||||
|
|
||||||
|
|
||||||
# - Remove symlink from old installation directory
|
# - Remove symlink from old installation directory
|
||||||
# -
|
# -
|
||||||
@@ -913,7 +834,16 @@ if [[ $? -eq 0 ]]; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -945,7 +875,16 @@ if [[ $? -eq 0 ]]; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
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
|
fi
|
||||||
|
|
||||||
# - Kopiere Verzeichnis "config" in das neue Installationsverzeichnis
|
# - Kopiere Verzeichnis "config" in das neue Installationsverzeichnis
|
||||||
@@ -1001,13 +940,22 @@ fi
|
|||||||
|
|
||||||
# - Backup Daten Verzeichnis (hardlinks - harte Dateiverweise)
|
# - Backup Daten Verzeichnis (hardlinks - harte Dateiverweise)
|
||||||
# -
|
# -
|
||||||
echononl " Copy (hardlink) data directory to '${OLD_DATA_DIR}.$backup_date'.."
|
echononl " Copy (hardlink) data directory to '${OLD_DATA_DIR}'.."
|
||||||
cp -al "${DATA_DIR}" "${OLD_DATA_DIR}.${backup_date}" > $log_file 2>&1
|
cp -al "${DATA_DIR}" "${OLD_DATA_DIR}" > $log_file 2>&1
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -1019,7 +967,16 @@ if [[ $? -eq 0 ]]; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
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
|
fi
|
||||||
|
|
||||||
# - Set Permissions on new data directory
|
# - Set Permissions on new data directory
|
||||||
@@ -1030,7 +987,16 @@ if [[ $? -eq 0 ]]; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -1043,38 +1009,145 @@ if [[ $? -eq 0 ]]; then
|
|||||||
else
|
else
|
||||||
echo_failed
|
echo_failed
|
||||||
error "$(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
|
fi
|
||||||
|
|
||||||
|
blank_line
|
||||||
|
|
||||||
|
|
||||||
# - Update Nextcloud
|
# - Update Nextcloud
|
||||||
# -
|
# -
|
||||||
echo ""
|
echo ""
|
||||||
echo " Update Nextcloud"
|
echo -e " Update Nextcloud\n"
|
||||||
su -c"/usr/local/php/bin/php ${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
|
if [[ $? -eq 0 ]]; then
|
||||||
info "Updating nextcloud core was successfully.."
|
info "Updating nextcloud core was successfully.."
|
||||||
else
|
else
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
# -----
|
||||||
|
# - (Re)install/(Re)enable some more nextcloud apps
|
||||||
|
# -----
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[37m\033[1m(Re)install/(Re)enable some more nextcloud apps..\033[m"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if $(systemctl list-units --full -all | grep -Fq "notify_push") ; then
|
||||||
|
echononl " Install notify_push app.."
|
||||||
|
if $(
|
||||||
|
sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:list \
|
||||||
|
| grep -q notify
|
||||||
|
) ; then
|
||||||
|
echo_skipped
|
||||||
|
else
|
||||||
|
sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:install notify_push > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
fatal "$(cat $log_file)"
|
fatal "$(cat $log_file)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
) ; then
|
||||||
|
echo_skipped
|
||||||
|
else
|
||||||
|
sudo -u "${HTTP_USER}" ${PHP_BIN} -f /${WEB_BASE_DIR}/htdocs/occ app:install > $log_file 2>&1
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo_ok
|
||||||
|
else
|
||||||
|
echo_failed
|
||||||
|
fatal "$(cat $log_file)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
## -----
|
echononl " Setup Nextcloud App 'notify_push'.."
|
||||||
## - (Re)install/(Re)enable some more nextcloud apps
|
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
|
||||||
#echo ""
|
echo_ok
|
||||||
#echo ""
|
else
|
||||||
#echo -e "\033[37m\033[1m(Re)install/(Re)enable some more nextcloud apps..\033[m"
|
echo_failed
|
||||||
#echo ""
|
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'
|
## - Install and enable nextcloud app 'calendar'
|
||||||
## -
|
## -
|
||||||
#_app="calendar"
|
#_app="calendar"
|
||||||
#
|
#
|
||||||
#echononl "Install nextcloud app '$_app'.."
|
#echononl "Install nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1097,7 +1170,7 @@ fi
|
|||||||
#fi
|
#fi
|
||||||
#
|
#
|
||||||
#echononl "Eanable nextcloud app '$_app'.."
|
#echononl "Eanable nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1123,7 +1196,7 @@ fi
|
|||||||
#_app="contacts"
|
#_app="contacts"
|
||||||
#
|
#
|
||||||
#echononl "Install nextcloud app '$_app'.."
|
#echononl "Install nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1146,7 +1219,7 @@ fi
|
|||||||
#fi
|
#fi
|
||||||
#
|
#
|
||||||
#echononl "Enable nextcloud app '$_app'.."
|
#echononl "Enable nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1172,7 +1245,7 @@ fi
|
|||||||
#_app="notes"
|
#_app="notes"
|
||||||
#
|
#
|
||||||
#echononl "Install nextcloud app '$_app'.."
|
#echononl "Install nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1195,7 +1268,7 @@ fi
|
|||||||
#fi
|
#fi
|
||||||
#
|
#
|
||||||
#echononl "Eanable nextcloud app '$_app'.."
|
#echononl "Eanable nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1221,7 +1294,7 @@ fi
|
|||||||
#_app="tasks"
|
#_app="tasks"
|
||||||
#
|
#
|
||||||
#echononl "Install nextcloud app '$_app'.."
|
#echononl "Install nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
||||||
#
|
#
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
@@ -1245,7 +1318,7 @@ fi
|
|||||||
#fi
|
#fi
|
||||||
#
|
#
|
||||||
#echononl "Eanable nextcloud app '$_app'.."
|
#echononl "Eanable nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1273,7 +1346,7 @@ fi
|
|||||||
# _app="richdocuments"
|
# _app="richdocuments"
|
||||||
#
|
#
|
||||||
# echononl "Install nextcloud app '$_app'.."
|
# echononl "Install nextcloud app '$_app'.."
|
||||||
# sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
# sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
||||||
# if [[ $? -eq 0 ]]; then
|
# if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
# else
|
# else
|
||||||
@@ -1296,7 +1369,7 @@ fi
|
|||||||
# fi
|
# fi
|
||||||
#
|
#
|
||||||
# echononl "Eanable nextcloud app '$_app'.."
|
# echononl "Eanable nextcloud app '$_app'.."
|
||||||
# sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
# sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
||||||
# if [[ $? -eq 0 ]]; then
|
# if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
# else
|
# else
|
||||||
@@ -1319,7 +1392,7 @@ fi
|
|||||||
# echo_skipped
|
# echo_skipped
|
||||||
# error "No Wopi URL given (variable 'WOPI_URL')."
|
# error "No Wopi URL given (variable 'WOPI_URL')."
|
||||||
# else
|
# else
|
||||||
# sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" config:app:set richdocuments wopi_url --value="$WOPI_URL" >> $log_file 2>&1
|
# sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" config:app:set richdocuments wopi_url --value="$WOPI_URL" >> $log_file 2>&1
|
||||||
# if [[ $? -eq 0 ]]; then
|
# if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
# else
|
# else
|
||||||
@@ -1347,7 +1420,7 @@ fi
|
|||||||
#_app="bruteforcesettings"
|
#_app="bruteforcesettings"
|
||||||
#
|
#
|
||||||
#echononl "Install nextcloud app '$_app'.."
|
#echononl "Install nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1370,7 +1443,7 @@ fi
|
|||||||
#fi
|
#fi
|
||||||
#
|
#
|
||||||
#echononl "Eanable nextcloud app '$_app'.."
|
#echononl "Eanable nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
||||||
#
|
#
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
@@ -1394,7 +1467,7 @@ fi
|
|||||||
#_app="announcementcenter"
|
#_app="announcementcenter"
|
||||||
#
|
#
|
||||||
#echononl "Install nextcloud app '$_app'.."
|
#echononl "Install nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:install "$_app" > $log_file 2>&1
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
#else
|
#else
|
||||||
@@ -1417,7 +1490,7 @@ fi
|
|||||||
#fi
|
#fi
|
||||||
#
|
#
|
||||||
#echononl "Eanable nextcloud app '$_app'.."
|
#echononl "Eanable nextcloud app '$_app'.."
|
||||||
#sudo -u "$HTTP_USER" "$php_binary" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
#sudo -u "$HTTP_USER" "${PHP_BIN}" "${INSTALL_DIR}/occ" app:enable "$_app" > $log_file 2>&1
|
||||||
#
|
#
|
||||||
#if [[ $? -eq 0 ]]; then
|
#if [[ $? -eq 0 ]]; then
|
||||||
# echo_ok
|
# echo_ok
|
||||||
@@ -1443,8 +1516,159 @@ fi
|
|||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\033[37m\033[1mDoing some post-update tasks..\033[m"
|
echo -e "\033[37m\033[1mDoing some post-update tasks..\033[m"
|
||||||
|
|
||||||
echo ""
|
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 .."
|
||||||
|
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.."
|
echononl " Restart PHP engine.."
|
||||||
if [[ "$PHP_ENGINE" = "FPM" ]]; then
|
if [[ "$PHP_ENGINE" = "FPM" ]]; then
|
||||||
if $SYSTEMD_EXISTS ; then
|
if $SYSTEMD_EXISTS ; then
|
||||||
@@ -1629,6 +1853,18 @@ else
|
|||||||
fi
|
fi
|
||||||
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
|
blank_line
|
||||||
clean_up 0
|
clean_up 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user