From 89c99ff2d2be1e6e2a904dc3686f269a58d87e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 23 Feb 2024 00:21:58 +0100 Subject: [PATCH] Simplify and cleanup scripts --- manifest.toml | 2 -- scripts/_common.sh | 18 ++++++++++++++++-- scripts/backup | 6 ------ scripts/change_url | 1 + scripts/install | 29 +++-------------------------- scripts/remove | 6 +----- scripts/restore | 28 ++++++---------------------- scripts/upgrade | 21 --------------------- 8 files changed, 27 insertions(+), 84 deletions(-) diff --git a/manifest.toml b/manifest.toml index 1b50376..cea1007 100644 --- a/manifest.toml +++ b/manifest.toml @@ -50,8 +50,6 @@ ram.runtime = "200M" [resources] [resources.system_user] - [resources.install_dir] - [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index ec74b54..64859a4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -9,7 +9,7 @@ #================================================= config_nginx() { - nginx_config="$YNH_APP_BASEDIR/conf/nginx.conf" + nginx_config="/etc/nginx/conf.d/$domain/$app.conf" # shellcheck disable=SC2016 principals_block=' @@ -37,6 +37,8 @@ location /.well-known/carddav { rewrite ^ https://$server_name/SOGo/dav/; }' + ynh_add_nginx_config + if ! is_url_handled -d "$domain" -p "/principals"; then echo "$principals_block" >> "$nginx_config" fi @@ -49,7 +51,19 @@ location /.well-known/carddav { if ! is_url_handled -d "$domain" -p "/.wellk-nown/carddav"; then echo "$carddav_block" >> "$nginx_config" fi - ynh_add_nginx_config + ynh_store_file_checksum --file="$nginx_config" + systemctl reload nginx.service +} + +set_permissions() { + chown -R "$app:$app" "/etc/$app" + chmod -R u=rwX,g=rX,o= "/etc/$app" + + chown -R "$app:$app" "/var/log/$app" + chmod -R u=rwX,g=rX,o= "/var/log/$app" + + chown root: "/etc/cron.d/$app" + chmod 644 "/etc/cron.d/$app" } #================================================= diff --git a/scripts/backup b/scripts/backup index 7c2afc2..228d9a0 100755 --- a/scripts/backup +++ b/scripts/backup @@ -22,9 +22,6 @@ ynh_print_info --message="Declaring files to be backed up..." # Backup the nginx configuration ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -# Backup the logrotate configuration -ynh_backup --src_path="/etc/logrotate.d/$app" - #================================================= # BACKUP VARIOUS FILES #================================================= @@ -32,9 +29,6 @@ ynh_backup --src_path="/etc/logrotate.d/$app" # Backup SOGo configuration ynh_backup --src_path="/etc/$app" -# Backup Stunnel configuration -ynh_backup --src_path="/etc/stunnel/$app.conf" - # Backup cron ynh_backup --src_path="/etc/cron.d/$app" diff --git a/scripts/change_url b/scripts/change_url index d9ed0d8..5c76915 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -20,6 +20,7 @@ fi ynh_script_progression --message="Updating NGINX configuration..." ynh_change_url_nginx_config +config_nginx #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 900360c..c305696 100755 --- a/scripts/install +++ b/scripts/install @@ -20,37 +20,14 @@ ynh_script_progression --message="Configuring application..." --weight=3 mkdir -p "/etc/$app" ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf" -chown -R "$app:$app" "/etc/$app" -chmod -R 750 "/etc/$app" - -# Configure stunnel -# To fix the issue https://sogo.nu/bugs/view.php?id=31 we need stunnel to be able to connect correctly to the smtp server -ynh_add_config --template="stunnel.conf" --destination="/etc/stunnel/$app.conf" - -# Enable stunnel at startup -ynh_replace_string --match_string="ENABLED=0" --replace_string="ENABLED=1" --target_file="/etc/default/stunnel4" - -#================================================= -# SETUP A CRON -#================================================= -ynh_script_progression --message="Setting up a cron..." --weight=1 - ynh_add_config --template="cron" --destination="/etc/cron.d/$app" -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" - -#================================================= -# SYSTEM CONFIGURATION -#================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 - config_nginx +ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend + yunohost service add "sogo" --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log" -ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend -chown -R "$app:$app" "/var/log/$app" -chmod -R 750 "/var/log/$app" +set_permissions #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index 1f411fc..e40fa3e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -14,11 +14,7 @@ source /usr/share/yunohost/helpers #================================================= 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 "sogo" >/dev/null; then - ynh_script_progression --message="Removing sogo service integration..." --weight=1 - yunohost service remove "sogo" -fi +yunohost service remove "sogo" # Remove the dedicated systemd config ynh_remove_systemd_config diff --git a/scripts/restore b/scripts/restore index 1a033e4..936d2a7 100755 --- a/scripts/restore +++ b/scripts/restore @@ -17,37 +17,19 @@ ynh_script_progression --message="Restoring the MySQL database..." --weight=1 ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql -# Enable stunnel at startup -ynh_replace_string --match_string "ENABLED=0" --replace_string "ENABLED=1" --target_file /etc/default/stunnel4 - #================================================= # RESTORE VARIOUS FILES #================================================= ynh_script_progression --message="Restoring various files..." --weight=1 - -ynh_restore_file --origin_path="/etc/$app" -chown -R "$app:$app" "/etc/$app" -chmod -R 750 "/etc/$app" - -ynh_restore_file --origin_path="/etc/stunnel/$app.conf" - -ynh_restore_file --origin_path="/etc/cron.d/$app" - -ynh_restore_file --origin_path="/var/log/$app" -chown -R "$app:$app" "/var/log/$app" -chmod -R 750 "/var/log/$app" +ynh_restore #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -systemctl enable "$app.service" --quiet yunohost service add "sogo" --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log" - -ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend +set_permissions #================================================= # START SYSTEMD SERVICE @@ -55,15 +37,17 @@ ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" -ynh_systemd_action --service_name="stunnel4" --action="restart" --log_path="systemd" #================================================= -# RELOAD NGINX AND PHP-FPM +# RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name="nginx" --action=reload +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --logfile="/var/log/$app/sogo.log" --nonappend + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f1be7c6..000e712 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -31,27 +31,6 @@ ynh_script_progression --message="Configuring application..." --weight=1 # Configure SOGO ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf" -chown -R "$app:$app" "/etc/$app" -chmod -R 750 "/etc/$app" - -# Configure stunnel -ynh_add_config --template="stunnel.conf" --destination="/etc/stunnel/$app.conf" - -# Enable stunnel at startup -ynh_replace_string --match_string="ENABLED=0" --replace_string="ENABLED=1" --target_file="/etc/default/stunnel4" - -# Protect logs dir -chown -R "$app:$app" "/var/log/$app" -chmod -R 750 "/var/log/$app" - -#================================================= -# SETUP A CRON -#================================================= -ynh_script_progression --message="Setting up a cron..." --weight=1 - -ynh_add_config --template="cron" --destination="/etc/cron.d/$app" -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" #================================================= # REAPPLY SYSTEM CONFIGURATIONS