Merge pull request #145 from YunoHost/misc-enh

Recommend ynh_add_config, misc cleanup/notes
This commit is contained in:
Alexandre Aubin 2021-03-15 02:27:57 +01:00 committed by GitHub
commit 611e69cd71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 30 deletions

View File

@ -216,18 +216,10 @@ ynh_add_systemd_config
### so we're going to use curl to automatically fill the fields and submit the ### so we're going to use curl to automatically fill the fields and submit the
### forms. ### forms.
# Set right permissions for curl install
chown -R $app: $final_path
# Set the app as temporarily public for curl call # Set the app as temporarily public for curl call
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
# Making the app public for curl # Making the app public for curl
ynh_permission_update --permission="main" --add="visitors" ynh_permission_update --permission="main" --add="visitors"
# Reload SSOwat config
yunohost app ssowatconf
# Reload NGINX
ynh_systemd_action --service_name=nginx --action=reload
# Installation with curl # Installation with curl
ynh_script_progression --message="Finalizing installation..." --time --weight=1 ynh_script_progression --message="Finalizing installation..." --time --weight=1
@ -237,24 +229,29 @@ ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
ynh_permission_update --permission="main" --remove="visitors" 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. ### You can add specific configuration files.
### (It's compatible with sed regular expressions syntax) ###
### 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"
#================================================= ### For more complex cases where you want to replace stuff using regexes,
# STORE THE CONFIG FILE CHECKSUM ### 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_store_file_checksum` is used to store the checksum of a file. ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file"
### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, ### ynh_store_file_checksum --file="$final_path/some_config_file"
### 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"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -290,7 +287,7 @@ ynh_use_logrotate
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
### `yunohost service add` integrates a service in YunoHost. It then gets ### `yunohost service add` integrates a service in YunoHost. It then gets
### displayed in the admin interface and through the others `yunohost service` commands. ### displayed in the admin interface and through the others `yunohost service` commands.
### (N.B.: this line only makes sense if the app adds a service to the system!) ### (N.B.: this line only makes sense if the app adds a service to the system!)
### If you're not using these lines: ### If you're not using these lines:
@ -354,6 +351,9 @@ then
ynh_permission_update --permission="main" --add="visitors" ynh_permission_update --permission="main" --add="visitors"
fi fi
### N.B. : the following extra permissions only make sense if your app
### does have for example an admin interface or an api.
# Only the admin can access the admin panel of the app (if the app has an admin panel) # Only the admin can access the admin panel of the app (if the app has an admin panel)
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin

View File

@ -159,17 +159,22 @@ ynh_script_progression --message="Upgrading systemd configuration..." --time --w
ynh_add_systemd_config 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. ### Same as during install
### 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" ### 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. ### For more complex cases where you want to replace stuff using regexes,
ynh_store_file_checksum --file="$final_path/CONFIG_FILE" ### 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 # GENERIC FINALIZATION