From e812f063c07214718d00c26909a9c9c67116e3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 27 Nov 2020 12:41:05 +0100 Subject: [PATCH] Testing (#11) - Added php helper to install the php provide the php file for the app Co-authored-by: anmol26s --- manifest.json | 2 +- scripts/_common.sh | 2 +- scripts/backup | 7 +++++++ scripts/install | 25 ++++++++++++++++++++++++- scripts/remove | 19 +++++++++++++++++++ scripts/restore | 19 ++++++++++++++----- scripts/upgrade | 32 ++++++++++++++++++++++++++++++-- sources/allnotes.json | 1 + 8 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 sources/allnotes.json diff --git a/manifest.json b/manifest.json index 1f1c8b5..9f47ed0 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Generic sticky notes for all purpose", "fr": "Des post-its génériques à tout faire" }, - "version": "1.0~ynh1", + "version": "1.0~ynh2", "url": "https://github.com/YunoHost-Apps/chtickynotes_ynh/", "license": "MIT", "developer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..30b0afa 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -3,7 +3,7 @@ #================================================= # COMMON VARIABLES #================================================= - +YNH_PHP_VERSION="7.3" #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index e9b4a77..2533458 100644 --- a/scripts/backup +++ b/scripts/backup @@ -24,6 +24,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -42,6 +43,12 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# BACKUP THE PHP-FPM CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 9ff9fc3..50d83cc 100644 --- a/scripts/install +++ b/scripts/install @@ -13,6 +13,11 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ### Remove this function if there's nothing to clean before calling the remove script. + true +} +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= @@ -63,11 +68,29 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2 # Create a dedicated NGINX config ynh_add_nginx_config +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=1 + +# Create a system user +ynh_system_user_create --username=$app + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Upgrading PHP-FPM configuration..." + +# Create a dedicated php-fpm config +ynh_add_fpm_config --usage=low --footprint=low + + #================================================= # SECURE FILES AND DIRECTORIES #================================================= -chown -R www-data: $final_path +# Set right permissions for curl install +chown -R $app: $final_path #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 55b082a..28bb30b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -27,6 +27,15 @@ ynh_script_progression --message="Removing ChtickyNotes main directory..." --wei # Remove the app directory securely ynh_secure_remove --file="$final_path" +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Removing php-fpm configuration..." --weight=1 + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config + + #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -35,6 +44,16 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= +ynh_script_progression --message="Removing the dedicated system user..." --weight=1 + +# Delete a system user +ynh_system_user_delete --username=$app + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 38cd912..080f407 100644 --- a/scripts/restore +++ b/scripts/restore @@ -25,6 +25,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -51,27 +52,35 @@ ynh_script_progression --message="Restoring ChtickyNotes main directory..." --we ynh_restore_file --origin_path="$final_path" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app + #================================================= # RESTORE USER RIGHTS #================================================= # Restore permissions on app files -chown -R www-data: $final_path +chown -R $app: $final_path #================================================= -# INTEGRATE SERVICE IN YUNOHOST +# RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 73862e1..1a6fccb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,6 +18,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= @@ -60,13 +61,28 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app + +#================================================= +# PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Configuring PHP-FPM..." + +# Create a dedicated PHP-FPM config +ynh_add_fpm_config --usage=low --footprint=low + #================================================= # SECURE FILES AND DIRECTORIES #================================================= -mkdir -p $final_path cp -a ../sources/* $final_path -chown -R www-data: $final_path +chown -R $app: $final_path #================================================= # NGINX CONFIGURATION @@ -76,6 +92,18 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated nginx config ynh_add_nginx_config +#================================================= +# SETUP SSOWAT +#================================================= +ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 + +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" +fi + #================================================= # RELOAD NGINX #================================================= diff --git a/sources/allnotes.json b/sources/allnotes.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/sources/allnotes.json @@ -0,0 +1 @@ +[] \ No newline at end of file