2016-03-18 18:38:54 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
2022-01-14 23:57:33 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2018-08-14 22:18:22 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2022-01-14 23:57:33 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2022-01-14 23:57:33 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2019-06-07 23:09:30 +02:00
|
|
|
|
2022-01-14 23:57:33 +01:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=web_port)
|
|
|
|
smtp_port=$(ynh_app_setting_get --app=$app --key=smtp_port)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_user=$db_name
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
2018-08-14 22:18:22 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2022-01-14 23:57:33 +01:00
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2018-08-14 22:18:22 +02:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE SETTINGS FROM OLD INSTALL
|
|
|
|
#=================================================
|
|
|
|
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Fixing old settings..." --weight=1
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
if [[ ${is_public,,*} = "yes" ]]
|
2016-03-18 18:38:54 +01:00
|
|
|
then
|
2018-08-14 22:18:22 +02:00
|
|
|
is_public=1
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_app_setting_set --app $app --key is_public --value 1
|
2016-03-18 18:38:54 +01:00
|
|
|
fi
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
if [[ ${is_public,,*} = "no" ]]
|
|
|
|
then
|
|
|
|
is_public=0
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_app_setting_set --app $app --key is_public --value 0
|
2018-08-14 22:18:22 +02:00
|
|
|
fi
|
2016-05-24 21:43:29 +02:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
if [[ -z $port ]]
|
|
|
|
then
|
|
|
|
# Find a port for SOGo
|
2019-06-07 23:09:30 +02:00
|
|
|
port=$(ynh_find_port --port 20000)
|
|
|
|
ynh_app_setting_set --app $app --key web_port --value $port
|
2018-08-14 22:18:22 +02:00
|
|
|
fi
|
2016-05-24 21:43:29 +02:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
if [[ -z $db_name ]]
|
|
|
|
then
|
|
|
|
db_name=$app
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_app_setting_set --app $app --key db_name --value $db_name
|
2018-08-14 22:18:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $db_user ]]
|
|
|
|
then
|
|
|
|
db_user=$app
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_app_setting_set --app $app --key db_user --value $db_user
|
2018-08-14 22:18:22 +02:00
|
|
|
fi
|
|
|
|
|
2020-08-04 21:54:28 +02:00
|
|
|
# Manage migration form SOGo 3.x to SOGo 4.x (Debian stretch -> Buster)
|
|
|
|
ynh_script_progression --message="Migrating database if needed..."
|
|
|
|
|
|
|
|
# FIXME use the new way to manage version when available on the core
|
|
|
|
app_previous_version="$(jq -r .version /etc/yunohost/apps/$app/manifest.json | cut -d~ -f1)"
|
|
|
|
if [[ "$app_previous_version" == 3.2.* ]]; then
|
|
|
|
ynh_replace_string --match_string __APP__ --replace_string $app --target_file migrations/3.2-4.0.sh
|
|
|
|
ynh_replace_string --match_string __DBUSER__ --replace_string $db_user --target_file migrations/3.2-4.0.sh
|
|
|
|
ynh_replace_string --match_string __DBPASS__ --replace_string $db_pwd --target_file migrations/3.2-4.0.sh
|
|
|
|
bash migrations/3.2-4.0.sh
|
|
|
|
fi
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# INSTALL DEPENDENCIES
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2018-08-14 22:18:22 +02:00
|
|
|
install_dependance
|
|
|
|
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Configuring application..."
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
# Configure SOGO
|
2020-03-25 23:00:34 +01:00
|
|
|
ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf"
|
2018-08-14 22:18:22 +02:00
|
|
|
|
|
|
|
# Configure stunnel
|
|
|
|
config_stunnel
|
|
|
|
|
|
|
|
# Install crontab
|
|
|
|
config_cron
|
|
|
|
|
|
|
|
#Configure Nginx
|
|
|
|
config_nginx
|
2016-03-18 18:38:54 +01:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Protecting directory..."
|
2018-08-14 22:18:22 +02:00
|
|
|
set_permission
|
|
|
|
|
|
|
|
# configure the sso
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2020-03-25 23:00:34 +01:00
|
|
|
|
|
|
|
if ! ynh_permission_exists --permission sync_client; then
|
|
|
|
ynh_permission_create --permission="sync_client" --allowed 'visitors' --auth_header=false\
|
|
|
|
--label="Sync client" --protected=true --show_tile=false\
|
|
|
|
--additional_urls="/Microsoft-Server-ActiveSync" "/principals" "/.well-known/caldav" "/.well-known/carddav"
|
|
|
|
python3 remove_sso_conf_persistent.py $domain \
|
2021-03-12 21:11:41 +01:00
|
|
|
|| ynh_print_warn --message="Your file /etc/ssowat/""conf.json.persistent doesn't respect the json syntax. The config file wasn't cleaned. Please clean it manually."
|
2018-08-14 22:18:22 +02:00
|
|
|
else
|
2020-03-25 23:00:34 +01:00
|
|
|
ynh_permission_update --permission="sync_client" --add='visitors' --label="Sync client" --protected=true --show_tile=false
|
|
|
|
ynh_permission_url --permission "sync_client" --auth_header=false\
|
|
|
|
--add_url="/Microsoft-Server-ActiveSync" "/principals" "/.well-known/caldav" "/.well-known/carddav"
|
2018-08-14 22:18:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# SETUP LOGROTATE
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2019-11-04 20:27:16 +01:00
|
|
|
ynh_use_logrotate --logfile /var/log/$app/sogo.log --nonappend
|
2018-08-14 22:18:22 +02:00
|
|
|
|
2020-05-24 00:32:03 +02:00
|
|
|
# Register service
|
|
|
|
yunohost service add $app --log "/var/log/$app/sogo.log"
|
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
# Restart services
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Starting SOGo services..." --weight=3
|
2022-01-14 23:57:33 +01:00
|
|
|
|
2018-08-14 22:18:22 +02:00
|
|
|
systemctl restart sogo
|
|
|
|
systemctl restart stunnel4
|
2019-06-07 23:09:30 +02:00
|
|
|
|
2022-01-14 23:57:33 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2019-06-07 23:09:30 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|