From 9eaaf473f1f273f867c7abc64fb5ac2e91458f51 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Wed, 27 Sep 2023 20:51:07 +0200 Subject: [PATCH] created yunohost scripts --- scripts/backup | 28 +++++++++++++++++++++++++++ scripts/install | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/remove | 18 +++++++++++++++++ scripts/restore | 45 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 scripts/backup create mode 100644 scripts/install create mode 100644 scripts/remove create mode 100644 scripts/restore diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..db90720 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,28 @@ +#!/bin/bash + +source /usr/share/yunohost/helpers + +#================================================= +# DECLARE DATA AND CONF FILES TO BACKUP +#================================================= +ynh_print_info --message="Declaring files to be backed up..." + +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= +ynh_backup --src_path="$install_dir" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# BACKUP THE SUDOERS CONFIGURATION +#================================================= +ynh_backup --src_path="/etc/sudoers.d/$app" + +#================================================= +# END OF SCRIPT +#================================================= +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..ed756b7 --- /dev/null +++ b/scripts/install @@ -0,0 +1,51 @@ +#!/bin/bash + +source /usr/share/yunohost/helpers + + +#================================================= +# CHECK IF RESTARTABLE SERVICES EXIST +#================================================= +ynh_script_progression --message="Checking installed apps: minidlna …" --weight=1 + +if ! yunohost app list | grep "id: minidlna" >/dev/null 2>&1 ; then + ynh_die --message="No restartable app found. aborting installation" --ret-code="1" +fi + + +#================================================= +# INSTALL FILES +#================================================= +ynh_script_progression --message="Setting up source files…" --weight=1 + +ynh_setup_source --dest_dir="$install_dir" + +ynh_add_config --template="index.html" --destination="$install_dir/index.html" +ynh_add_config --template="restarter.php" --destination="$install_dir/$app.php" + +chown -R www-data:www-data "$install_dir" +chmod 750 "$install_dir" +chmod 640 "$install_dir/*" + + +#================================================= +# SUDOERS CONFIGURATION +#================================================= +ynh_script_progression --message="Adding sudoers configuration …" --weight=1 + +ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app" +chown root:root "/etc/sudoers.d/$app" +chmod 600 "/etc/sudoers.d/$app" + +#================================================= +# WEBSERVER CONFIGURATION +#================================================= +ynh_script_progression --message="Adding nginx configuration …" --weight=1 + +ynh_add_nginx_config + + +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..df30719 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,18 @@ +#!/bin/bash + +source /usr/share/yunohost/helpers + +#================================================= +# REMOVE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Removing nginx web server configuration..." --weight=1 + +ynh_remove_nginx_config + + +#================================================= +# REMOVE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Removing nginx web server configuration..." --weight=1 + +rm /etc/sudoers.d/$app diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..32f64af --- /dev/null +++ b/scripts/restore @@ -0,0 +1,45 @@ +#!/bin/bash + +source /usr/share/yunohost/helpers + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=1 + +ynh_restore_file --origin_path="$install_dir" + +chown -R www-date:www-data $install_dir +chmod 750 "$install_dir" +chmod 640 "$install_dir/*" + + +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=2 + +ynh_systemd_action --service_name=nginx --action=reload + + +#================================================= +# RESTORE SUDOERS CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the sudoers configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/sudoers.d/$app" +chown root:root "/etc/sudoers.d/$app" +chmod 600 "/etc/sudoers.d/$app" + + +#================================================= +# END OF SCRIPT +#================================================= +ynh_script_progression --message="Restoration completed for $app" --last