2019-09-20 12:55:12 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
2021-08-22 13:21:33 +02:00
|
|
|
ynh_clean_check_starting
|
2019-09-20 12:55:12 +02:00
|
|
|
}
|
2021-08-21 17:30:03 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
2019-09-20 12:55:12 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2021-08-21 17:30:03 +02:00
|
|
|
path_url="/"
|
2019-09-20 12:55:12 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
test ! -e /usr/share/$app-web || ynh_die --message="Mailman3 is already installed !"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
test ! -e /etc/$app || ynh_die --message="Mailman3 is already installed !"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Finding an available port..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port --port=8095)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# mailman3-app database
|
|
|
|
db_name_app=$(ynh_sanitize_dbid --db_name="${app}_app")
|
|
|
|
db_user_app=$db_name_app
|
|
|
|
db_pwd_app=$(ynh_string_random --length=30)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name_app --value=$db_name_app
|
2019-09-20 12:55:12 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd_app --value=$db_pwd_app
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_psql_setup_db --db_user=$db_user_app --db_name=$db_name_app --db_pwd=$db_pwd_app
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
# mailman3-web database
|
2021-08-21 17:30:03 +02:00
|
|
|
db_name_web=$(ynh_sanitize_dbid --db_name="${app}_web")
|
|
|
|
db_user_web=$db_name_web
|
|
|
|
db_pwd_web=$(ynh_string_random --length=30)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name_web --value=$db_name_web
|
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd_web --value=$db_pwd_web
|
|
|
|
ynh_psql_setup_db --db_user=$db_user_web --db_name=$db_name_web --db_pwd=$db_pwd_web
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
# NGINX CONFIGURATION
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
# mailman3 core configuration
|
2021-08-21 17:30:03 +02:00
|
|
|
rest_api_admin_user="rest_admin"
|
2019-09-20 12:55:12 +02:00
|
|
|
rest_api_admin_pwd=$(head -n15 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c15)
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=rest_admin_user --value="$rest_api_admin_user"
|
2019-09-22 17:37:54 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=rest_admin_pwd --value="$rest_api_admin_pwd"
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_add_config --template="../conf/mailman.cfg" --destination="/etc/mailman3/mailman.cfg"
|
|
|
|
|
|
|
|
chmod 400 "/etc/mailman3/mailman.cfg"
|
|
|
|
chown list:list "/etc/mailman3/mailman.cfg"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
# hyperkitty configuration
|
2019-09-30 15:50:17 +02:00
|
|
|
archiver_key=$(head -n32 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c32)
|
2019-09-20 12:55:12 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=archiver_key --value="$archiver_key"
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_add_config --template="../conf/mailman-hyperkitty.cfg" --destination="/etc/mailman3/mailman-hyperkitty.cfg"
|
|
|
|
|
|
|
|
chmod 400 "/etc/mailman3/mailman-hyperkitty.cfg"
|
|
|
|
chown list:list "/etc/mailman3/mailman-hyperkitty.cfg"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2019-09-30 15:50:17 +02:00
|
|
|
# mailman3-web configuration
|
|
|
|
secret_key=$(head -n64 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c64)
|
2019-09-20 12:55:12 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=secret_key --value="$secret_key"
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_add_config --template="../conf/mailman-web.py" --destination="/etc/mailman3/mailman-web.py"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-25 03:39:10 +02:00
|
|
|
chmod 440 "/etc/mailman3/mailman-web.py"
|
|
|
|
chown list:www-data "/etc/mailman3/mailman-web.py"
|
|
|
|
|
2019-09-24 12:08:24 +02:00
|
|
|
#=================================================
|
|
|
|
# RUN DATABASE MIGRATIONS
|
|
|
|
#=================================================
|
2021-08-22 13:21:33 +02:00
|
|
|
ynh_script_progression --message="Running database migrations..."
|
2019-09-24 12:08:24 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
pushd /usr/share/mailman3-web
|
|
|
|
python3 manage.py migrate || ynh_die --message="Mailman3 migrations failed!"
|
|
|
|
popd
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-25 03:39:10 +02:00
|
|
|
#=================================================
|
|
|
|
# POSTFIX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring postfix mail server..."
|
|
|
|
|
|
|
|
# Add postfix configuration hook and regen postfix conf
|
|
|
|
cp -R ../sources/hooks/conf_regen/98-postfix_mailman3 /usr/share/yunohost/hooks/conf_regen/
|
|
|
|
yunohost tools regen-conf postfix
|
|
|
|
ynh_systemd_action --service_name=postfix --action="restart"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
systemctl enable $app.service --quiet
|
|
|
|
systemctl enable "$app-web".service --quiet
|
|
|
|
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2019-09-20 12:55:12 +02:00
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2019-09-30 15:50:17 +02:00
|
|
|
|
2021-08-25 03:39:10 +02:00
|
|
|
yunohost service add $app --description="Mailman3 daemon" --log="/var/log/$app/mailman.log"
|
|
|
|
yunohost service add "$app-web" --description="Mailman3 web daemon" --log="/var/log/$app/web/mailman-web.log"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# Start a systemd service
|
2021-08-25 03:39:10 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="restart"
|
|
|
|
ynh_systemd_action --service_name="$app-web" --action="restart"
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
# Make app public if necessary
|
2019-09-20 12:55:12 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2021-08-21 17:30:03 +02:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2019-09-20 12:55:12 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2019-09-20 12:55:12 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-08-21 17:30:03 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|