Commit 1ec3bb19 authored by Daniel's avatar Daniel

Update overlay/root/scripts/redis_config.sh, overlay/root/scripts/functions.sh files

parent fee2ac76
......@@ -120,25 +120,34 @@ conf_activate()
}
conf_update(){
option_end=""
assignment_char="="
print_only=false
backup_ext=""
debug=false
local file_conf=""; local option=""; local new_val=""; local add_after=""; local add_before="";
local option_end=""
local assignment_char="="
local backup_ext=""
local print_only=false
local debug=false
local activate_option=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; ;;
-v | --value) new_val=$2; ;;
-e | --end-char) 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; ;;
--debug) debug=true; shift; continue; ;;
-p | --print-only) print_only=true; shift; continue; ;;
*) echo "ERROR: unknown parameter '$1'"; return 1; ;;
--activate) activate_option=true; shift; continue; ;;
*)
if [ "$1" == "-*" ]; then echo "ERROR: unknown parameter '$1'"; return 1; fi
# accept config as last parameter without -c
if [ $# -eq 1 ]; then file_conf="$1"; break; fi
if [ $# -eq 2 ]; then file_conf="$1"; option="$2"; debug=true; break; fi
if [ $# -eq 3 ]; then file_conf="$1"; option="$2"; new_val="$3"; break; fi
;;
esac
shift 2
done
......@@ -169,7 +178,7 @@ conf_update(){
fi
# check if the option is present in the config file, if not error
current_entry="$(cat ${file_conf} | grep ${option})"
local 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!"
......@@ -189,17 +198,18 @@ conf_update(){
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
echo " -c | --config : '${file_conf}'"
echo " -o | --option : '${option}'"
echo " -v | --value : '${new_val}'"
echo " -e | --end-char : '${pipe_val}'"
echo " -a | --assignment-char : '${add_after}'"
echo "-b | --backup-extension : '${backup_ext}'"
echo " --add-before : '${add_before}'"
echo " --add-after : '${option_end}'"
echo " --activate : '${activate_option}'"
echo " -p | --print-only : '${print_only}'"
fi
##################
......@@ -232,14 +242,19 @@ conf_update(){
# remove all spaces
# "s|\([^[:space:]]*\)[[:space:]]*\([^[:space:]]*\)|\1 \2|g"
local ret_order="\1\2"
if $activate_option; then local ret_order="\2"; fi
if $print_only; then
sed -n -e "s|\(.*\)\(${option}\)\([[:space:]]*\)${assignment_char}.*|\1\2${assignment_char}${new_val}${option_end}|gp" $file_conf
sed -n -e "s|\(.*\)\(${option}\)\([[:space:]]*\)${assignment_char}.*|${ret_order}${assignment_char}${new_val}${option_end}|gp" $file_conf
else
# 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
# 1. everything before the option
# 2. option
# 3. whitespaces between option and assignment_char
sed -i "$backup_ext" "s|\(.*\)\(${option}\)\([[:space:]]*\)${assignment_char}.*|${ret_order}${assignment_char}${new_val}${option_end}|g" $file_conf
fi
return 0
}
......
......@@ -3,8 +3,8 @@
echo "redis: starting setup"
# install redis
echo "redis: installing packages"
pkg install redis php74-pecl-redis
#echo "redis: installing packages"
#pkg install redis php74-pecl-redis
# enable redis service
sysrc redis_enable=YES
......@@ -23,16 +23,15 @@ echo "redis: setup redis config"
# setup redis config file
if [ ! -f "$file_redis_conf" ]; then cp "${file_redis_conf}.sample" ${file_redis_conf}; fi
#
sed -i .orig 's/^bind .*/bind 127.0.0.1/' ${file_redis_conf}
conf_update -a ' ' --activate ${file_redis_conf} ^bind 127.0.0.1
# Disable Redis listening on TCP by setting 'port' to 0
sed -i .orig 's/^port .*/port 0/' ${file_redis_conf}
conf_update -a ' ' --activate ${file_redis_conf} ^port 0
#
# Enable Redis unix socket
conf_update_enable -c ${file_redis_conf} -o "unixsocket" -v "${file_redis_sock}" -a " "
conf_update -a ' ' --activate ${file_redis_conf} unixsocket ${file_redis_sock}
#
# Grant permission to the socket to all members of the redis group
conf_update_enable -c ${file_redis_conf} -o "unixsocketperm" -v "770" -a " "
conf_update -a ' ' --activate ${file_redis_conf} unixsocketperm 770
echo "redis: register redis in nextcloud"
# set caching
......
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