diff --git a/conf/garradin_migrations b/conf/garradin_migrations index 7688cf8..96f1226 100644 --- a/conf/garradin_migrations +++ b/conf/garradin_migrations @@ -1,2 +1,7 @@ +# App main directory +/var/www/$app + +# NGINX web server configuration /etc/nginx/conf.d/$domain.d/$app.conf -/etc/php/8.0/fpm/pool.d/$app.conf \ No newline at end of file + +/etc/php/8.0/fpm/pool.d/$app.conf diff --git a/conf/garradin_post_migration.sh b/conf/garradin_post_migration.sh index c8c6bea..4b75453 100644 --- a/conf/garradin_post_migration.sh +++ b/conf/garradin_post_migration.sh @@ -25,8 +25,14 @@ script_name="$0" ynh_secure_remove --file="/etc/yunohost/apps/$old_app" yunohost app ssowatconf + +#================================================= +# REMOVE THE OLD USER +#================================================= +ynh_user_exists --username=$old_app && ynh_system_user_delete $old_app + #================================================= # DELETE THIS SCRIPT #================================================= -echo "rm $script_name" | at now + 1 minutes \ No newline at end of file +echo "rm $script_name" | at now + 1 minutes diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh index 63f926c..9f4b973 100644 --- a/scripts/experimental_helper.sh +++ b/scripts/experimental_helper.sh @@ -76,7 +76,7 @@ ynh_handle_app_migration () { fi #================================================= - # CHECK IF IT HAS TO MIGRATE + # CHECK IF IT HAS TO MIGRATE #================================================= migration_process=0 @@ -147,7 +147,7 @@ ynh_handle_app_migration () { new_label=$(echo $new_app_id | cut -c1 | tr [:lower:] [:upper:])$(echo $new_app_id | cut -c2-) ynh_app_setting_set --app=$new_app --key=label --value=$new_label fi - + permissions_name=$(yunohost user permission list $old_app --short --output-as plain) for permission_name in $permissions_name do @@ -196,10 +196,9 @@ ynh_handle_app_migration () { #================================================= old_db_name=$(ynh_app_setting_get --app=$old_app --key=db_name) - + # Check if a database exists before trying to move it - local mysql_root_password=$(cat $MYSQL_ROOT_PWD_FILE) - if [ -n "$old_db_name" ] && mysqlshow -u root -p$mysql_root_password | grep -q "^| $old_db_name" + if [ -n "$old_db_name" ] && mysqlshow | grep -q "^| $old_db_name" then old_db_user=$old_db_name db_pwd=$(ynh_app_setting_get --app=$old_app --key=mysqlpwd) @@ -215,7 +214,7 @@ ynh_handle_app_migration () { # Create a new database ynh_mysql_setup_db --db_user=$new_db_user --db_name=$new_db_name --db_pwd=$db_pwd - + # Then restore the old one into the new one ynh_mysql_connect_as --user=$new_db_user --password=$db_pwd --database=$new_db_name < "$sql_dump" diff --git a/scripts/install b/scripts/install index c251a96..7b2f7e9 100644 --- a/scripts/install +++ b/scripts/install @@ -100,6 +100,7 @@ ynh_script_progression --message="Adding a configuration file..." --weight=5 # create a key for the secret key CSFR: secret_key=$(ynh_string_random --length=50) +ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key # Install configuration files ynh_add_config --template="config.local.php" --destination="$final_path/config.local.php" diff --git a/scripts/upgrade b/scripts/upgrade index 194e02e..73c67d1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -39,9 +39,18 @@ 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_migration() { + yunohost app remove $app + app=garradin ynh_restore_upgradebackup +} + ynh_clean_setup () { # Restore it if the upgrade fails - ynh_restore_upgradebackup + if [[ $migration_process -eq 1 ]]; then + ynh_clean_setup_migration + else + ynh_restore_upgradebackup + fi } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -71,17 +80,13 @@ fi #================================================= [[ $YNH_APP_ID == "garradin" ]] \ - && [[ "$(cat "$final_path/VERSION")" != 1.2.2 ]] \ - && ynh_die --message "It look like that you have an old Garradin install. You need first upgrade Garradin instance (id: $garradin_migrate_id) and after migrate to Paheko." + && [[ "$(cat "$final_path/VERSION")" != 1.2.2 ]] \ + && ynh_die --message "It looks like that you have an old Garradin installed. You need to first upgrade your Garradin instance (id: $garradin_migrate_id) and after to migrate to Paheko." + ynh_handle_app_migration --migration_id=garradin --migration_list=garradin_migrations if [[ $migration_process -eq 1 ]]; then - final_path="/var/www/$app" - - # Replace the user - ynh_system_user_delete --username=$old_app - ynh_system_user_create --username=$app || \ - ynh_die --message "Unable to create $app system account" + final_path=$(ynh_app_setting_get --app=$app --key=final_path) fi #================================================= @@ -184,19 +189,19 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= if [[ $migration_process -eq 1 ]]; then - echo "Garradin has been successfully migrated to Paheko! \ -A last scheduled operation will run in a couple of minutes to finish the \ -migration in YunoHost side. Do not proceed any application operation while \ -you don't see Garradin as installed." >&2 + echo "Garradin has been successfully migrated to Paheko! \ + A last scheduled operation will run in a couple of minutes to finish the \ + migration in YunoHost side. Do not proceed any application operation while \ + you don't see Garradin as installed." >&2 - # Execute a post migration script after the end of this upgrade. - # Mainly for some cleaning - script_post_migration=garradin_post_migration.sh - ynh_replace_string --match_string __OLD_APP__ --replace_string "$old_app" --target_file ../conf/$script_post_migration - ynh_replace_string --match_string __NEW_APP__ --replace_string "$app" --target_file ../conf/$script_post_migration - cp ../conf/$script_post_migration /tmp - chmod +x /tmp/$script_post_migration - (cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes) + # Execute a post migration script after the end of this upgrade. + # Mainly for some cleaning + script_post_migration=garradin_post_migration.sh + ynh_replace_string --match_string __OLD_APP__ --replace_string "$old_app" --target_file ../conf/$script_post_migration + ynh_replace_string --match_string __NEW_APP__ --replace_string "$app" --target_file ../conf/$script_post_migration + cp ../conf/$script_post_migration /tmp + chmod +x /tmp/$script_post_migration + (cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes) fi #=================================================