From b8732361c7b8619c2504374c7e3be092e0f2b778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:02:33 +0100 Subject: [PATCH] cleaning --- scripts/install | 15 ---------- scripts/remove | 43 ++-------------------------- scripts/restore | 75 +++++++++++++------------------------------------ 3 files changed, 22 insertions(+), 111 deletions(-) diff --git a/scripts/install b/scripts/install index e7cd541..fb5ea8e 100644 --- a/scripts/install +++ b/scripts/install @@ -18,27 +18,12 @@ source /usr/share/yunohost/helpers #================================================= password="$YNH_APP_ARG_PASSWORD" -export=$YNH_APP_ARG_EXPORT -mypads=$YNH_APP_ARG_MYPADS -useldap=$YNH_APP_ARG_USELDAP - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - -if [ "${#password}" -lt 8 ] || [ "${#password}" -gt 30 ] -then - ynh_die --message="The password must be between 8 and 30 characters." -fi #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=3 -ynh_app_setting_set --app=$app --key=mypads --value=$mypads -ynh_app_setting_set --app=$app --key=useldap --value=$useldap ynh_app_setting_set --app=$app --key=overwrite_settings --value="1" ynh_app_setting_set --app=$app --key=overwrite_credentials --value="1" ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1" diff --git a/scripts/remove b/scripts/remove index b04383f..5008d7e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,10 +17,11 @@ ynh_script_progression --message="Loading installation settings..." --weight=3 export=$(ynh_app_setting_get --app=$app --key=export) #================================================= -# STANDARD REMOVE +# REMOVE SYSTEM CONFIGURATIONS #================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEMD SERVICE #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null @@ -29,58 +30,20 @@ then yunohost service remove $app fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=2 - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=2 - # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=1 - -if [ "$export" != "none" ] -then - # Remove metapackage and its dependencies - ynh_exec_warn_less ynh_remove_app_dependencies -fi - ynh_remove_nodejs -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=7 - # Remove the dedicated Fail2Ban config ynh_remove_fail2ban_config -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." --weight=1 - # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index 1232a1b..7005a1c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,8 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Loading installation settings..." --weight=3 -export=$(ynh_app_setting_get --app=$app --key=export) -mypads=$(ynh_app_setting_get --app=$app --key=mypads) password=$(ynh_app_setting_get --app=$app --key=password) #================================================= @@ -26,7 +24,6 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$install_dir" -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:$app "$install_dir" @@ -37,31 +34,32 @@ chmod 600 "$install_dir/credentials.json" chown $app:$app "$install_dir/credentials.json" #================================================= -# RESTORE FAIL2BAN CONFIGURATION +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=6 +# RESTORE THE PHP-FPM CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" ynh_systemd_action --action=restart --service_name=fail2ban -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=60 - ynh_install_nodejs --nodejs_version=$nodejs_version ynh_use_nodejs -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +mkdir -p /var/log/$app +touch /var/log/$app/etherpad.log +chown $app -R /var/log/$app + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + +yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log" + #================================================= # RESTORE THE MYSQL DATABASE #================================================= @@ -70,49 +68,14 @@ ynh_script_progression --message="Restoring the MySQL database..." --weight=2 echo "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql -#================================================= -# HANDLE LOG FILES AND LOGROTATE -#================================================= - -mkdir -p /var/log/$app -touch /var/log/$app/etherpad.log -chown $app -R /var/log/$app - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=8 - -ynh_systemd_action --service_name=$app --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" - #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 + +ynh_systemd_action --service_name=$app --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120" ynh_systemd_action --action=reload --service_name=nginx