From b97fafcd5b46b50e0cc19f74cd5d77ea7e1a9bf2 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sat, 30 May 2020 19:18:05 +0200 Subject: [PATCH] Apply last example_ynh --- manifest.json | 1 - scripts/backup | 19 +++---- scripts/change_url | 2 +- scripts/install | 95 ++++++++++++++++------------------- scripts/remove | 21 ++++---- scripts/restore | 38 +++++++------- scripts/upgrade | 122 ++++++++++++++++++++++----------------------- 7 files changed, 141 insertions(+), 157 deletions(-) diff --git a/manifest.json b/manifest.json index 79e9520..29b7f95 100644 --- a/manifest.json +++ b/manifest.json @@ -56,7 +56,6 @@ }, "default": true } - ] } } diff --git a/scripts/backup b/scripts/backup index 14f0869..b3a8400 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -19,7 +20,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Backing up The Lounge..." +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -27,11 +28,17 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) config_path=$(ynh_app_setting_get --app=$app --key=config_path) domain=$(ynh_app_setting_get --app=$app --key=domain) +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= + +ynh_print_info --message="Declaring files to be backed up..." + #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path=$final_path +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION @@ -39,12 +46,6 @@ ynh_backup --src_path=$final_path ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# BACKUP LOGROTATE -#================================================= - -ynh_backup --src_path="/etc/logrotate.d/$app" - #================================================= # BACKUP SYSTEMD #================================================= @@ -55,7 +56,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" # BACKUP CONFIG #================================================= -ynh_backup --src_path=$config_path +ynh_backup --src_path="$config_path" #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index d92c78a..85f3330 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -104,4 +104,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression --message="Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index 96e9cc6..7eb36e1 100644 --- a/scripts/install +++ b/scripts/install @@ -16,7 +16,6 @@ source /usr/share/yunohost/helpers ynh_clean_setup () { ynh_clean_check_starting } - # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -36,28 +35,11 @@ ynh_script_progression --message="Validating installation parameters..." final_path=/var/www/$app config_path=/home/yunohost.app/$app - -test ! -e "$final_path" || ynh_die "This path already contains a folder" - -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) - -# Check web path availability -ynh_webpath_available $domain $path_url +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Configuring firewall..." - -# Find a free port -port=$(ynh_find_port 9000) - -ynh_app_setting_set --app=$app --key=port --value=$port - #================================================= # STORE SETTINGS FROM MANIFEST #================================================= @@ -66,16 +48,26 @@ ynh_script_progression --message="Storing installation settings..." ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=is_public --value=$is_public -ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=config_path --value=$config_path +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# FIND AND OPEN A PORT +#================================================= +ynh_script_progression --message="Configuring firewall..." + +# Find an available port +port=$(ynh_find_port 9000) +ynh_app_setting_set --app=$app --key=port --value=$port + #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_install_nodejs --nodejs_version=$nodejs_version # Install Yarn ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" @@ -85,16 +77,34 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st #================================================= ynh_script_progression --message="Setting up source files..." -mkdir -p $final_path - -mkdir -p $config_path - +ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir=$final_path #================================================= -# COPY A CONFIG FILE +# NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Configuring nginx web server..." + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app + +#================================================= +# SPECIFIC SETUP +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_script_progression --message="Modifying a config file..." + +mkdir -p $config_path # Main config File ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js" @@ -109,27 +119,10 @@ ynh_store_file_checksum "$config_path/config.js" ynh_script_progression --message="Installing The Lounge..." pushd $final_path - -yarn install && ynh_exec_warn_less NODE_ENV=production yarn build - + yarn install + ynh_exec_warn_less NODE_ENV=production yarn build popd -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring nginx web server..." - -# Create a dedicated nginx config -ynh_add_nginx_config - #================================================= # SETUP SYSTEMD #================================================= @@ -142,25 +135,23 @@ ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path ynh_add_systemd_config -yunohost service add $app --description "Self-hosted web IRC client" --log "/var/log/$app/$app.log" - #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." # Set permissions to app files chown -R $app: $final_path chown -R $app: $config_path #================================================= -# SETUP LOGROTATE +# INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Configuring log rotation..." +ynh_script_progression --message="Integrating service in YunoHost..." -# Use logrotate to manage application logfile(s) -ynh_use_logrotate +yunohost service add $app --description "Self-hosted web IRC client" --log_type "systemd" #================================================= # START SYSTEMD SERVICE @@ -189,4 +180,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 1b25793..75eb175 100644 --- a/scripts/remove +++ b/scripts/remove @@ -24,10 +24,10 @@ config_path=$(ynh_app_setting_get --app=$app --key=config_path) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove a service from the admin panel, added by `yunohost service add` +# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then ynh_script_progression --message="Removing $app service..." @@ -53,12 +53,10 @@ ynh_remove_nodejs #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing $app main directory..." +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove --file=$final_path - -ynh_secure_remove --file=$config_path +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION @@ -69,12 +67,13 @@ ynh_script_progression --message="Removing nginx web server configuration..." ynh_remove_nginx_config #================================================= -# REMOVE LOGROTATE CONFIGURATION +# SPECIFIC REMOVE #================================================= -ynh_script_progression --message="Removing logrotate configuration..." +# REMOVE THE CONFIG FILE +#================================================= +ynh_script_progression --message="Removing the config file..." -# Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_secure_remove --file="$config_path" #================================================= # GENERIC FINALIZATION @@ -90,4 +89,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 720a610..155acb7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -16,7 +17,6 @@ source /usr/share/yunohost/helpers ynh_clean_setup () { ynh_clean_check_starting } - # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -47,6 +47,7 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the nginx configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -55,7 +56,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file --origin_path=$final_path +ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER @@ -65,6 +66,15 @@ ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create --username=$app +#================================================= +# RESTORE USER RIGHTS +#================================================= +ynh_script_progression --message="Restoring user rights..." + +# Restore permissions to app files +chown -R $app: $final_path +chown -R $app: $config_path + #================================================= # SPECIFIC RESTORATION #================================================= @@ -83,15 +93,7 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st #================================================= ynh_script_progression --message="Restoring the config path..." -ynh_restore_file --origin_path=$config_path - -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions to app files -chown -R $app: $final_path -chown -R $app: $config_path +ynh_restore_file --origin_path="$config_path" #================================================= # RESTORE SYSTEMD @@ -99,14 +101,14 @@ chown -R $app: $config_path ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" - systemctl enable $app.service #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --log "/var/log/$app/$app.log" +yunohost service add $app --description "Self-hosted web IRC client" --log_path="systemd" --line_match="Available at http" #================================================= # START SYSTEMD SERVICE @@ -115,12 +117,6 @@ ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Available at http" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= @@ -134,4 +130,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index abaf462..71f2f16 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,6 +26,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -75,7 +76,7 @@ ynh_abort_if_errors #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # STANDARD UPGRADE STEPS @@ -97,40 +98,7 @@ then ynh_secure_remove --file=$final_path # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir=$final_path -fi - -#================================================= -# COPY A CONFIG FILE -#================================================= - -# Main config File -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js" - -cp -a ../conf/config.js "$config_path" - -#================================================= -# UPGRADE NODEJS AND YARN -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -# Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version - -# Install Yarn -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" - -#================================================= -# UPGRADE THE LOUNGE -#================================================= - -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - pushd $final_path - - yarn install && ynh_exec_warn_less NODE_ENV=production yarn build - - popd + ynh_setup_source --dest_dir="$final_path" fi #================================================= @@ -141,18 +109,55 @@ ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." + +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + +# Install Yarn +ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" + #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." -# Create a system user +# Create a dedicated user (if not existing) ynh_system_user_create --username=$app +#================================================= +# SPECIFIC UPGRADE +#================================================= +# UPGRADE THE LOUNGE +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading the lounge..." + pushd $final_path + yarn install && ynh_exec_warn_less NODE_ENV=production yarn build + popd +fi + +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_script_progression --message="Modifying a config file..." + +ynh_backup_if_checksum_is_different --file="$config_path" +# Main config File +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.js" + +cp -a ../conf/config.js "$config_path" +ynh_store_file_checksum "$config_path/config.js" + #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." +ynh_script_progression --message="Upgrading systemd configuration..." ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service" @@ -161,39 +166,32 @@ ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path ynh_add_systemd_config -yunohost service add $app --description "Self-hosted web IRC client" --log "/var/log/$app/$app.log" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -### 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="$config_path/config.js" - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$config_path/config.js" - -cp -a ../conf/config.js "$config_path" - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append - #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." -# Set right permissions for curl installation +# Set permissions on app files chown -R $app: $final_path chown -R $app: $config_path +#================================================= +# SETUP SSOWAT +#================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." + +# Make app public if necessary or protect it +[ $is_public -eq 0 ] || ynh_permission_update --permission "main" --add "visitors" + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description "Self-hosted web IRC client" --log_type "systemd" + #================================================= # START SYSTEMD SERVICE #================================================= @@ -212,4 +210,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression --message="Upgrade of $app completed"