From b7b0e172a5a34dd31b32fd115123588a60d8c34b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 12 Mar 2021 16:41:18 +0100 Subject: [PATCH] Recommend the use of ynh_add_config --- scripts/install | 33 +++++++++++++++++++-------------- scripts/upgrade | 19 ++++++++++++------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/scripts/install b/scripts/install index 22ee463..a7b45ed 100755 --- a/scripts/install +++ b/scripts/install @@ -229,24 +229,29 @@ ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" ynh_permission_update --permission="main" --remove="visitors" #================================================= -# MODIFY A CONFIG FILE +# ADD A CONFIGURATION #================================================= -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) +### You can add specific configuration files. +### +### Typically, put your template conf file in ../conf/your_config_file +### The template may contain strings such as __FOO__ or __FOO_BAR__, +### which will automatically be replaced by the values of $foo and $foo_bar +### +### ynh_add_config will also keep track of the config file's checksum, +### which later during upgrade may allow to automatically backup the config file +### if it's found that the file was manually modified +### +### Check the documentation of `ynh_add_config` for more info. -ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/CONFIG_FILE" +ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file" -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -### `ynh_store_file_checksum` is used to store the checksum of a file. -### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, -### you can make a backup of this file before modifying it again if the admin had modified it. - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/CONFIG_FILE" +### For more complex cases where you want to replace stuff using regexes, +### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### When doing so, you also need to manually call ynh_store_file_checksum +### +### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file" +### ynh_store_file_checksum --file="$final_path/some_config_file" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index fff0363..a749b70 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -159,17 +159,22 @@ ynh_script_progression --message="Upgrading systemd configuration..." --time --w ynh_add_systemd_config #================================================= -# MODIFY A CONFIG FILE +# UPDATE A CONFIG FILE #================================================= -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" +### Same as during install +### +### The file will automatically be backed-up if it's found to be manually modified (because +### ynh_add_config keeps track of the file's checksum) -ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/CONFIG_FILE" +ynh_add_config --template="some_config_file" --destination="$final_path/some_config_file" -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/CONFIG_FILE" +### For more complex cases where you want to replace stuff using regexes, +### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### When doing so, you also need to manually call ynh_store_file_checksum +### +### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file" +### ynh_store_file_checksum --file="$final_path/some_config_file" #================================================= # GENERIC FINALIZATION