Commit 2de02c7f authored by Daniel's avatar Daniel

Update overlay/root/scripts/nc_tuning.sh, overlay/root/scripts/nc_config.sh,...

Update overlay/root/scripts/nc_tuning.sh, overlay/root/scripts/nc_config.sh, overlay/root/scripts/functions.sh files
Deleted overlay/nextcloud/templates/autoconfig.php
parent 1960f73a
# autoconfiguration file for nextcloud
#
# create database user and password in advance!
#
# https://docs.nextcloud.com/server/20/admin_manual/configuration_server/automatic_configuration.html?highlight=autoconfig
#
# copy this to the nextcloud/config directory
<?php
$AUTOCONFIG = array(
"dbtype" => "CHANGE__DB_TYPE__",
"dbname" => "CHANGE__DB_NAME__",
"dbuser" => "CHANGE__DB_ROOT__",
"dbpass" => "CHANGE__DB_ROOT_PW__",
"dbhost" => "localhost",
"dbtableprefix" => "oc",
"adminlogin" => "CHANGE__NC_ROOT__",
"adminpass" => "CHANGE__NC_ROOT_PW__",
"directory" => "CHANGE__dir_nextcloud_data__",
);
......@@ -3,6 +3,8 @@
# some function definitions
###
cerr(){ >&2 echo "$@" ;}
# function to generate secret values
# returns existing secret
generate_secret()
......@@ -116,30 +118,129 @@ conf_activate()
file_conf=$1; option=$2;
sed -i '.sedbkp' -e "s|.*\(${option}.*\)|\1|g" $file_conf
}
conf_update()
{
file_conf=$1; option=$2; new_val=$3; add_after=$4
# check input
if [ ! -e "$file_conf" ]; then echo "config '${file_conf}' does not exits!"; return; fi
# if [ -z "$option" ]; then echo "no option passed!"; return; fi
# if empty, try to read from stdin, cat prints /dev/stdin and sed escapes \n
if [ -z "$new_val" ]; then new_val=$(cat | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g'); fi
#echo $new_val
# check if the option is present in the config file
option_has_entry=false
current_val=$(cat ${file_conf} | grep "${option}")
if [ -n "$option" ] && [ -n "$current_val" ]; then option_has_entry=true; fi
# if there is an entry, then replace the existing values
if $option_has_entry
then
sed -i '.sedbkp' "s|\(.*\)\(${option}\).*|\1\2${new_val}|g" $file_conf
conf_update(){
option_end=""
assignment_char="="
print_only=false
backup_ext=""
debug=false
while [ "$1" != "" ]; do
case "${1}" in
-c | --config) file_conf=$2; ;;
-o | --option) option=$2; ;;
-v | --new-val) new_val=$2; ;;
-e | --option-end) option_end=$2; ;;
-a | --assignment-char) assignment_char=$2; ;;
-b | --backup-extension) backup_ext=$2; ;;
--add-after) add_after=$2; ;;
--add-before) add_before=$2; ;;
-d | --debug) debug=true; shift; continue; ;;
-p | --print-only) print_only=true; shift; continue; ;;
*) echo "ERROR: unknown parameter '$1'"; return 1; ;;
esac
shift 2
done
# DO NOT ECHO BEFORE THIS LINE
# if the option for the new value does not exist, try to read it from stdin
# and escapt newlines for sed
if [ -z "${new_val}" ]; then
#cerr reading from stdin
#new_val=`cat | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g'`
fi
# check input parameters
if [ ! -f "${file_conf}" ]; then
echo "config '${file_conf}' does not exits!"
return 1
fi
if [ -n "${add_after}" ] && [ -n "${add_before}" ]; then
echo "only one of '--add-after' '--add-before' is allowed!";
return 1
fi
if [ -n "${option}" ] && [ -n "${add_after}" ]; then
echo "DO NOT set 'option' if using '--add-after' or '--add-before'!";
return 1
fi
if [ -n "${option}" ] && [ -n "${add_before}" ]; then
echo "DO NOT set 'option' if using '--add-after' or '--add-before'!";
return 1
fi
# check if the option is present in the config file, if not error
current_entry="$(cat ${file_conf} | grep ${option})"
if [ -n "$option" ] && [ -z "$current_entry" ]; then
echo "option '${option}' does not exist in '${file_conf}'!"
echo "add either '--add-after' or '--add-before' to insert a new value!"
return 1
fi
# if there is no new value for an existing option, print current entry and exit
if [ -n "$option" ] && [ -z "$new_val" ]; then
echo "Now new value was entered for option '${option}'!"
echo "The script contains the following options containing '${option}'"
echo "$current_entry"
return 1
fi
# with this, an empty option will print all options of the config file
# without setting -p
if [ -z "${option}" ]; then
print_only=true
fi
if $debug; then
echo conf: $file_conf
echo option: $option
echo value: $new_val
echo pipe_val: $pipe_val
echo after: $add_after
echo before: $add_before
echo end_char: $option_end
echo assign_char: $assignment_char
echo backup_ext: $backup_ext
fi
##################
# user add a new entry
##################
# add the new value in the lines before the add_before value
if [ -n "${add_before}" ]; then
if $print_only; then
sed -n -e "s|.*${add_after}.*|${new_val}\n&|gp" $file_conf
else
sed -i "${backup_ext}" -e "s|.*${add_after}.*|${new_val}\n&|g" $file_conf
fi
return 0
fi
# add the new value in the lines after the add_after value
if [ -n "${add_after}" ]; then
if $print_only; then
sed -n -e "s|.*${add_after}.*|&\n${new_val}|gp" $file_conf
else
sed -i "$backup_ext" -e "s|.*${add_after}.*|&\n${new_val}|g" $file_conf
fi
return 0
fi
##################
# user wants to update an existing value
##################
# remove all spaces
# "s|\([^[:space:]]*\)[[:space:]]*\([^[:space:]]*\)|\1 \2|g"
if $print_only; then
sed -n -e "s|\(.*\)\(${option}\)\([[:space:]]*\)${assignment_char}.*|\1\2${assignment_char}${new_val}${option_end}|gp" $file_conf
else
# check if after was passed
if [ -z "$add_after" ]; then echo "add_after not set!"; return; fi
sed -i '.sedbkp' -e "s|.*${add_after}.*|&\n${option}${new_val}|g" $file_conf
fi
# 1. everything before the option
# 2. option
# 3. whitespaces between option and assignment_char
sed -i "$backup_ext" "s|\(.*\)\(${option}\)\([[:space:]]*\)${assignment_char}.*|\1\2${assignment_char}${new_val}${option_end}|g" $file_conf
fi
return 0
}
conf_update_enable()
......
......@@ -6,7 +6,13 @@ echo; echo "nextcloud: setup php-fpm config"
# change /usr/local/etc/php-fpm.d/nextcloud.conf
# create a backup
cp ${file_php_fpm_nc_conf} "${file_php_fpm_nc_conf}.bkp"
conf_update ${file_php_fpm_nc_conf} "env[PATH][[:SPACE:]]=" "$PATH"
conf_update ${file_php_fpm_nc_conf} "php_admin_value[session.save_path].*=" "$dir_nextcloud_sessions"
conf_update ${file_php_fpm_nc_conf} "env[PATH].*=" "$PATH"
change_config_value_by_vars ${file_php_fpm_nc_conf}
php_admin_value[session.save_path]
service php-fpm restart 1>/dev/null
sleep 5
......
......@@ -25,8 +25,8 @@ conf_update_enable ${file_php_conf} "opcache.memory_consumption.*=" "128"
conf_update_enable ${file_php_conf} "opcache.save_comments.*=" "1"
conf_update_enable ${file_php_conf} "opcache.revalidate_freq.*=" "1"
service php-fpm restart
service nginx restart
service php-fpm restart 1>/dev/null
service nginx restart 1>/dev/null
echo "tuning: fpm"
# php-fpm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment