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

164 lines
5.8 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
#=================================================
2022-01-14 23:57:33 +01:00
# IMPORT GENERIC HELPERS
#=================================================
2016-03-18 18:38:54 +01:00
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
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2022-01-14 23:57:33 +01:00
#=================================================
2018-08-14 22:18:22 +02:00
# RETRIEVE ARGUMENTS FROM THE MANIFEST
2022-01-14 23:57:33 +01:00
#=================================================
2018-08-14 22:18:22 +02:00
domain=$YNH_APP_ARG_DOMAIN
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
2018-08-14 22:18:22 +02:00
# Set variable
path_url="/SOGo"
# final_path="/opt/yunohost/$app"
2016-03-18 18:38:54 +01:00
2018-08-14 22:18:22 +02:00
# Register (book) web path
ynh_webpath_register --app $app --domain $domain --path_url $path_url
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
2022-01-14 23:57:33 +01:00
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
2016-03-18 18:38:54 +01:00
2018-08-14 22:18:22 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2022-01-14 23:57:33 +01:00
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
port=$(ynh_find_port --port 20000)
ynh_app_setting_set --app=$app --key=web_port --value=$port
smtp_port=$(ynh_find_port --port $((port+1)))
ynh_app_setting_set --app=$app --key=smtp_port --value=$smtp_port
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
#=================================================
2018-08-14 22:18:22 +02:00
# INSTALL DEPENDENCIES
2022-01-14 23:57:33 +01:00
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=1
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
ynh_install_app_dependencies $pkg_dependencies
#=================================================
2018-08-14 22:18:22 +02:00
# CREATE A MYSQL DATABASE
2022-01-14 23:57:33 +01:00
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=1
db_name=$(ynh_sanitize_dbid --db_name=$app)
2018-08-14 22:18:22 +02:00
db_user=$db_name
2022-01-14 23:57:33 +01:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
ynh_script_progression --message="Configuring application..." --weight=3
2016-03-18 18:38:54 +01:00
2018-08-14 22:18:22 +02:00
# Configure SOGO
mkdir -p /etc/$app
ynh_add_config --template="sogo.conf" --destination="/etc/$app/sogo.conf"
2016-03-18 18:38:54 +01:00
2018-08-14 22:18:22 +02:00
# 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
2022-01-15 10:16:51 +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
2016-03-18 18:38:54 +01: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"
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
2018-08-14 22:18:22 +02:00
config_nginx
2016-03-18 20:36:22 +01:00
2018-08-14 22:18:22 +02:00
#=================================================
2022-01-14 23:57:33 +01:00
# SECURE FILES AND DIRECTORIES
2018-08-14 22:18:22 +02:00
#=================================================
2022-01-14 23:57:33 +01:00
ynh_script_progression --message="Protecting directory..." --weight=1
2016-03-18 18:38:54 +01:00
2018-08-14 22:18:22 +02:00
set_permission
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
ynh_use_logrotate --logfile /var/log/$app/sogo.log --nonappend
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
if [ "$is_public" == '1' ];
then
ynh_permission_update --permission "main" --add "visitors"
2016-03-18 18:38:54 +01:00
fi
2022-01-14 23:57:33 +01:00
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"
2016-03-18 18:38:54 +01:00
2022-01-14 23:57:33 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2020-05-24 00:32:03 +02:00
2022-01-15 10:05:56 +01:00
yunohost service add $app --description="Groupware for E-Mail, Contacts and Calender" --log="/var/log/$app/$app.log"
2022-01-14 23:57:33 +01:00
#=================================================
# 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"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last