1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/vaultwarden_ynh.git synced 2024-09-03 18:26:31 +02:00

Fixing upgrade

This commit is contained in:
yalh76 2021-05-09 20:55:30 +02:00
parent 0fe522d34c
commit 5f671bd62c
3 changed files with 32 additions and 38 deletions

View file

@ -5,7 +5,7 @@
#=================================================
# dependencies used by the app
pkg_dependencies="curl tar pkg-config libssl-dev libc6-dev at"
pkg_dependencies="curl tar pkg-config libssl-dev libc6-dev"
#=================================================
# PERSONAL HELPERS

View file

@ -33,28 +33,6 @@ ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --show_tile="false"
fi
# Create a permission if needed
if ! ynh_permission_exists --permission="api"; then
ynh_permission_create --permission="api" --url="/api" --additional_urls="/identity/connect/token" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true"
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
@ -86,6 +64,7 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --li
#=================================================
ynh_handle_app_migration --migration_id="bitwarden" --migration_list="bitwarden_migration"
if [ $migration_process -eq 1 ]
then
# If a migration has been perform
@ -99,6 +78,28 @@ then
ynh_secure_remove --file="$final_path/live/bitwarden_rs"
fi
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --show_tile="false"
fi
# Create a permission if needed
if ! ynh_permission_exists --permission="api"; then
ynh_permission_create --permission="api" --url="/api" --additional_urls="/identity/connect/token" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true"
fi
#=================================================
# CREATE DEDICATED USER
#=================================================

View file

@ -47,6 +47,9 @@
# | 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
#=================================================
@ -99,7 +102,7 @@ ynh_handle_app_migration () {
# TODO Handle multi instance apps...
# Check that there is not already an app installed for this id.
(yunohost app list | grep -q "id: $new_app") \
(yunohost app list | grep -q -w "id: $new_app") \
&& ynh_die --message="$new_app is already installed"
#=================================================
@ -126,6 +129,7 @@ ynh_handle_app_migration () {
local settings_dir="/etc/yunohost/apps"
cp -a "$settings_dir/$old_app" "$settings_dir/$new_app"
cp -a ../{scripts,conf} "$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"
@ -143,6 +147,9 @@ 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
yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('$old_app.main', force=True, sync_perm=False)"
yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$new_app.main', url='/' , sync_perm=True)"
#=================================================
# MOVE FILES TO THE NEW DESTINATION
@ -210,19 +217,6 @@ ynh_handle_app_migration () {
ynh_app_setting_set --app=$new_app --key=db_name --value=$db_name
fi
#=================================================
# CREATE A NEW USER
#=================================================
new_final_path=$(ynh_app_setting_get --app=$new_app --key=final_path)
# Check if the user exists on the system
if ynh_system_user_exists --username="$old_app"
then
ynh_print_info --message="Create a new user $new_app to replace $old_app" >&2
ynh_system_user_create --username=$app --home_dir="$new_final_path"
fi
#=================================================
# CHANGE THE FAKE DEPENDENCIES PACKAGE
#=================================================
@ -252,7 +246,6 @@ ynh_handle_app_migration () {
app=$new_app
# Set migration_process to 1 to inform that an upgrade has been made
migration_process=1
fi