mirror of
https://github.com/YunoHost-Apps/sogo_ynh.git
synced 2024-09-03 20:26:07 +02:00
144 lines
4.1 KiB
Bash
Executable file
144 lines
4.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
|
|
# Import common cmd
|
|
source ./experimental_helper.sh
|
|
source ./_common.sh
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
# LOAD SETTINGS
|
|
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=$(ynh_app_setting_get --app=$app --key=db_user)
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
# restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# UPGRADE SETTINGS FROM OLD INSTALL
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Fixing old settings..." --weight=1
|
|
|
|
if [[ ${is_public,,*} = "yes" ]]
|
|
then
|
|
is_public=1
|
|
ynh_app_setting_set --app $app --key is_public --value 1
|
|
fi
|
|
|
|
if [[ ${is_public,,*} = "no" ]]
|
|
then
|
|
is_public=0
|
|
ynh_app_setting_set --app $app --key is_public --value 0
|
|
fi
|
|
|
|
if [[ -z $port ]]
|
|
then
|
|
# Find a port for SOGo
|
|
port=$(ynh_find_port --port 20000)
|
|
ynh_app_setting_set --app $app --key web_port --value $port
|
|
fi
|
|
|
|
if [[ -z $db_name ]]
|
|
then
|
|
db_name=$app
|
|
ynh_app_setting_set --app $app --key db_name --value $db_name
|
|
fi
|
|
|
|
if [[ -z $db_user ]]
|
|
then
|
|
db_user=$app
|
|
ynh_app_setting_set --app $app --key db_user --value $db_user
|
|
fi
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
install_dependance
|
|
|
|
ynh_script_progression --message="Configuring application..."
|
|
|
|
# Configure SOGO
|
|
config_sogo
|
|
|
|
# Configure stunnel
|
|
config_stunnel
|
|
|
|
# Install crontab
|
|
config_cron
|
|
|
|
#Configure Nginx
|
|
config_nginx
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
ynh_script_progression --message="Protecting directory..."
|
|
set_permission
|
|
|
|
# configure the sso
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
if [ "$is_public" = "0" ];
|
|
then # Retire l'accès public
|
|
ynh_app_setting_delete --app $app --key skipped_uris
|
|
else
|
|
ynh_app_setting_set --app $app --key unprotected_uris --value "/"
|
|
fi
|
|
python3 add_sso_conf.py
|
|
|
|
# SETUP LOGROTATE
|
|
ynh_script_progression --message="Configuring log rotation..."
|
|
ynh_use_logrotate --logfile /var/log/$app/sogo.log --nonappend
|
|
|
|
# Register service
|
|
yunohost service add $app --log "/var/log/$app/sogo.log"
|
|
|
|
# Restart services
|
|
ynh_script_progression --message="Starting SOGo services..." --weight=3
|
|
systemctl restart sogo
|
|
systemctl restart stunnel4
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|