mirror of
https://github.com/YunoHost-Apps/mailman3_ynh.git
synced 2024-09-03 19:36:17 +02:00
141 lines
5.7 KiB
Bash
Executable file
141 lines
5.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# INITIALIZE AND STORE SETTINGS
|
|
#=================================================
|
|
|
|
# Maybe add that as install arg ?
|
|
email="admin@$domain"
|
|
|
|
# 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"
|
|
ynh_app_setting_set --app="$app" --key="db_user_app" --value="$db_user_app"
|
|
ynh_app_setting_set --app="$app" --key="db_pwd_app" --value="$db_pwd_app"
|
|
|
|
# mailman3-web database
|
|
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_user_web" --value="$db_user_web"
|
|
ynh_app_setting_set --app="$app" --key="db_pwd_web" --value="$db_pwd_web"
|
|
|
|
# mailman3 core configuration
|
|
rest_api_admin_user="rest_admin"
|
|
rest_api_admin_pwd=$(head -n15 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c15)
|
|
ynh_app_setting_set --app="$app" --key="rest_api_admin_user" --value="$rest_api_admin_user"
|
|
ynh_app_setting_set --app="$app" --key="rest_api_admin_pwd" --value="$rest_api_admin_pwd"
|
|
|
|
# hyperkitty configuration
|
|
archiver_key=$(head -n32 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c32)
|
|
ynh_app_setting_set --app="$app" --key=archiver_key --value="$archiver_key"
|
|
|
|
# mailman3-web configuration
|
|
secret_key=$(head -n64 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c64)
|
|
ynh_app_setting_set --app="$app" --key=secret_key --value="$secret_key"
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
|
# Can' use resource helper because we need 2 dbs with specific names…
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
# mailman3-app database
|
|
ynh_psql_setup_db --db_user="$db_user_app" --db_name="$db_name_app" --db_pwd="$db_pwd_app"
|
|
|
|
# mailman3-web database
|
|
ynh_psql_setup_db --db_user="$db_user_web" --db_name="$db_name_web" --db_pwd="$db_pwd_web"
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding $app's configuration files..."
|
|
|
|
ynh_add_config --template="mailman.cfg" --destination="/etc/mailman3/mailman.cfg"
|
|
chmod 400 "/etc/mailman3/mailman.cfg"
|
|
chown list:list "/etc/mailman3/mailman.cfg"
|
|
|
|
ynh_add_config --template="mailman-hyperkitty.cfg" --destination="/etc/mailman3/mailman-hyperkitty.cfg"
|
|
chmod 400 "/etc/mailman3/mailman-hyperkitty.cfg"
|
|
chown list:list "/etc/mailman3/mailman-hyperkitty.cfg"
|
|
|
|
ynh_add_config --template="mailman-web.py" --destination="/etc/mailman3/mailman-web.py"
|
|
chmod 440 "/etc/mailman3/mailman-web.py"
|
|
chown list:www-data "/etc/mailman3/mailman-web.py"
|
|
|
|
#=================================================
|
|
# RUN DATABASE MIGRATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Running database migrations..."
|
|
pushd /usr/share/mailman3-web
|
|
python3 manage.py migrate || ynh_die --message="Mailman3 migrations failed!"
|
|
popd
|
|
|
|
#=================================================
|
|
# CREATE SUPERUSER
|
|
#=================================================
|
|
ynh_script_progression --message="Creating superuser..."
|
|
pushd /usr/share/mailman3-web
|
|
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('$admin', '$email', '$password')" | python manage.py shell
|
|
popd
|
|
|
|
#=================================================
|
|
# CONFIGURE MAINDOMAIN
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring maindomain..."
|
|
pushd /usr/share/mailman3-web
|
|
echo "UPDATE django_site SET domain='$domain',name='$domain' WHERE domain='example.com';" | python3 manage.py dbshell
|
|
popd
|
|
|
|
#=================================================
|
|
# 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
|
|
sudo -su list mailman aliases
|
|
ynh_systemd_action --service_name=postfix --action="restart"
|
|
|
|
#=================================================
|
|
# SYSTEM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd config
|
|
systemctl enable "$app.service" --quiet
|
|
systemctl enable "$app-web.service" --quiet
|
|
|
|
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"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting $app's systemd services..." --weight=1
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name="$app" --action="restart"
|
|
ynh_systemd_action --service_name="$app-web" --action="restart"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|