1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ghost_ynh.git synced 2024-09-03 19:16:02 +02:00

Update ynh_add_config

This commit is contained in:
yalh76 2020-06-18 00:58:38 +02:00
parent 2c10036c1a
commit 06f73c81b8
3 changed files with 29 additions and 27 deletions

View file

@ -123,7 +123,7 @@ ynh_system_user_create --username=$app
#================================================= #=================================================
ynh_script_progression --message="Modifying a config file..." ynh_script_progression --message="Modifying a config file..."
ynh_add_config --origin="../conf/config.production.json" --destination="$final_path/config.production.json" --vars="db_name db_user db_pwd" ynh_add_config --template="../conf/config.production.json" --destination="$final_path/config.production.json"
#============================================== #==============================================
# BUILD GHOST # BUILD GHOST

View file

@ -168,7 +168,7 @@ ynh_system_user_create --username=$app
#================================================= #=================================================
ynh_script_progression --message="Modifying a config file..." ynh_script_progression --message="Modifying a config file..."
ynh_add_config --origin="../conf/config.production.json" --destination="$final_path/config.production.json" --vars="db_name db_user db_pwd" ynh_add_config --template="../conf/config.production.json" --destination="$final_path/config.production.json"
#============================================== #==============================================
# BUILD GHOST # BUILD GHOST

View file

@ -16,16 +16,16 @@
# The helper will use the template $template to generate a config file # The helper will use the template $template to generate a config file
# $destination by replacing the following keywords with global variables # $destination by replacing the following keywords with global variables
# that should be defined before calling this helper : # that should be defined before calling this helper :
# __PATH__ by $path_url # __PATH__ by $path_url
# __NAME__ by $app # __NAME__ by $app
# __NAMETOCHANGE__ by $app # __NAMETOCHANGE__ by $app
# __USER__ by $app # __USER__ by $app
# __FINALPATH__ by $final_path # __FINALPATH__ by $final_path
# __PHPVERSION__ by $YNH_PHP_VERSION # __PHPVERSION__ by $YNH_PHP_VERSION
# #
# And any dynamic variables that should be defined before calling this helper like: # And any dynamic variables that should be defined before calling this helper like:
# __DOMAIN__ by $domain # __DOMAIN__ by $domain
# __APP__ by $app # __APP__ by $app
# __VAR_1__ by $var_1 # __VAR_1__ by $var_1
# __VAR_2__ by $var_2 # __VAR_2__ by $var_2
# #
@ -71,16 +71,16 @@ ynh_add_config () {
# #
# The helper will replace the following keywords with global variables # The helper will replace the following keywords with global variables
# that should be defined before calling this helper : # that should be defined before calling this helper :
# __PATH__ by $path_url # __PATH__ by $path_url
# __NAME__ by $app # __NAME__ by $app
# __NAMETOCHANGE__ by $app # __NAMETOCHANGE__ by $app
# __USER__ by $app # __USER__ by $app
# __FINALPATH__ by $final_path # __FINALPATH__ by $final_path
# __PHPVERSION__ by $YNH_PHP_VERSION # __PHPVERSION__ by $YNH_PHP_VERSION
# #
# And any dynamic variables that should be defined before calling this helper like: # And any dynamic variables that should be defined before calling this helper like:
# __DOMAIN__ by $domain # __DOMAIN__ by $domain
# __APP__ by $app # __APP__ by $app
# __VAR_1__ by $var_1 # __VAR_1__ by $var_1
# __VAR_2__ by $var_2 # __VAR_2__ by $var_2
# #
@ -116,20 +116,22 @@ ynh_replace_vars () {
# Replace othes variables # Replace othes variables
# List other unique (__ __) variables in $file # List other unique (__ __) variables in $file
local uniques_vars=( $(grep -o '__[^.]*__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" )) local uniques_vars=( $(grep -o '__[A-Z0-9]+__' $file | sort --unique | sed "s@__\([^.]*\)__@\L\1@g" ))
# Do the replacement # Do the replacement
local delimit=@ local delimit=@
for one_var in "${uniques_vars[@]}" for one_var in "${uniques_vars[@]}"
do do
if test -n "${!one_var:-}"; then # Validate that one_var is indeed defined
match_string="__${one_var^^}__" test -n "${!one_var:-}" || ynh_die --message="\$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file"
match_string=${match_string//${delimit}/"\\${delimit}"}
replace_string="${!one_var}" # Escape delimiter in match/replace string
replace_string=${replace_string//${delimit}/"\\${delimit}"} match_string="__${one_var^^}__"
sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$file" match_string=${match_string//${delimit}/"\\${delimit}"}
else replace_string="${!one_var}"
ynh_die --message="\$$one_var wasn't initialized when trying to replace __${one_var^^}__ in $file" replace_string=${replace_string//${delimit}/"\\${delimit}"}
fi
# Actually replace (sed is used instead of ynh_replace_string to avoid triggering an epic amount of debug logs)
sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$file"
done done
} }