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 #20 from YunoHost-Apps/v2-without-migration

V2 without migration
This commit is contained in:
Robles Rodolphe 2023-05-28 01:26:11 +02:00 committed by GitHub
commit 7ca244c3fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 19 additions and 394 deletions

View file

@ -16,8 +16,6 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
## Overview ## Overview
## Paheko
Paheko (we chose the name Paheko, a word from the Māori language meaning "to cooperate", illustrating the purpose of the software: to improve together the daily management of an association) is software for associative management. Paheko (we chose the name Paheko, a word from the Māori language meaning "to cooperate", illustrating the purpose of the software: to improve together the daily management of an association) is software for associative management.
It is the tool of choice for managing an association, a sports club, an NGO, etc. It is designed to meet the needs of a small to medium-sized structure: management of members, accounting, website, note-taking in meetings, archiving and sharing of the association's operating documents, discussion between members, etc. etc. . It is the tool of choice for managing an association, a sports club, an NGO, etc. It is designed to meet the needs of a small to medium-sized structure: management of members, accounting, website, note-taking in meetings, archiving and sharing of the association's operating documents, discussion between members, etc. etc. .
@ -34,7 +32,7 @@ You can now upgrade Garradin with Paheko !
![Logo Paheko](https://master.garradin.eu/garradin-devient-paheko/logo_v3_small-fs8.png) ![Logo Paheko](https://master.garradin.eu/garradin-devient-paheko/logo_v3_small-fs8.png)
**Shipped version:** 1.2.8~ynh1 **Shipped version:** 1.2.9~ynh1
**Demo:** https://paheko.cloud/essai/ **Demo:** https://paheko.cloud/essai/

View file

@ -30,7 +30,7 @@ Paheko (Nous avons choisi le nom Paheko, un mot de la langue Māori qui signifie
![Logo Paheko](https://master.garradin.eu/garradin-devient-paheko/logo_v3_small-fs8.png) ![Logo Paheko](https://master.garradin.eu/garradin-devient-paheko/logo_v3_small-fs8.png)
**Version incluse :** 1.2.8~ynh1 **Version incluse :** 1.2.9~ynh1
**Démo :** https://paheko.cloud/essai/ **Démo :** https://paheko.cloud/essai/

View file

@ -1,7 +0,0 @@
# 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

View file

@ -1,46 +0,0 @@
#!/bin/bash
# Ending the migration process from Gogs to Gitea
set -u
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#=================================================
# SET VARIABLES
#=================================================
old_app="__OLD_APP__"
new_app="__NEW_APP__"
script_name="$0"
#=================================================
# DELETE OLD APP'S SESSIONS
#=================================================
[ -n "$old_app" ] && find /var/lib/php/sessions/ -user "$old_app" -delete
#=================================================
# DELETE OLD APP'S SETTINGS
#=================================================
# `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

View file

@ -3,9 +3,13 @@
This package handle the migration from Garradin to Paheko. For that, you will have to upgrade your Garradin application with this repository. This can only be done from the command-line interface - e.g. through SSH. Once you're connected, you simply have to execute the following: This package handle the migration from Garradin to Paheko. For that, you will have to upgrade your Garradin application with this repository. This can only be done from the command-line interface - e.g. through SSH. Once you're connected, you simply have to execute the following:
```bash ```bash
sudo yunohost app upgrade garradin -u https://github.com/YunoHost-Apps/paheko_ynh --debug sudo yunohost app upgrade garradin -u https://github.com/YunoHost-Apps/paheko_ynh/tree/garradin-migration --debug
``` ```
The --debug option will let you see the full output. If you encounter any issue, please report it aand paste the logs. The --debug option will let you see the full output. If you encounter any issue, please report it aand paste the logs.
**Important**: After the migration, you'll have to wait a couple of minutes (at most 3 minutes) before you can start using Paheko. **Important**: After the migration, you'll have to wait a couple of minutes (at most 3 minutes) before you can start using Paheko.
Once the migration is done, you should then upgrade to new release of Paheko.

View file

@ -3,9 +3,11 @@
Ce paquet supporte la migration de Garradin vers Paheko. Pour ce faire, vous allez devoir mettre à jour l'application Garradin à l'aide de ce dépôt. Cette opération ne peut se faire seulement depuis une interface en ligne de commande, autrement dit en SSH. Une fois connecté/e, vous devez simplement lancer la commande suivante : Ce paquet supporte la migration de Garradin vers Paheko. Pour ce faire, vous allez devoir mettre à jour l'application Garradin à l'aide de ce dépôt. Cette opération ne peut se faire seulement depuis une interface en ligne de commande, autrement dit en SSH. Une fois connecté/e, vous devez simplement lancer la commande suivante :
```bash ```bash
sudo yunohost app upgrade garradin -u https://github.com/YunoHost-Apps/paheko_ynh --debug sudo yunohost app upgrade garradin -u https://github.com/YunoHost-Apps/paheko_ynh/tree/garradin-migration --debug
``` ```
L'option debug vous permet de voir l'entièreté du journal d'installation. Si vous rencontrez des difficultés, merci de créer un ticket en collant le journal d'erreur. L'option debug vous permet de voir l'entièreté du journal d'installation. Si vous rencontrez des difficultés, merci de créer un ticket en collant le journal d'erreur.
**Important** : Après la migration, veuillez attendre quelques instants (maximum 3 minutes) avant de commencer à utiliser Paheko. **Important** : Après la migration, veuillez attendre quelques instants (maximum 3 minutes) avant de commencer à utiliser Paheko.
Une fois la migration terminée, vous pourrez mettre à jour avec la dernière version stable de Paheko.

View file

@ -1,5 +1,3 @@
## Paheko
Paheko (we chose the name Paheko, a word from the Māori language meaning "to cooperate", illustrating the purpose of the software: to improve together the daily management of an association) is software for associative management. Paheko (we chose the name Paheko, a word from the Māori language meaning "to cooperate", illustrating the purpose of the software: to improve together the daily management of an association) is software for associative management.
It is the tool of choice for managing an association, a sports club, an NGO, etc. It is designed to meet the needs of a small to medium-sized structure: management of members, accounting, website, note-taking in meetings, archiving and sharing of the association's operating documents, discussion between members, etc. etc. . It is the tool of choice for managing an association, a sports club, an NGO, etc. It is designed to meet the needs of a small to medium-sized structure: management of members, accounting, website, note-taking in meetings, archiving and sharing of the association's operating documents, discussion between members, etc. etc. .

View file

@ -5,7 +5,7 @@ name = "Paheko"
description.en = "Software to manage association" description.en = "Software to manage association"
description.fr = "Logiciel libre de gestion d'association" description.fr = "Logiciel libre de gestion d'association"
version = "1.2.8~ynh1" version = "1.2.9~ynh1"
maintainers = ["rodinux"] maintainers = ["rodinux"]
@ -42,8 +42,8 @@ ram.runtime = "50M"
[resources] [resources]
[resources.sources.main] [resources.sources.main]
url = "https://fossil.kd2.org/paheko/uv/paheko-1.2.8.tar.gz" url = "https://fossil.kd2.org/paheko/uv/paheko-1.2.9.tar.gz"
sha256 = "d1946fca1a56b03fc59f577fe750aca2e94251a10440eea354b523d553ddd3fa" sha256 = "e07b51f35fefbe63387dc3f00df107438f224216085f1689a1911afa40438939"
autoupdate.strategy = "latest_github_tag" autoupdate.strategy = "latest_github_tag"
[resources.system_user] [resources.system_user]

View file

@ -1,265 +0,0 @@
#!/bin/bash
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args
# Make the main steps to migrate an app to its fork.
#
# This helper has to be used for an app which needs to migrate to a new name or a new fork
# (like owncloud to nextcloud or zerobin to privatebin).
#
# This helper will move the files of an app to its new name
# or recreate the things it can't move.
#
# To specify which files it has to move, you have to create a "migration file", stored in ../conf
# This file is a simple list of each file it has to move,
# except that file names must reference the $app variable instead of the real name of the app,
# and every instance-specific variables (like $domain).
# $app is especially important because it's this variable which will be used to identify the old place and the new one for each file.
#
# If a database exists for this app, it will be dumped and then imported in a newly created database, with a new name and new user.
# Don't forget you have to then apply these changes to application-specific settings (depends on the packaged application)
#
# Same things for an existing user, a new one will be created.
# But the old one can't be removed unless it's not used. See below.
#
# If you have some dependencies for your app, it's possible to change the fake debian package which manages them.
# You have to fill the $pkg_dependencies variable, and then a new fake package will be created and installed,
# and the old one will be removed.
# If you don't have a $pkg_dependencies variable, the helper can't know what the app dependencies are.
#
# The app settings.yml will be modified as follows:
# - finalpath will be changed according to the new name (but only if the existing $final_path contains the old app name)
# - The checksums of php-fpm and nginx config files will be updated too.
# - If there is a $db_name value, it will be changed.
# - And, of course, the ID will be changed to the new name too.
#
# Finally, the $app variable will take the value of the new name.
# The helper will set the $migration_process variable to 1 if a migration has been successfully handled.
#
# You have to handle by yourself all the migrations not done by this helper, like configuration or special values in settings.yml
# Also, at the end of the upgrade script, you have to add a post_migration script to handle all the things the helper can't do during YunoHost upgrade (mostly for permission reasons),
# especially remove the old user, move some hooks and remove the old configuration directory
# To launch this script, you have to move it elsewhere and start it after the upgrade script.
# `cp ../conf/$script_post_migration /tmp`
# `(cd /tmp; echo "/tmp/$script_post_migration" | at now + 2 minutes)`
#
# usage: ynh_handle_app_migration migration_id migration_list
# | arg: -i, --migration_id= - ID from which to migrate
# | arg: -l, --migration_list= - File specifying every file to move (one file per line)
ynh_handle_app_migration () {
# Need for end of install
ynh_package_install at
#=================================================
# LOAD SETTINGS
#=================================================
old_app=$YNH_APP_INSTANCE_NAME
local old_app_id=$YNH_APP_ID
local old_app_number=$YNH_APP_INSTANCE_NUMBER
# Declare an array to define the options of this helper.
declare -Ar args_array=( [i]=migration_id= [l]=migration_list= )
# Get the id from which to migrate
local migration_id
# And the file with the paths to move
local migration_list
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Get the new app id in the manifest
local new_app_id=$(grep \"id\": ../manifest.json | cut -d\" -f4)
if [ $old_app_number -eq 1 ]; then
local new_app=$new_app_id
else
local new_app=${new_app_id}__${old_app_number}
fi
#=================================================
# CHECK IF IT HAS TO MIGRATE
#=================================================
migration_process=0
if [ "$old_app_id" == "$new_app_id" ]
then
# If the 2 id are the same
# No migration to do.
echo 0
return 0
else
if [ "$old_app_id" != "$migration_id" ]
then
# If the new app is not the authorized id, fail.
ynh_die --message="Incompatible application for migration from $old_app_id to $new_app_id"
fi
ynh_print_info --message="Migrate from $old_app_id to $new_app_id" >&2
#=================================================
# CHECK IF THE MIGRATION CAN BE DONE
#=================================================
# TODO Handle multi instance apps...
# Check that there is not already an app installed for this id.
(yunohost app list | grep -q -w "id: $new_app") \
&& ynh_die --message="$new_app is already installed"
#=================================================
# CHECK THE LIST OF FILES TO MOVE
#=================================================
local temp_migration_list="$(tempfile)"
# Build the list by removing blank lines and comment lines
sed '/^#.*\|^$/d' "../conf/$migration_list" > "$temp_migration_list"
# Check if there is no file in the destination
local file_to_move=""
while read file_to_move
do
# Replace all occurences of $app by $new_app in each file to move.
local move_to_destination="${file_to_move//\$app/$new_app}"
test -e "$move_to_destination" && ynh_die --message="A file named $move_to_destination already exists."
done < "$temp_migration_list"
#=================================================
# COPY YUNOHOST SETTINGS FOR THIS APP
#=================================================
local settings_dir="/etc/yunohost/apps"
cp -a "$settings_dir/$old_app" "$settings_dir/$new_app"
cp -a ../{scripts,conf,manifest.json} "$settings_dir/$new_app"
# Replace the old id by the new one
ynh_replace_string --match_string="\(^id: .*\)$old_app" --replace_string="\1$new_app" --target_file="$settings_dir/$new_app/settings.yml"
# INFO: There a special behavior with yunohost app setting:
# if the id given in argument does not match with the id
# stored in the config file, the config file will be purged.
# That's why we use sed instead of app setting here.
# https://github.com/YunoHost/yunohost/blob/c6b5284be8da39cf2da4e1036a730eb5e0515096/src/yunohost/app.py#L1316-L1321
# Change the label if it's simply the name of the app
old_label=$(ynh_app_setting_get --app=$new_app --key=label)
if [ "${old_label,,}" == "$old_app_id" ]
then
# Build the new label from the id of the app. With the first character as upper case
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
yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('$permission_name', force=True, sync_perm=False)"
done
yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$new_app.main', url='/' , show_tile=True , sync_perm=True)"
#=================================================
# MOVE FILES TO THE NEW DESTINATION
#=================================================
while read file_to_move
do
# Replace all occurence of $app by $new_app in each file to move.
move_to_destination="$(eval echo "${file_to_move//\$app/$new_app}")"
local real_file_to_move="$(eval echo "${file_to_move//\$app/$old_app}")"
ynh_print_info --message="Move file $real_file_to_move to $move_to_destination" >&2
mv "$real_file_to_move" "$move_to_destination"
done < "$temp_migration_list"
#=================================================
# UPDATE SETTINGS KNOWN ENTRIES
#=================================================
# Replace nginx checksum
ynh_replace_string --match_string="\(^checksum__etc_nginx.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml"
# Replace php-fpm checksums
ynh_replace_string --match_string="\(^checksum__etc_php.*[-_]\)$old_app" --replace_string="\1$new_app" --target_file="$settings_dir/$new_app/settings.yml"
# Replace final_path
ynh_replace_string --match_string="\(^final_path: .*\)$old_app" --replace_string="\1$new_app" --target_file="$settings_dir/$new_app/settings.yml"
# Replace fail2ban_filter
ynh_replace_string --match_string="\(^checksum__etc_fail2ban_filter.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml"
# Replace fail2ban_jail
ynh_replace_string --match_string="\(^checksum__etc_fail2ban_jail.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml"
# Replace systemd
ynh_replace_string --match_string="\(^checksum__etc_systemd_system.*\)_$old_app" --replace_string="\1_$new_app" --target_file="$settings_dir/$new_app/settings.yml"
#=================================================
# MOVE THE MYSQL DATABASE
#=================================================
old_db_name=$(ynh_app_setting_get --app=$old_app --key=db_name)
# Check if a database exists before trying to move it
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)
new_db_name=$(ynh_sanitize_dbid --db_name=$new_app)
new_db_user=$new_db_name
ynh_print_info --message="Rename the database $db_name to $new_db_name" >&2
local sql_dump="/tmp/${db_name}-$(date '+%s').sql"
# Dump the old database
ynh_mysql_dump_db --database="$old_db_name" > "$sql_dump"
# 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"
# Remove the old database
ynh_mysql_remove_db --db_user=$old_db_user --db_name=$old_db_name
# And the dump
ynh_secure_remove --file="$sql_dump"
# Update the value of $db_name
db_name=$new_db_name
db_user=$new_db_user
ynh_app_setting_set --app=$new_app --key=db_name --value=$db_name
fi
#=================================================
# CHANGE THE FAKE DEPENDENCIES PACKAGE
#=================================================
# Check if a variable $pkg_dependencies exists
# If this variable doesn't exist, this part shall be managed in the upgrade script.
if [ -n "${pkg_dependencies:-}" ]
then
# Define the name of the package
local old_package_name="${old_app//_/-}-ynh-deps"
local new_package_name="${new_app//_/-}-ynh-deps"
if ynh_package_is_installed --package="$old_package_name"
then
# Install a new fake package
app=$new_app
ynh_install_app_dependencies $pkg_dependencies
# Then remove the old one
app=$old_app
ynh_remove_app_dependencies
fi
fi
#=================================================
# UPDATE THE ID OF THE APP
#=================================================
app=$new_app
# Set migration_process to 1 to inform that an upgrade has been made
migration_process=1
fi
}

View file

@ -48,9 +48,9 @@ secret_key=$(ynh_string_random --length=50)
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
# Install configuration files # Install configuration files
ynh_add_config --template="../conf/config.local.php" --destination="$install_dir/config.local.php" ynh_add_config --template="config.local.php" --destination="$install_dir/config.local.php"
ynh_add_config --template="../conf/config.local.yunohost.php" --destination="$install_dir/config.local.yunohost.php" ynh_add_config --template="config.local.yunohost.php" --destination="$install_dir/config.local.yunohost.php"
ynh_add_config --template="../conf/config.local.user.php" --destination="$install_dir/config.local.user.php" ynh_add_config --template="config.local.user.php" --destination="$install_dir/config.local.user.php"
# Permissions on files and directories # Permissions on files and directories
chmod -R o-rwx "$install_dir" chmod -R o-rwx "$install_dir"

View file

@ -7,8 +7,6 @@
#================================================= #=================================================
# Load common variables and helpers # Load common variables and helpers
source ./experimental_helper.sh
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -18,27 +16,6 @@ source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=30
# 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
if [[ $migration_process -eq 1 ]]; then
ynh_clean_setup_migration
else
ynh_restore_upgradebackup
fi
}
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#================================================= #=================================================
@ -52,22 +29,6 @@ if [[ -z "${secret_key:-}" ]]; then
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
fi fi
#=================================================
# MIGRATION FROM Garradin
#=================================================
[[ $YNH_APP_ID == "garradin" ]] \
&& [[ "$(cat "$install_dir/VERSION")" != 1.2.4 ]] \
&& 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
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
ynh_permission_update --permission="main" --add="all_users"
ynh_permission_update --permission="main" --add="visitors"
fi
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
@ -107,11 +68,11 @@ ynh_add_nginx_config
ynh_script_progression --message="Updating a configuration file..." --weight=5 ynh_script_progression --message="Updating a configuration file..." --weight=5
if ynh_compare_current_package_version --comparison lt --version 1.1.15~ynh1; then if ynh_compare_current_package_version --comparison lt --version 1.1.15~ynh1; then
ynh_add_config --template="../cong/config.local.user.php" --destination="$install_dir/config.local.user.php" ynh_add_config --template="config.local.user.php" --destination="$install_dir/config.local.user.php"
fi fi
ynh_add_config --template="../cong/config.local.php" --destination="$install_dir/config.local.php" ynh_add_config --template="config.local.php" --destination="$install_dir/config.local.php"
ynh_add_config --template="../cong/config.local.yunohost.php" --destination="$install_dir/config.local.yunohost.php" ynh_add_config --template="config.local.yunohost.php" --destination="$install_dir/config.local.yunohost.php"
# NOTE: Don't overwrite config.local.user.php # NOTE: Don't overwrite config.local.user.php
# Permissions on files and directories # Permissions on files and directories
@ -134,26 +95,6 @@ ynh_local_curl "/admin/index.php"
sleep 5 sleep 5
ynh_local_curl "/index.php" ynh_local_curl "/index.php"
#=================================================
# FINISH MIGRATION PROCESS
#=================================================
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
# 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
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================