1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/paheko_ynh.git synced 2024-09-03 19:56:22 +02:00

Merge pull request #5 from fflorent/migration-fixes

Some improvements and fix migration
This commit is contained in:
Robles Rodolphe 2023-02-08 09:11:58 +01:00 committed by GitHub
commit 7190189aad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 30 deletions

View file

@ -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
/etc/php/8.0/fpm/pool.d/$app.conf

View file

@ -22,11 +22,19 @@ script_name="$0"
# DELETE OLD APP'S SETTINGS
#=================================================
ynh_secure_remove --file="/etc/yunohost/apps/$old_app"
# `app=""` Circumvents this issue: https://github.com/YunoHost/issues/issues/2138
app="" 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
echo "rm $script_name" | at now + 1 minutes

View file

@ -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"

View file

@ -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"

View file

@ -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
@ -59,6 +68,13 @@ if [ -z "$final_path" ]; then
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
# If secret_key doesn't exist, create it
if [[ -z "$secret_key" ]]; then
secret_key=$(ynh_string_random --length=50)
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
@ -71,17 +87,15 @@ 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)
ynh_permission_update --permission="main" --add="all_users"
ynh_permission_update --permission="main" --add="visitors"
fi
#=================================================
@ -184,19 +198,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
#=================================================