1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

Use ynh_send_readme_to_admin helper

This commit is contained in:
Jean-Baptiste Holcroft 2018-04-01 12:50:02 +02:00
parent 12b209a5a4
commit 851eed2914
3 changed files with 61 additions and 15 deletions

View file

@ -265,3 +265,52 @@ ynh_psql_drop_user() {
user="$1"
su --command="dropuser \"${user}\"" postgres
}
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin app_message [recipients]
# | arg: app_message - The message to send to the administrator.
# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
ynh_send_readme_to_admin() {
local app_message="${1:-...No specific informations...}"
local recipients="${2:-root}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
local mail_message="This is an automated message from your beloved YunoHost server.
Specific informations for the application $app.
$app_message
---
Automatic diagnosis data from YunoHost
$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
# Send the email to the recipients
echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
}

View file

@ -273,3 +273,14 @@ fi
#=================================================
systemctl reload nginx
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
message="
Weblate settings file : $settings
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/weblate_ynh
"
ynh_send_readme_to_admin "$message" "$admin"

View file

@ -207,7 +207,6 @@ then
weblate_fill_settings "$settings"
# send diff to the server administrator
mail_subject="'$app' settings diff from $previous_version to $current_version"
mail_message="
Weblate was updated from version $previous_version to $current_version
@ -225,20 +224,7 @@ then
For any issue, please file a bug in: https://github.com/YunoHost-Apps/weblate_ynh
"
# Email server admin - for ACTION
echo "$mail_message" | mail -s "$mail_subject" root -u root
# inform weblate's admin
mail_subject="'$app' was updated from $previous_version to $current_version"
mail_message="
Weblate was updated from version $previous_version to $current_version
A new settings.py has been created and a diff has been sent to root user.
Your administrator may have to update your settings.py to have a fully working installation.
"
# Email weblate's admin - for INFO
echo "$mail_subject" | mail -s "$mail_subject" "$admin_mail"
ynh_send_readme_to_admin "$mail_message" root "$admin_mail"
else
echo "Settings.py was not modified, using the new default file for $current_version."
# generate new defaults settings