mirror of
https://github.com/YunoHost-Apps/flarum_ynh.git
synced 2024-09-03 18:36:24 +02:00
Merge pull request #58 from YunoHost-Apps/patch-email
Email admin with their credentials
This commit is contained in:
commit
8c5b136fa5
3 changed files with 137 additions and 82 deletions
|
@ -50,9 +50,9 @@
|
||||||
"name": "admin",
|
"name": "admin",
|
||||||
"type": "user",
|
"type": "user",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose the admin user",
|
"en": "Choose the admin user (required for automatic post-installation)",
|
||||||
"fr": "Choisissez l’administrateur",
|
"fr": "Choisissez l’administrateur (nécessaire pour la post-installation automatique)",
|
||||||
"de": "Wählen einen Administrator"
|
"de": "Wählen einen Administrator (erforderlich für die automatische Nachinstallation)"
|
||||||
},
|
},
|
||||||
"example": "johndoe",
|
"example": "johndoe",
|
||||||
"optional": true
|
"optional": true
|
||||||
|
@ -60,9 +60,9 @@
|
||||||
{
|
{
|
||||||
"name": "title",
|
"name": "title",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose a title for your forum",
|
"en": "Choose a title for your forum (required for automatic post-installation)",
|
||||||
"fr": "Choisissez un titre pour votre forum",
|
"fr": "Choisissez un titre pour votre forum (nécessaire pour la post-installation automatique)",
|
||||||
"de": "Wählen einen Titel für eure Internetforum"
|
"de": "Wählen einen Titel für eure Internetforum (erforderlich für die automatische Nachinstallation)"
|
||||||
},
|
},
|
||||||
"example": "My forum",
|
"example": "My forum",
|
||||||
"default": "",
|
"default": "",
|
||||||
|
|
|
@ -10,3 +10,52 @@ exec_as() {
|
||||||
sudo -u "$USER" "$@"
|
sudo -u "$USER" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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 information...}"
|
||||||
|
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 information 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"
|
||||||
|
}
|
||||||
|
|
|
@ -249,7 +249,13 @@ for username in $(ynh_user_list); do
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
>&2 echo "Installation successfull. Admin : $admin, password : $admin_pwd. Change it!"
|
app_message="User : $admin, password : $admin_pwd
|
||||||
|
Change your password!
|
||||||
|
Your forum is accessible at https://$domain/$path_url"
|
||||||
|
>&2 echo $app_message
|
||||||
|
ynh_send_readme_to_admin "$app_message" "$admin"
|
||||||
else
|
else
|
||||||
>&2 echo "Installation successfull. Post-installation required, visit your Flarum instance!"
|
app_message="Post-installation required, visit your Flarum instance."
|
||||||
|
>&2 echo $app_message
|
||||||
|
ynh_send_readme_to_admin "$app_message" "$admin"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue