diff --git a/scripts/backup b/scripts/backup index a675fe7..87926d7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= diff --git a/scripts/change_url b/scripts/change_url index b2c6c33..f009a85 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -4,8 +4,6 @@ ## new location is available via $domain and $path (or $new_domain and $new_path variables if you want to be explicit) ## old values are available via, you guessed it, $old_domain and $old_path -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -13,12 +11,10 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" @@ -33,17 +29,13 @@ ynh_change_url_nginx_config #================================================= # SPECIFIC MODIFICATIONS #================================================= -# ... -#================================================= ## do any changes to files that reference specific installation domain/path, i.e. regenerate configs etc -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" diff --git a/scripts/config b/scripts/config index 29f78f8..48be2ff 100644 --- a/scripts/config +++ b/scripts/config @@ -8,8 +8,6 @@ # (validation of several interdependent fields, specific getter/setter for a value, # display dynamic informations or choices, pre-loading of config type .cube... ). -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 923f4d6..5e20de5 100755 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -37,8 +35,6 @@ source /usr/share/yunohost/helpers foo="bar" ynh_app_setting_set --app=$app --key=foo --value=$foo -#================================================= -# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -56,6 +52,38 @@ ynh_setup_source --dest_dir="$install_dir" ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" +#================================================= +# APP INITIAL CONFIGURATION +#================================================= +ynh_script_progression --message="Adding $app's configuration files..." --weight=1 + +### 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_add_config --template="some_config_file" --destination="$install_dir/some_config_file" + +# FIXME: this should be handled by the core in the future +### You may need to use chmod 600 instead of 400, +### for example if the app is expected to be able to modify its own config +chmod 400 "$install_dir/some_config_file" +chown "$app:$app" "$install_dir/some_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="$install_dir/some_config_file" +### ynh_store_file_checksum --file="$install_dir/some_config_file" + #================================================= # SYSTEM CONFIGURATION #================================================= @@ -132,40 +160,6 @@ ynh_use_logrotate # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" -#================================================= -# APP INITIAL CONFIGURATION -#================================================= -# ADD A CONFIGURATION -#================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 - -### 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_add_config --template="some_config_file" --destination="$install_dir/some_config_file" - -# FIXME: this should be handled by the core in the future -### You may need to use chmod 600 instead of 400, -### for example if the app is expected to be able to modify its own config -chmod 400 "$install_dir/some_config_file" -chown "$app:$app" "$install_dir/some_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="$install_dir/some_config_file" -### ynh_store_file_checksum --file="$install_dir/some_config_file" - #================================================= # SETUP APPLICATION WITH CURL #================================================= @@ -179,12 +173,10 @@ chown "$app:$app" "$install_dir/some_config_file" ynh_script_progression --message="Finalizing installation..." --weight=1 ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" -#================================================= -# GENERIC FINALIZATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ### `ynh_systemd_action` is used to start a systemd service for an app. ### Only needed if you have configure a systemd service diff --git a/scripts/remove b/scripts/remove index 9369d1b..828d42f 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= diff --git a/scripts/restore b/scripts/restore index 29e7bca..c4c090a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -77,8 +75,6 @@ ynh_restore_file --origin_path="/etc/$app/" ### For other apps, the simple way is better: ynh_restore_file --origin_path="/var/log/$app/" -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 72469be..fab8a9a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,6 @@ #!/bin/bash -#================================================= -# GENERIC START + #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -30,7 +29,12 @@ source /usr/share/yunohost/helpers # upgrade_type=$(ynh_check_app_version_changed) #================================================= -# STANDARD UPGRADE STEPS +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 + +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -52,15 +56,6 @@ source /usr/share/yunohost/helpers # ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir # fi -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 - -ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" - -#================================================= -# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -74,31 +69,10 @@ ynh_setup_source --dest_dir="$install_dir" ### ownership to all files such as after the ynh_setup_source step chown -R "$app:www-data" "$install_dir" -#================================================= -# REAPPLY SYSTEM CONFIGURATIONS -#================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 - -### This should be a literal copypaste of what happened in the install's "System configuration" section - -ynh_add_fpm_config - -ynh_add_nginx_config - -ynh_add_systemd_config - -yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" - -ynh_use_logrotate --non-append - -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" - -#================================================= -# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=1 +ynh_script_progression --message="Updating $app's configuration files..." --weight=1 ### Same as during install ### @@ -120,10 +94,29 @@ chown "$app:$app" "$install_dir/some_config_file" ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" ### ynh_store_file_checksum --file="$install_dir/some_config_file" +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +### This should be a literal copypaste of what happened in the install's "System configuration" section + +ynh_add_fpm_config + +ynh_add_nginx_config + +ynh_add_systemd_config + +yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" + +ynh_use_logrotate --non-append + +ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" + #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"