From cd679074f91e85c53ffe8ab2cdf1941d64692690 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 4 Dec 2023 23:54:49 +0100 Subject: [PATCH] Improve the horendous configuration management using shitload of ynh_replace_string ... --- conf/backend/config-autodiscover.php | 2 +- conf/backend/config-imap.php | 2 +- conf/config.php | 2 +- manifest.toml | 3 + scripts/install | 122 ++++++++++----------------- scripts/remove | 2 +- scripts/upgrade | 107 ++++++++++------------- 7 files changed, 96 insertions(+), 144 deletions(-) diff --git a/conf/backend/config-autodiscover.php b/conf/backend/config-autodiscover.php index 2c232f9..6930b36 100644 --- a/conf/backend/config-autodiscover.php +++ b/conf/backend/config-autodiscover.php @@ -87,7 +87,7 @@ define('LOGBACKEND', 'filelog'); - define('LOGFILEDIR', '__FINAL_LOGPATH__/'); + define('LOGFILEDIR', '__LOG_DIR__/'); define('LOGFILE', LOGFILEDIR . 'autodiscover.log'); define('LOGERRORFILE', LOGFILEDIR . 'autodiscover-error.log'); define('LOGLEVEL', LOGLEVEL_ERROR); diff --git a/conf/backend/config-imap.php b/conf/backend/config-imap.php index e48d50b..156c120 100644 --- a/conf/backend/config-imap.php +++ b/conf/backend/config-imap.php @@ -217,7 +217,7 @@ define('SYSTEM_MIME_TYPES_MAPPING', '/etc/mime.types'); // Use BackendCalDAV for Meetings. You cannot hope to get that functionality working without a caldav backend. -define('IMAP_MEETING_USE_CALDAV', __FLAGTOCHANGE__); +define('IMAP_MEETING_USE_CALDAV', __IMAP_MEETING_USE_CALDAV__); // If your IMAP server allows authenticating via GSSAPI, php-imap will not fall back properly to other authentication // methods and you will be unable to log in. Uncomment the following line to disable that authentication method. diff --git a/conf/config.php b/conf/config.php index 389ae9d..19154b0 100644 --- a/conf/config.php +++ b/conf/config.php @@ -120,7 +120,7 @@ $specialLogUsers = array(); // Filelog settings - define('LOGFILEDIR', '/var/log/__APP__/'); + define('LOGFILEDIR', '__LOG_DIR__'); define('LOGFILE', LOGFILEDIR . 'z-push.log'); define('LOGERRORFILE', LOGFILEDIR . 'z-push-error.log'); diff --git a/manifest.toml b/manifest.toml index c507539..fd1f790 100644 --- a/manifest.toml +++ b/manifest.toml @@ -42,6 +42,9 @@ ram.runtime = "50M" [resources.permissions] main.url = "/" + + # FIXME: watdo with this ... + #REMOVEME? ynh_permission_create --permission="autodiscover" --url="re:$domain_regex/[Aa]uto[Dd]iscover/.*" --allowed="visitors" --show_tile="false" --protected="true" [resources.apt] packages = "php7.4-soap, php7.4-imap, php7.4-xsl, php7.4-curl, php7.4-xml, php7.4-ldap, php7.4-cli, php7.4-mbstring, php7.4-memcached, libawl-php" diff --git a/scripts/install b/scripts/install index ff2da61..4b48fb9 100755 --- a/scripts/install +++ b/scripts/install @@ -14,6 +14,8 @@ source /usr/share/yunohost/helpers #================================================= path="/Microsoft-Server-ActiveSync" +timezone="$(cat /etc/timezone)" +log_dir="/var/log/$app" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -45,58 +47,40 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Creating a final log path..." --weight=1 -final_logpath="/var/log/$app" -ynh_app_setting_set --app=$app --key=final_logpath --value=$final_logpath - -mkdir -p $final_logpath - -chmod 750 "$final_logpath" -chmod -R o-rwx "$final_logpath" -chown -R $app:www-data "$final_logpath" +mkdir -p $log_dir +chmod 750 "$log_dir" +chmod -R o-rwx "$log_dir" +chown -R $app:www-data "$log_dir" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -# Configuration -ynh_replace_string --match_string="__TIMEZONE__" --replace_string=$(cat /etc/timezone) --target_file="../conf/config.php" -ynh_replace_string --match_string="__TIMEZONE__" --replace_string=$(cat /etc/timezone) --target_file="../conf/backend/config-autodiscover.php" -ynh_replace_string --match_string="__FINAL_LOGPATH__" --replace_string=$final_logpath --target_file="../conf/config.php" -ynh_replace_string --match_string="__FINAL_LOGPATH__" --replace_string=$final_logpath --target_file="../conf/backend/config-autodiscover.php" - -# Storage of state_dir in /home/yunohost.app -# This contains the sync status in between device and z-push -ynh_replace_string --match_string="__DATA_DIR__" --replace_string=$data_dir --target_file="../conf/config.php" - # Enable caldav carddav support if yunohost app list | grep -q 'id: baikal' ; then echo "Detected Baikal" - bailkaldomain=$(ynh_app_setting_get --app="baikal" --key=domain) - bailkalpath=$(ynh_app_setting_get --app="baikal" --key=path) - bailkalpath=${bailkalpath%/} + baikaldomain=$(ynh_app_setting_get --app="baikal" --key=domain) + baikalpath=$(ynh_app_setting_get --app="baikal" --key=path) + baikalpath=${baikalpath%/} - # Configuration of backend - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/config.php" - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/backend/config-autodiscover.php" + # Variables to hydrate template + backend="BackendCombined" + caldav_server="$baikaldomain" + caldav_path="${baikalpath}/cal.php/calendars/%u/" + caldav_personal="default" - # Configuration baikal - ynh_replace_string --match_string="__CALDAV_SERVER__" --replace_string="${bailkaldomain}" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PATH__" --replace_string="${bailkalpath}/cal.php/calendars/%u/" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PERSONAL__" --replace_string="default" --target_file="../conf/backend/config-caldav.php" + carddav_server="$baikaldomain" + carddav_path="${baikalpath}/card.php/addressbooks/%u/" + carddav_default_path="${baikalpath}/card.php/addressbooks/%u/default" - ynh_replace_string --match_string="__CARDDAV_SERVER__" --replace_string="${bailkaldomain}" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_PATH__" --replace_string="${bailkalpath}/card.php/addressbooks/%u/" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_DEFAULT_PATH__" --replace_string="${bailkalpath}/card.php/addressbooks/%u/default" --target_file="../conf/backend/config-carddav.php" + imap_server="$domain" + imap_meeting_use_caldav="true" - ynh_replace_string --match_string="__IMAP_SERVER__" --replace_string="${domain}" --target_file="../conf/backend/config-imap.php" - ynh_replace_string --match_string="__FLAGTOCHANGE__" --replace_string="true" --target_file="../conf/backend/config-imap.php" - - # Copy config - cp -af ../conf/backend/config-caldav.php $install_dir/backend/caldav/config.php - cp -af ../conf/backend/config-carddav.php $install_dir/backend/carddav/config.php - cp -af ../conf/backend/config-imap.php $install_dir/backend/imap/config.php - cp -af ../conf/backend/config-combined.php $install_dir/backend/combined/config.php + ynh_add_config --template="backend/config-caldav.php" --destination="$install_dir/backend/caldav/config.php" + ynh_add_config --template="backend/config-carddav.php" --destination="$install_dir/backend/carddav/config.php" + ynh_add_config --template="backend/config-imap.php" --destination="$install_dir/backend/imap/config.php" + ynh_add_config --template="backend/config-combined.php" --destination="$install_dir/backend/combined/config.php" elif yunohost app list | grep -q 'id: nextcloud' ; then echo "Detected NextCloud" @@ -104,44 +88,36 @@ elif yunohost app list | grep -q 'id: nextcloud' ; then nextcloudpath=$(ynh_app_setting_get --app="nextcloud" --key=path) nextcloudpath=${nextcloudpath%/} - # Configuration of backend - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/config.php" - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/backend/config-autodiscover.php" + # Variables to hydrate template + backend="BackendCombined" + caldav_server="$nextclouddomain" + caldav_path="${nextcloudpath}/remote.php/dav/calendars/%u/" + caldav_personal="personal" - # Configuration nextcloud - ynh_replace_string --match_string="__CALDAV_SERVER__" --replace_string="${nextclouddomain}" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PATH__" --replace_string="${nextcloudpath}/remote.php/dav/calendars/%u/" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PERSONAL__" --replace_string="personal" --target_file="../conf/backend/config-caldav.php" + carddav_server="$nextclouddomain" + carddav_path="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/" + carddav_default_path="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/" - ynh_replace_string --match_string="__CARDDAV_SERVER__" --replace_string="${nextclouddomain}" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_PATH__" --replace_string="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_DEFAULT_PATH__" --replace_string="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/" --target_file="../conf/backend/config-carddav.php" + imap_server="$domain" + imap_meeting_use_caldav="true" - ynh_replace_string --match_string="__IMAP_SERVER__" --replace_string="${domain}" --target_file="../conf/backend/config-imap.php" - ynh_replace_string --match_string="__FLAGTOCHANGE__" --replace_string="true" --target_file="../conf/backend/config-imap.php" + ynh_add_config --template="backend/config-caldav.php" --destination="$install_dir/backend/caldav/config.php" + ynh_add_config --template="backend/config-carddav.php" --destination="$install_dir/backend/carddav/config.php" + ynh_add_config --template="backend/config-imap.php" --destination="$install_dir/backend/imap/config.php" + ynh_add_config --template="backend/config-combined.php" --destination="$install_dir/backend/combined/config.php" - # Copy config - cp -af ../conf/backend/config-caldav.php $install_dir/backend/caldav/config.php - cp -af ../conf/backend/config-carddav.php $install_dir/backend/carddav/config.php - cp -af ../conf/backend/config-imap.php $install_dir/backend/imap/config.php - cp -af ../conf/backend/config-combined.php $install_dir/backend/combined/config.php else - # Configuration of backend - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendIMAP" --target_file="../conf/config.php" - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendIMAP" --target_file="../conf/backend/config-autodiscover.php" - - # Configuration imap - ynh_replace_string --match_string="__IMAP_SERVER__" --replace_string="${domain}" --target_file="../conf/backend/config-imap.php" - ynh_replace_string --match_string="__FLAGTOCHANGE__" --replace_string="false" --target_file="../conf/backend/config-imap.php" - - # Copy config - cp -af ../conf/backend/config-imap.php $install_dir/backend/imap/config.php + backend="BackendIMAP" + imap_server="$domain" + imap_meeting_use_caldav="false" + + ynh_add_config --template="backend/config-imap.php" --destination="$install_dir/backend/imap/config.php" fi # Copy config -cp -af ../conf/config.php $install_dir/config.php -cp -af ../conf/backend/config-autodiscover.php $install_dir/autodiscover/config.php -cp -af ../conf/backend/config-searchldap.php $install_dir/backend/searchldap/config.php +ynh_add_config --template="config.php" --destination="$install_dir/config.php" +ynh_add_config --template="backend/config-autodiscover.php" --destination="$install_dir/autodiscover/config.php" +ynh_add_config --template="backend/config-searchldap.php" --destination="$install_dir/backend/searchldap/config.php" #Copy XMLElement.php ln -s /usr/share/awl/inc/XML* /var/www/$app/include/ @@ -156,14 +132,6 @@ ynh_script_progression --message="Configuring log rotation..." --weight=1 # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# SETUP SSOWAT -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1 - -#domain_regex=$(echo "$domain" | sed 's@-@.@g') -#REMOVEME? ynh_permission_create --permission="autodiscover" --url="re:$domain_regex/[Aa]uto[Dd]iscover/.*" --allowed="visitors" --show_tile="false" --protected="true" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 17a6924..6822235 100755 --- a/scripts/remove +++ b/scripts/remove @@ -25,7 +25,7 @@ ynh_remove_nginx_config # Remove the dedicated PHP-FPM config ynh_remove_fpm_config -ynh_secure_remove --file="$final_logpath" +ynh_secure_remove --file="$log_dir" #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 075c4d9..fa2a4f5 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,9 @@ source /usr/share/yunohost/helpers upgrade_type=$(ynh_check_app_version_changed) +timezone="$(cat /etc/timezone)" +log_dir="/var/log/$app" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -51,89 +54,67 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Updating a config file..." --weight=1 -# Configuration -ynh_replace_string --match_string="__TIMEZONE__" --replace_string="$(cat /etc/timezone)" --target_file="../conf/config.php" -ynh_replace_string --match_string="__TIMEZONE__" --replace_string="$(cat /etc/timezone)" --target_file="../conf/backend/config-autodiscover.php" -ynh_replace_string --match_string="__FINAL_LOGPATH__" --replace_string="$final_logpath" --target_file="../conf/config.php" -ynh_replace_string --match_string="__FINAL_LOGPATH__" --replace_string="$final_logpath" --target_file="../conf/backend/config-autodiscover.php" - -# Storage of state_dir in /home/yunohost.app -# This contains the sync status in between device and z-push -ynh_replace_string __DATA_DIR__ $data_dir ../conf/config.php - # Enable caldav carddav support if yunohost app list | grep -q 'id: baikal' ; then echo "Detected Baikal" - bailkaldomain=$(ynh_app_setting_get --app=baikal --key=domain) - bailkalpath=$(ynh_app_setting_get --app=baikal --key=path) - bailkalpath=${bailkalpath%/} + baikaldomain=$(ynh_app_setting_get --app="baikal" --key=domain) + baikalpath=$(ynh_app_setting_get --app="baikal" --key=path) + baikalpath=${baikalpath%/} - # Configuration of backend - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/config.php" - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/backend/config-autodiscover.php" + # Variables to hydrate template + backend="BackendCombined" + caldav_server="$baikaldomain" + caldav_path="${baikalpath}/cal.php/calendars/%u/" + caldav_personal="default" - # Configuration baikal - ynh_replace_string --match_string="__CALDAV_SERVER__" --replace_string="${bailkaldomain}" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PATH__" --replace_string="${bailkalpath}/cal.php/calendars/%u/" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PERSONAL__" --replace_string="default" --target_file="../conf/backend/config-caldav.php" + carddav_server="$baikaldomain" + carddav_path="${baikalpath}/card.php/addressbooks/%u/" + carddav_default_path="${baikalpath}/card.php/addressbooks/%u/default" - ynh_replace_string --match_string="__CARDDAV_SERVER__" --replace_string="${bailkaldomain}" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_PATH__" --replace_string="${bailkalpath}/card.php/addressbooks/%u/" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_DEFAULT_PATH__" --replace_string="${bailkalpath}/card.php/addressbooks/%u/default" --target_file="../conf/backend/config-carddav.php" + imap_server="$domain" + imap_meeting_use_caldav="true" - ynh_replace_string --match_string="__IMAP_SERVER__" --replace_string="${domain}" --target_file="../conf/backend/config-imap.php" - ynh_replace_string --match_string="__FLAGTOCHANGE__" --replace_string="true" --target_file="../conf/backend/config-imap.php" - - # Copy config - cp -af ../conf/backend/config-caldav.php $install_dir/backend/caldav/config.php - cp -af ../conf/backend/config-carddav.php $install_dir/backend/carddav/config.php - cp -af ../conf/backend/config-imap.php $install_dir/backend/imap/config.php - cp -af ../conf/backend/config-combined.php $install_dir/backend/combined/config.php + ynh_add_config --template="backend/config-caldav.php" --destination="$install_dir/backend/caldav/config.php" + ynh_add_config --template="backend/config-carddav.php" --destination="$install_dir/backend/carddav/config.php" + ynh_add_config --template="backend/config-imap.php" --destination="$install_dir/backend/imap/config.php" + ynh_add_config --template="backend/config-combined.php" --destination="$install_dir/backend/combined/config.php" elif yunohost app list | grep -q 'id: nextcloud' ; then echo "Detected NextCloud" - nextclouddomain=$(ynh_app_setting_get --app=nextcloud --key=domain) - nextcloudpath=$(ynh_app_setting_get --app=nextcloud --key=path) + nextclouddomain=$(ynh_app_setting_get --app="nextcloud" --key=domain) + nextcloudpath=$(ynh_app_setting_get --app="nextcloud" --key=path) nextcloudpath=${nextcloudpath%/} - # Configuration of backend - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/config.php" - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendCombined" --target_file="../conf/backend/config-autodiscover.php" + # Variables to hydrate template + backend="BackendCombined" + caldav_server="$nextclouddomain" + caldav_path="${nextcloudpath}/remote.php/dav/calendars/%u/" + caldav_personal="personal" - # Configuration nextcloud - ynh_replace_string --match_string="__CALDAV_SERVER__" --replace_string="${nextclouddomain}" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PATH__" --replace_string="${nextcloudpath}/remote.php/dav/calendars/%u/" --target_file="../conf/backend/config-caldav.php" - ynh_replace_string --match_string="__CALDAV_PERSONAL__" --replace_string="personal" --target_file="../conf/backend/config-caldav.php" + carddav_server="$nextclouddomain" + carddav_path="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/" + carddav_default_path="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/" - ynh_replace_string --match_string="__CARDDAV_SERVER__" --replace_string="${nextclouddomain}" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_PATH__" --replace_string="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/contacts/" --target_file="../conf/backend/config-carddav.php" - ynh_replace_string --match_string="__CARDDAV_DEFAULT_PATH__" --replace_string="${nextcloudpath}/remote.php/dav/addressbooks/users/%u/contacts/" --target_file="../conf/backend/config-carddav.php" + imap_server="$domain" + imap_meeting_use_caldav="true" - ynh_replace_string --match_string="__IMAP_SERVER__" --replace_string="${domain}" --target_file="../conf/backend/config-imap.php" - ynh_replace_string --match_string="__FLAGTOCHANGE__" --replace_string="true" --target_file="../conf/backend/config-imap.php" + ynh_add_config --template="backend/config-caldav.php" --destination="$install_dir/backend/caldav/config.php" + ynh_add_config --template="backend/config-carddav.php" --destination="$install_dir/backend/carddav/config.php" + ynh_add_config --template="backend/config-imap.php" --destination="$install_dir/backend/imap/config.php" + ynh_add_config --template="backend/config-combined.php" --destination="$install_dir/backend/combined/config.php" - # Copy config - cp -af ../conf/backend/config-caldav.php $install_dir/backend/caldav/config.php - cp -af ../conf/backend/config-carddav.php $install_dir/backend/carddav/config.php - cp -af ../conf/backend/config-imap.php $install_dir/backend/imap/config.php - cp -af ../conf/backend/config-combined.php $install_dir/backend/combined/config.php else - # Configuration of backend - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendIMAP" --target_file="../conf/config.php" - ynh_replace_string --match_string="__BACKEND__" --replace_string="BackendIMAP" --target_file="../conf/backend/config-autodiscover.php" - - # Configuration imap - ynh_replace_string --match_string="__IMAP_SERVER__" --replace_string="${domain}" --target_file="../conf/backend/config-imap.php" - ynh_replace_string --match_string="__FLAGTOCHANGE__" --replace_string="false" --target_file="../conf/backend/config-imap.php" - - # Copy config - cp -af ../conf/backend/config-imap.php $install_dir/backend/imap/config.php + backend="BackendIMAP" + imap_server="$domain" + imap_meeting_use_caldav="false" + + ynh_add_config --template="backend/config-imap.php" --destination="$install_dir/backend/imap/config.php" fi # Copy config -cp -af ../conf/config.php $install_dir/config.php -cp -af ../conf/backend/config-autodiscover.php $install_dir/autodiscover/config.php -cp -af ../conf/backend/config-searchldap.php $install_dir/backend/searchldap/config.php +ynh_add_config --template="config.php" --destination="$install_dir/config.php" +ynh_add_config --template="backend/config-autodiscover.php" --destination="$install_dir/autodiscover/config.php" +ynh_add_config --template="backend/config-searchldap.php" --destination="$install_dir/backend/searchldap/config.php" # Fixstates to avoid full resync of devices after version upgrades $install_dir/z-push-admin.php -a fixstates