From f6f83b1484ea83187386d6d34828dbbf4de926e1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 9 Apr 2021 22:31:57 +0200 Subject: [PATCH] apply example_ynh --- README.md | 4 +-- check_process | 8 +++--- manifest.json | 27 +++---------------- scripts/backup | 2 +- scripts/change_url | 20 +++++++------- scripts/install | 66 ++++++++++++++++++---------------------------- scripts/remove | 7 +++-- scripts/restore | 26 ++++++++---------- scripts/upgrade | 38 ++++++++++++-------------- 9 files changed, 76 insertions(+), 122 deletions(-) diff --git a/README.md b/README.md index 0db18a5..7f224d6 100755 --- a/README.md +++ b/README.md @@ -39,8 +39,8 @@ LDAP is activated but HTTP auth is not supported #### Supported architectures -* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/plume%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/plume/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/plume%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/plume/) +* x86-64 - [![Build Status](https://ci-apps.yunohost.org/ci/logs/plume.svg)](https://ci-apps.yunohost.org/ci/apps/plume/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/plume.svg)](https://ci-apps-arm.yunohost.org/ci/apps/plume/) ## Limitations diff --git a/check_process b/check_process index eed099f..4f99234 100755 --- a/check_process +++ b/check_process @@ -1,7 +1,7 @@ ;; Test complet ; Manifest domain="domain.tld" (DOMAIN) - admin="john" (USER) + admin="john" (USER) is_public=1 (PUBLIC|public=1|private=0) password="pass" name="my blog" @@ -23,10 +23,10 @@ backup_restore=1 multi_instance=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Options -Email=anmol@datamol.org;yalh@yahoo.com -Notification=yes +Email= +Notification=none ;;; Upgrade options ; commit=279716dff5fc79cc84ae2d7799c8094017ac028e name=0.3.0-alpha-2~ynh1 diff --git a/manifest.json b/manifest.json index 19353db..d5e1d8e 100755 --- a/manifest.json +++ b/manifest.json @@ -9,14 +9,9 @@ "version": "0.6.0~ynh1", "url": "https://joinplu.me/", "license": "AGPL-3.0-only", - "maintainer": [ - { - "name": "Anmol Sharma", - "email": "anmol@datamol.org" - }, - { - "name": "yalh76" - }], + "maintainer": { + "name": "yalh76" + }, "requirements": { "yunohost": ">= 4.1.3" }, @@ -29,37 +24,21 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain name for Plume", - "fr": "Choisissez un nom de domaine pour Plume" - }, "example": "example.com" }, { "name": "admin", "type": "user", - "ask": { - "en": "Choose the Plume administrator (must be an existing YunoHost user)", - "fr": "Choisissez l'administrateur de Plume (doit ĂȘtre un utilisateur YunoHost existant)" - }, "example": "johndoe" }, { "name": "is_public", "type": "boolean", - "ask": { - "en": "Is it a public application?", - "fr": "Est-ce une application publique ?" - }, "default": true }, { "name": "password", "type": "password", - "ask": { - "en": "Set the administrator password", - "fr": "DĂ©finissez le mot de passe administrateur" - }, "example": "Choose a password" }, { diff --git a/scripts/backup b/scripts/backup index f9f415a..37a5e95 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# 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 diff --git a/scripts/change_url b/scripts/change_url index 56ca613..53e96df 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -35,9 +35,9 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -45,7 +45,7 @@ ynh_clean_setup () { # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script @@ -79,23 +79,23 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --li #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." +ynh_script_progression --message="Updating NGINX web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf -# Change the path in the nginx config file +# Change the path in the NGINX config file if [ $change_path -eq 1 ] then - # Make a backup of the original nginx config file if modified + # Make a backup of the original NGINX config file if modified ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for nginx helper + # Set global variables for NGINX helper domain="$old_domain" path_url="$new_path" - # Create a dedicated nginx config + # Create a dedicated NGINX config ynh_add_nginx_config fi -# Change the domain for nginx +# Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location @@ -132,7 +132,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --l #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/install b/scripts/install index f0e46c3..93626c8 100755 --- a/scripts/install +++ b/scripts/install @@ -72,7 +72,7 @@ ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Finding an available port ..." +ynh_script_progression --message="Finding an available port..." # Find an available port port=$(ynh_find_port --port=8095) @@ -81,10 +81,18 @@ ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies ..." +ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CREATE A POSTGRESQL DATABASE #================================================= @@ -101,7 +109,7 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files ..." +ynh_script_progression --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src @@ -120,22 +128,18 @@ chmod +x $final_path/.cargo/bin/* # Remove empty bin directory ynh_secure_remove --file="$final_path/$app/bin/" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." +ynh_script_progression --message="Configuring NGINX web server..." -# Create a dedicated nginx config +# 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 --home_dir="$final_path" - #================================================= # SPECIFIC SETUP #================================================= @@ -145,20 +149,6 @@ ynh_system_user_create --username=$app --home_dir="$final_path" mkdir -p "/var/log/$app" chown -R "$app":"$app" "/var/log/$app" -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_script_progression --message="Modifying a config file..." - -# setup application config -config_file="$final_path/$app/.env" -cp "../conf/.env" $config_file -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file=$config_file -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file=$config_file -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file=$config_file -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=$config_file -ynh_replace_string --match_string="__SECRET_KEY__" --replace_string="$secret_key" --target_file=$config_file - #================================================= # MAKE SETUP #================================================= @@ -196,23 +186,17 @@ ynh_script_progression --message="Configuring a systemd service..." ynh_add_systemd_config #================================================= -# STORE THE CONFIG FILE CHECKSUM +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Storing the config file checksum..." +ynh_script_progression --message="Adding a config file..." -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file=$config_file +#ynh_add_config --template="../conf/.env" --destination="$final_path/$app/.env" + +chmod 400 "$final_path/$app/.env" +chown $app:$app "$final_path/$app/.env" #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions to app files -chown -R $app: $final_path - #================================================= # SETUP LOGROTATE #================================================= @@ -226,7 +210,7 @@ ynh_use_logrotate #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Plume" --log "/var/log/$app/$app.log" +yunohost service add $app --description="$app daemon for Plume" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -251,7 +235,7 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/remove b/scripts/remove index c41a2f0..eb4e008 100755 --- a/scripts/remove +++ b/scripts/remove @@ -28,7 +28,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove the service from the list of services known by Yunohost (added from `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 integration..." @@ -80,9 +80,9 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." +ynh_script_progression --message="Removing NGINX web server configuration..." -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= @@ -102,7 +102,6 @@ ynh_script_progression --message="Removing various files..." # Remove the log files ynh_secure_remove --file="/var/log/$app" -ynh_secure_remove --file="/var/log/$app/" #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index 645101a..08a9642 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source ../settings/scripts/ynh_detect_arch__2 source /usr/share/yunohost/helpers @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -50,17 +50,10 @@ test ! -d $final_path \ #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the nginx configuration..." +ynh_script_progression --message="Restoring the NGINX web server configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring the app main directory..." - -ynh_restore_file --origin_path="$final_path" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -70,12 +63,15 @@ ynh_script_progression --message="Recreating the dedicated system user..." ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= -# RESTORE USER RIGHTS +# RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring user rights..." +ynh_script_progression --message="Restoring the app main directory..." -# Restore permissions on app files -chown -R "$app":"$app" $final_path +ynh_restore_file --origin_path="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" #================================================= # CREATE LOG FOLDER @@ -117,7 +113,7 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Plume" --log "/var/log/$app/$app.log" +yunohost service add $app --description="$app daemon for Plume" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 92f2f6a..14998de 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -73,7 +73,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup ynh_clean_check_starting } @@ -89,6 +89,14 @@ ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped plume" +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -108,12 +116,16 @@ then ynh_secure_remove --file="$final_path/$app/bin/" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R root:$app "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading NGINX web server configuration..." -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= @@ -123,14 +135,6 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" - #================================================= # SPECIFIC UPGRADE #================================================= @@ -175,14 +179,6 @@ ynh_add_systemd_config #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions on app files -chown -R "$app":"$app" "$final_path" - #================================================= # SETUP LOGROTATE #================================================= @@ -196,7 +192,7 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Plume" --log "/var/log/$app/$app.log" +yunohost service add $app --description="$app daemon for Plume" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE @@ -208,7 +204,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --l #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload