From cf621e81a3df37b77cdc97a305e10dfb27631c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sat, 17 Apr 2021 19:35:31 +0200 Subject: [PATCH] Testing (#12) * Protect config file --- manifest.json | 2 +- scripts/install | 14 +++++--------- scripts/restore | 19 ++++++++++--------- scripts/upgrade | 27 ++++++++++----------------- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/manifest.json b/manifest.json index 2576980..8b8fc4c 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Self-hosted file storage server", "fr": "Serveur de stockage de fichiers auto-hébergé" }, - "version": "12.2.0~ynh5", + "version": "12.2.0~ynh6", "url": "https://github.com/silverwind/droppy", "license": "BSD-2-Clause", "maintainer": { diff --git a/scripts/install b/scripts/install index 0ed62e5..99536a1 100644 --- a/scripts/install +++ b/scripts/install @@ -45,8 +45,8 @@ ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= ynh_script_progression --message="Storing installation settings..." --weight=2 -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=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url #================================================= # STANDARD MODIFICATIONS @@ -136,12 +136,7 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Modifying a config file..." --weight=1 -cp ../conf/config.json.example "$final_path/config/config.json" - -# Main config File -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config/config.json" - -ynh_store_file_checksum --file="$final_path/config/config.json" +ynh_add_config --template="../conf/config.json.example" --destination="$final_path/config/config.json" #================================================= # GENERIC FINALIZATION @@ -153,6 +148,7 @@ ynh_script_progression --message="Securing files and directories..." --weight=1 # Set permissions to app files chown -R $app: $final_path chmod 755 $final_path +chmod 600 $final_path/config/config.json #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -167,7 +163,7 @@ yunohost service add $app --description="Self-hosted file storage server" --log= ynh_script_progression --message="Starting a systemd service..." --weight=40 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ready for requests!" +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Ready for requests!" #================================================= # SETUP SSOWAT diff --git a/scripts/restore b/scripts/restore index 31c881f..5276b01 100644 --- a/scripts/restore +++ b/scripts/restore @@ -49,20 +49,20 @@ ynh_script_progression --message="Restoring the NGINX configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring $app main directory..." --weight=20 - -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 +ynh_system_user_create --username=$app --home_dir=$final_path + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring $app main directory..." --weight=20 + +ynh_restore_file --origin_path="$final_path" #================================================= # RESTORE USER RIGHTS @@ -97,6 +97,7 @@ systemctl enable $app.service --quiet ynh_restore_file "/home/yunohost.app/$app" chown -R $app: "/home/yunohost.app/$app" +chmod 600 $final_path/config/config.json #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -110,7 +111,7 @@ yunohost service add $app --description="Self-hosted file storage server" --log= #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=40 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Ready for requests!" +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Ready for requests!" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index e426619..66866c6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -63,6 +63,14 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=9 ynh_systemd_action --service_name=$app --action=stop --log_path=systemd +#================================================= +# 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 --home_dir=$final_path + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -94,14 +102,6 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=2 # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -#================================================= -# 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 - #================================================= # SPECIFIC UPGRADE #============================================== @@ -139,15 +139,7 @@ chown -R $app:$app "$data_path" #================================================= ynh_script_progression --message="Modifying a config file..." --weight=2 -ynh_backup_if_checksum_is_different --file="$final_path/config/config.json" - -cp ../conf/config.json.example "$final_path/config/config.json" - -# Main config File -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config/config.json" - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/config/config.json" +ynh_add_config --template="../conf/config.json.example" --destination="$final_path/config/config.json" #================================================= # SETUP SYSTEMD @@ -170,6 +162,7 @@ ynh_script_progression --message="Securing files and directories..." --weight=2 # Set permissions on app files chown -R $app:$app $final_path chmod 755 $final_path +chmod 600 $final_path/config/config.json #================================================= # INTEGRATE SERVICE IN YUNOHOST