From d258711f4a60960057ac3fb9df0ade752b37c9d1 Mon Sep 17 00:00:00 2001 From: Douze Baie <12b@distrilab.fr> Date: Thu, 13 Jun 2024 16:30:01 +0200 Subject: [PATCH] feat(yunohost extension): complete upgrade, backup, restore and remove scripts --- scripts/backup | 12 ++++++++++++ scripts/install | 4 +++- scripts/remove | 6 +++++- scripts/restore | 14 ++++++++++++++ scripts/upgrade | 23 +++++++++++++++++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/scripts/backup b/scripts/backup index 214b288..f237759 100755 --- a/scripts/backup +++ b/scripts/backup @@ -33,6 +33,18 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" +#================================================= +# BACKUP THE IMPORTER PLUGIN SUDOERS FILE +#================================================= + +ynh_backup --src_path="/etc/sudoers.d/$app" + +#================================================= +# BACKUP THE IMPORTER PLUGIN POST APP INSTALL HOOK +#================================================= + +ynh_backup --src_path="/etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh" + #================================================= # BACKUP THE MYSQL DATABASE #================================================= diff --git a/scripts/install b/scripts/install index e5358f3..95e2405 100755 --- a/scripts/install +++ b/scripts/install @@ -77,7 +77,7 @@ ynh_replace_string --match_string="'allow_raw_html' => false," --replace_string= #================================================= ynh_script_progression --message="Configure importer plugin" --weight=1 -# Download yeswiki plugin from yeswiki repository +# Download importer plugin from yeswiki repository mkdir -p "$install_dir/tools/importer" ynh_setup_source --dest_dir="$install_dir/tools/importer" --source_id="importerplugin" @@ -99,6 +99,8 @@ chmod +x $install_dir/tools/yunohost/private/scripts/*.sh # Add app user in sudoers to authorize to launch yunohost cli commands without password ynh_add_config --template="sudoers" --destination="/etc/sudoers.d/$app" chown root:root /etc/sudoers.d/$app + +# Add a post app install hook to sync the app importer ynh_add_config --template="sync_app_importer.sh" --destination="/etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh" chown root:root /etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh chmod +x /etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh diff --git a/scripts/remove b/scripts/remove index 03fafa5..dce13b4 100755 --- a/scripts/remove +++ b/scripts/remove @@ -20,7 +20,11 @@ ynh_remove_nginx_config # Remove the dedicated PHP-FPM config ynh_remove_fpm_config -# TODO: remove /etc/sudoers/$app +# Remove sudoers file +ynh_secure_remove --file="/etc/sudoers/$app" + +# Remove post app install hook +ynh_secure_remove --file="/etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 2dff91d..87d2b2d 100755 --- a/scripts/restore +++ b/scripts/restore @@ -35,6 +35,20 @@ ynh_script_progression --message="Restoring the NGINX web server configuration.. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RESTORE THE IMPORTER PLUGIN SUDOERS FILE +#================================================= +ynh_script_progression --message="Restoring the app importer plugin sudoers file..." + +ynh_restore_file --origin_path="/etc/sudoers.d/$app" + +#================================================= +# RESTORE THE IMPORTER PLUGIN POST APP INSTALL HOOK +#================================================= +ynh_script_progression --message="Restoring the app importer post app install hook..." + +ynh_restore_file --origin_path="/etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh" + #================================================= # RESTORE THE MYSQL DATABASE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index b453b76..6c1a048 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -73,6 +73,29 @@ ynh_secure_remove "$install_dir/tools/importer" mkdir -p "$install_dir/tools/importer" ynh_setup_source --dest_dir="$install_dir/tools/importer" --source_id="importerplugin" +# Ensure that scripts are executable +chmod +x $install_dir/tools/yunohost/private/scripts/*.sh + +# Add app user in sudoers to authorize to launch yunohost cli commands without password +ynh_add_config --template="sudoers" --destination="/etc/sudoers.d/$app" +chown root:root /etc/sudoers.d/$app + +# Add a post app install hook to sync the app importer +ynh_add_config --template="sync_app_importer.sh" --destination="/etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh" +chown root:root /etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh +chmod +x /etc/yunohost/hooks.d/post_app_install/$app_sync_app_importer.sh + +# ToDo : Add importer config in wakka.config.php if it is not already there ? +# if [ ??? ]; then +# ynh_replace_string --match_string=");" --replace_string=" 'dataSources' => [\n'yunohost-cli' => [\n'formId' => '5', // form id used in local bazar\n'lang' > +# fi + +# At last, run the YunoHost app importer +ynh_script_progression --message="Import YunoHost apps in bazar" --weight=2 +pushd $install_dir +ynh_exec_as $app ./yeswicli importer:sync -s yunohost-cli +popd + #================================================= # SECURE FILES AND DIRECTORIES #=================================================