diff --git a/conf/mail.exs b/conf/mail.exs new file mode 100644 index 0000000..f22ef70 --- /dev/null +++ b/conf/mail.exs @@ -0,0 +1,18 @@ + +config :mobilizon, Mobilizon.Web.Email.Mailer, + adapter: Bamboo.SMTPAdapter, + server: "127.0.0.1", + #hostname: "127.0.0.1", + # usually 25, 465 or 587 + port: 25, + username: "__YNH_USER__", + password: "__YNH_USER_PASSWORD__", + # can be `:always` or `:never` + tls: :never, + allowed_tls_versions: [:"tlsv1.2"], + retries: 1, + # can be `true` + no_mx_lookups: false, + # can be `:always`. If your smtp relay requires authentication set it to `:always`. + auth: :always + diff --git a/scripts/install b/scripts/install index 88ed3f0..b657d9c 100644 --- a/scripts/install +++ b/scripts/install @@ -28,9 +28,8 @@ path_url="/" admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE - admin_email=$(ynh_user_get_info $admin 'mail') - +ynh_user_password=$(ynh_string_random --length=30) app=$YNH_APP_INSTANCE_NAME #================================================= @@ -57,6 +56,7 @@ 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=language --value=$language ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email +ynh_app_setting_set --app=$app --key=ynh_user_password --value=$ynh_user_password #================================================= # STANDARD MODIFICATIONS @@ -130,6 +130,9 @@ ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app --home_dir=$final_path +yunohost user create ${app}_notifs --firstname "Mobilizon" --lastname "Notifications" --mail ${app}_notifs@$domain --password "$ynh_user_password" -q 0 +yunohost user update ${app}_notifs --add-mailalias $app@$domain --add-mailforward $admin_email + #================================================= # SPECIFIC SETUP #================================================= @@ -157,9 +160,12 @@ pushd $final_path/$app popd cat "../conf/ldap.exs" >> "$config" +cat "../conf/mail.exs" >> "$config" pushd $final_path/$app chmod o-rwx $config + ynh_replace_string --match_string="__YNH_USER__" --replace_string="${app}_notifs" --target_file="$config" + ynh_replace_string --match_string="__YNH_USER_PASSWORD__" --replace_string="${ynh_user_password}" --target_file="$config" # Compile *again* because we added ldap conf in between... dunno if the first is relevant sudo -u "$app" MIX_ENV=prod mix compile ynh_secure_remove --file="/tmp/setup_db.psql" diff --git a/scripts/remove b/scripts/remove index 7a6b0af..578eb37 100644 --- a/scripts/remove +++ b/scripts/remove @@ -107,6 +107,8 @@ ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete --username=$app +yunohost user delete ${app}_notifs + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 1218c66..6ca26c2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -34,6 +34,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) port=$(ynh_app_setting_get --app=$app --key=port) +ynh_user_password=$(ynh_app_setting_get --app=$app --key=ynh_user_password) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -69,6 +70,9 @@ ynh_script_progression --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir=$final_path +yunohost user create ${app}_notifs --firstname "Mobilizon" --lastname "Notifications" --mail ${app}_notifs@$domain --password "$ynh_user_password" -q 0 +yunohost user update ${app}_notifs --add-mailalias $app@$domain --add-mailforward $admin_email + #================================================= # RESTORE USER RIGHTS #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 4e7524f..a97a13d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -102,12 +102,22 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line if ynh_version_gt "0.1.1" "${previous_version}" ; then ynh_script_progression --message="Upgrade configuration to 1.0.0..." + ynh_user_password=$(ynh_string_random --length=30) + ynh_app_setting_set --app=$app --key=ynh_user_password --value=$ynh_user_password + + yunohost user create ${app}_notifs --firstname "Mobilizon" --lastname "Notifications" --mail ${app}_notifs@$domain --password "$ynh_user_password" -q 0 + yunohost user update ${app}_notifs --add-mailalias $app@$domain --add-mailforward $admin_email + config="$final_path/$app/config/prod.secret.exs" ynh_backup_if_checksum_is_different --file="$config" - # Implement ldap + # Implement ldap and mail cat "../conf/ldap.exs" >> "$config" + cat "../conf/mail.exs" >> "$config" + ynh_replace_string --match_string="__YNH_USER__" --replace_string="${app}_notifs" --target_file="$config" + ynh_replace_string --match_string="__YNH_USER_PASSWORD__" --replace_string="${ynh_user_password}" --target_file="$config" + # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$config" fi