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/install

107 lines
3.3 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Import common cmd
source ./experimental_helper.sh
source ./_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
ynh_script_progression --message="Validating installation parameters..."
# RETRIEVE ARGUMENTS FROM THE MANIFEST
domain=$YNH_APP_ARG_DOMAIN
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
# Set variable
path_url="/SOGo"
# final_path="/opt/yunohost/$app"
# Register (book) web path
ynh_webpath_register --app $app --domain $domain --path_url $path_url
# Find a port for SOGo
ynh_script_progression --message="Finding available ports..."
port=$(ynh_find_port --port 20000)
smtp_port=$(ynh_find_port --port $((port+1)))
# STORE SETTINGS FROM MANIFEST
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app $app --key admin --value $admin
ynh_app_setting_set --app $app --key is_public --value $is_public
ynh_app_setting_set --app $app --key smtp_port --value $smtp_port
ynh_app_setting_set --app $app --key web_port --value $port
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
ynh_script_progression --message="Installing dependencies..." --weight=7
install_dependance
# CREATE A MYSQL DATABASE
ynh_script_progression --message="Configuring MySQL database..."
db_name=$(ynh_sanitize_dbid $app)
db_user=$db_name
ynh_app_setting_set --app $app --key db_name --value $db_name
ynh_app_setting_set --app $app --key db_user --value $db_user
ynh_mysql_setup_db --db_name $db_name --db_user $db_user
ynh_script_progression --message="Configuring application..." --weight=3
# Configure SOGO
mkdir -p /etc/$app
ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf"
# Configure stunnel
# To fix the issue https://sogo.nu/bugs/view.php?id=31 we need stunnel to be able to connect correctly to the smtp server
config_stunnel
# Install crontab
config_cron
#Configure Nginx
ynh_script_progression --message="Configuring nginx..." --weight=1
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..."
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"
if [ "$is_public" == '1' ];
then
ynh_permission_update --permission "main" --add "visitors"
fi
# 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="Installation of $app completed" --last