1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/sogo_ynh.git synced 2024-09-03 20:26:07 +02:00
sogo_ynh/scripts/upgrade

186 lines
6.7 KiB
Text
Raw Normal View History

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
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)
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
#=================================================
2022-01-15 12:05:29 +01:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2018-08-14 22:18:22 +02:00
2022-01-15 12:05:29 +01:00
if [[ -z $port ]]; then
2018-08-14 22:18:22 +02:00
# Find a port for SOGo
2022-01-15 12:05:29 +01:00
port=$(ynh_find_port --port=20000)
2022-01-15 11:55:45 +01:00
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
2022-01-15 12:05:29 +01:00
if [[ -z $db_name ]]; then
2018-08-14 22:18:22 +02:00
db_name=$app
2022-01-15 11:55:45 +01:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2018-08-14 22:18:22 +02:00
fi
2022-01-15 12:05:29 +01:00
if [[ -z $db_user ]]; then
2018-08-14 22:18:22 +02:00
db_user=$app
2022-01-15 11:55:45 +01:00
ynh_app_setting_set --app=$app --key=db_user --value=$db_user
fi
2022-01-15 11:58:38 +01:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="sync_client"; then
# Create the required permissions
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"
fi
2018-08-14 22:18:22 +02:00
#=================================================
# STANDARD MODIFICATIONS
2022-01-15 10:12:54 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2022-01-15 11:55:45 +01:00
ynh_script_progression --message="Upgrading dependencies..." --weight=1
2022-01-15 10:12:54 +01:00
ynh_install_app_dependencies $pkg_dependencies
2018-08-14 22:18:22 +02:00
2022-01-15 10:12:54 +01:00
#=================================================
# UPDATE A CONFIG FILE
#=================================================
2022-01-15 12:10:50 +01:00
ynh_script_progression --message="Configuring application..." --weight=1
2018-08-14 22:18:22 +02:00
# Configure SOGO
2022-01-15 10:12:54 +01:00
ynh_add_config --template="../conf/sogo.conf" --destination="/etc/$app/sogo.conf"
2018-08-14 22:18:22 +02:00
# Configure stunnel
2022-01-15 12:06:50 +01:00
ynh_add_config --template="../conf/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"
2018-08-14 22:18:22 +02:00
2022-01-15 10:05:56 +01:00
#=================================================
# SETUP A CRON
#=================================================
ynh_script_progression --message="Setuping a cron..." --weight=1
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
2022-01-15 10:11:21 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
2018-08-14 22:18:22 +02:00
config_nginx
2016-03-18 18:38:54 +01:00
2018-08-14 22:18:22 +02:00
#=================================================
2022-01-15 12:03:56 +01:00
# SECURE FILES AND DIRECTORIES
2018-08-14 22:18:22 +02:00
#=================================================
2022-01-15 12:03:56 +01:00
ynh_script_progression --message="Protecting directory..." --weight=1
chown -R $app:$app /etc/$app
chmod u=rwX,g=rX,o= -R /etc/$app
chown -R $app:$app /var/log/$app
chmod u=rwX,g=rX,o= -R /var/log/$app
2018-08-14 22:18:22 +02:00
# configure the sso
ynh_script_progression --message="Configuring permissions..."
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
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
2022-01-15 10:11:21 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2018-08-14 22:18:22 +02:00
# SETUP LOGROTATE
2022-01-15 10:11:21 +01:00
#=================================================
2022-01-15 12:03:56 +01:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2022-01-15 10:11:21 +01:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
2018-08-14 22:18:22 +02:00
2022-01-15 10:09:18 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd"
ynh_systemd_action --service_name=stunnel4 --action="restart" --log_path="systemd"
2020-05-24 00:32:03 +02:00
2022-01-15 10:09:18 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2022-01-14 23:57:33 +01:00
2022-01-15 10:09:18 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2022-01-14 23:57:33 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last