1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/z-push_ynh.git synced 2024-09-03 18:05:58 +02:00

Improve the horendous configuration management using shitload of ynh_replace_string ...

This commit is contained in:
Alexandre Aubin 2023-12-04 23:54:49 +01:00
parent 4c8766eca3
commit cd679074f9
7 changed files with 96 additions and 144 deletions

View file

@ -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);

View file

@ -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.

View file

@ -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');

View file

@ -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"

View file

@ -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
#=================================================

View file

@ -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

View file

@ -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