From bf9dbbb01be9f95b43f8047dcbbc49cfff0b4c94 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Mon, 25 Sep 2017 10:32:11 +0200 Subject: [PATCH] Add SMTP configuration --- conf/settings.py | 7 +++++++ scripts/_common.sh | 19 ++++++++++++++++++- scripts/install | 8 +++++--- scripts/restore | 3 ++- scripts/upgrade | 3 ++- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/conf/settings.py b/conf/settings.py index e4ea206..da0f464 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -554,6 +554,13 @@ EMAIL_SEND_HTML = True # Subject of emails includes site title EMAIL_SUBJECT_PREFIX = '[{0}] '.format(SITE_TITLE) +# SMTP settings +EMAIL_HOST="localhost" +EMAIL_HOST_USER="__NAME__" +EMAIL_HOST_PASSWORD="__SMTPPWD__" +EMAIL_PORT=465 +EMAIL_USE_SSL=True + # Enable remote hooks ENABLE_HOOKS = True diff --git a/scripts/_common.sh b/scripts/_common.sh index 72e18ea..dd4cc87 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,6 +1,23 @@ #!/bin/bash -# Source: https://github.com/YunoHost-Apps/coin_ynh/ +# Create a system user +# +# usage: ynh_system_user_create user_name [home_dir] +# | arg: user_name - Name of the system user that will be create +# | arg: home_dir - Path of the home dir for the user. Usually the final path of the app. If this argument is omitted, the user will be created without home +# | arg: password - user password (for SMTP access) +ynh_system_user_create_smtp () { + if ! ynh_system_user_exists "$1" # Check if the user exists on the system + then # If the user doesn't exist + if [ $# -ge 2 ]; then # If a home dir is mentioned + user_home_dir="-d $2" + else + user_home_dir="--no-create-home" + fi + user_home_dir="-d $2" + sudo useradd $user_home_dir --system --user-group $1 --shell /bin/false || ynh_die "Unable to create $1 system account" + fi +} ynh_psql_test_if_first_run() { if [ -f /etc/yunohost/psql ]; diff --git a/scripts/install b/scripts/install index ef9bf79..d99803a 100755 --- a/scripts/install +++ b/scripts/install @@ -101,8 +101,10 @@ ynh_add_nginx_config # CREATE DEDICATED USER #================================================= -# Create a system user -ynh_system_user_create "$app" +# Create system user for email notifications +smtp_pwd=$(ynh_string_random) +ynh_system_user_create_smtp "$app" "$smtp_pwd" +ynh_app_setting_set "$app" smtppwd "$smtp_pwd" #================================================= # SPECIFIC SETUP @@ -156,7 +158,7 @@ ynh_replace_string "__DOMAIN__" "$domain" "$final_path/venv/lib/python2.7 ynh_replace_string "__KEY__" "$key" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" ynh_replace_string "__PATHURL__" "$path_url" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" - +ynh_replace_string "__SMTPPWD__" "$smtp_pwd" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py" #================================================= # SPECIFIC SETUP Filling up the database diff --git a/scripts/restore b/scripts/restore index 656d58a..6a0145a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -31,6 +31,7 @@ domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get $app db_name) +smtp_pwd=$(ynh_app_setting_get $app smtppwd) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -60,7 +61,7 @@ ynh_restore_file "$final_path" #================================================= # Create the dedicated user (if not existing) -ynh_system_user_create "$app" +ynh_system_user_create_smtp "$app" "$smtp_pwd" #================================================= # RESTORE USER RIGHTS diff --git a/scripts/upgrade b/scripts/upgrade index 944ef92..b83db53 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,6 +22,7 @@ is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) port=$(ynh_app_setting_get $app port) db_name=$(ynh_app_setting_get $app db_name) +smtp_pwd=$(ynh_app_setting_get $app smtppwd) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -68,7 +69,7 @@ ynh_add_nginx_config #================================================= # Create a system user -ynh_system_user_create $app +ynh_system_user_create_smtp "$app" "$smtp_pwd" #================================================= # SPECIFIC UPGRADE