From 32354a83148b88aedf912a412978e9615decc887 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 26 Jun 2021 21:32:15 +0200 Subject: [PATCH] Fix --- scripts/install | 3 ++- scripts/restore | 28 +++++++++------------------- scripts/upgrade | 39 +++++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/scripts/install b/scripts/install index fb71df8..db08404 100755 --- a/scripts/install +++ b/scripts/install @@ -91,8 +91,9 @@ ynh_script_progression --message="Creating a MySQL database..." --weight=2 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name echo "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name #================================================= diff --git a/scripts/restore b/scripts/restore index 76edbad..5f1d6d4 100755 --- a/scripts/restore +++ b/scripts/restore @@ -51,13 +51,6 @@ test ! -d $final_path \ 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..." --weight=2 - -ynh_restore_file --origin_path="$final_path" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -67,13 +60,15 @@ ynh_script_progression --message="Recreating the dedicated system user..." --wei ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= -# RESTORE USER RIGHTS +# RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=2 -# Restore permissions on app files -chown -R root:root $final_path -mkdir -p "$final_path/lib/node_modules/facilmap-server/cache" -chown -R facilmap:facilmap "$final_path/lib/node_modules/facilmap-server/cache" +ynh_restore_file --origin_path="$final_path" + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SPECIFIC RESTORATION @@ -85,11 +80,6 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=10 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies -#================================================= -# REINSTALL NODEJS -#================================================= -ynh_script_progression --message="Installing NodeJS..." --weight=30 - ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= @@ -98,8 +88,8 @@ ynh_install_nodejs --nodejs_version=$nodejs_version ynh_script_progression --message="Restoring the MySQL database..." --weight=5 db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) - -facilmap_create_db +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +echo "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 209f4d8..4b6d3a8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -73,6 +73,14 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" # ynh_setup_source --dest_dir="$final_path" #fi +#================================================= +# 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" + #================================================= # NGINX CONFIGURATION #================================================= @@ -88,29 +96,21 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=10 ynh_install_app_dependencies $pkg_dependencies -#================================================= -# UPGRADE NODEJS -#================================================= -ynh_script_progression --message="Installing NodeJS..." --weight=40 - 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) -facilmap_create_user - #================================================= # SPECIFIC UPGRADE #================================================= # BUILD NODE DEPENDENCIES #================================================= -ynh_script_progression --message="Building node dependencies..." --weight=70 +ynh_script_progression --message="Building node dependencies..." --weight=20 + +chown -R $app $final_path + +pushd "$final_path" + ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" install --prefix "$final_path" -g facilmap-server@"$facilmap_version" +popd -facilmap_install_app #================================================= # SETUP SYSTEMD @@ -118,14 +118,15 @@ facilmap_install_app ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config -ynh_add_systemd_config --others_var="ynh_node_load_PATH" +ynh_add_systemd_config #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating config files..." --weight=2 -facilmap_add_config +mkdir -p "$final_path/etc" +ynh_add_config --template="../conf/config.env" --destination="$final_path/etc/facilmap.env" #================================================= # GENERIC FINALIZATION @@ -135,7 +136,9 @@ facilmap_add_config ynh_script_progression --message="Setting files permissions..." --weight=1 # Set permissions on app files -facilmap_set_permissions +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= # SETUP LOGROTATE