1
0
Fork 0
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:
Titus PiJean 2018-02-14 10:54:14 +01:00 committed by GitHub
commit 8c5b136fa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 137 additions and 82 deletions

View file

@ -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 ladministrateur", "fr": "Choisissez ladministrateur (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": "",

View file

@ -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"
}

View file

@ -83,28 +83,28 @@ composer_path=/opt/${app}_composer
# Test if composer is installed # Test if composer is installed
if ! type "${composer_path}/composer" > /dev/null; then if ! type "${composer_path}/composer" > /dev/null; then
# Prepare composer directories # Prepare composer directories
sudo mkdir -p $composer_path sudo mkdir -p $composer_path
sudo mkdir -p $composer_path/cache sudo mkdir -p $composer_path/cache
sudo chown -R $app:www-data $composer_path sudo chown -R $app:www-data $composer_path
sudo chmod -R 0775 $composer_path sudo chmod -R 0775 $composer_path
# Install composer (https://getcomposer.org) # Install composer (https://getcomposer.org)
EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q) EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
php -r "copy('https://getcomposer.org/installer', '$composer_path/composer-setup.php');" php -r "copy('https://getcomposer.org/installer', '$composer_path/composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', '$composer_path/composer-setup.php');") ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', '$composer_path/composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ] if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
then then
sudo su - $app -s /bin/bash -c "php $composer_path/composer-setup.php --install-dir=$composer_path --filename=composer --quiet" sudo su - $app -s /bin/bash -c "php $composer_path/composer-setup.php --install-dir=$composer_path --filename=composer --quiet"
RESULT=$? RESULT=$?
else else
>&2 echo 'ERROR: Invalid Composer installer signature' >&2 echo 'ERROR: Invalid Composer installer signature'
RESULT=1 RESULT=1
fi fi
if [ $RESULT != 0 ] if [ $RESULT != 0 ]
then then
ynh_die 'Composer could not be installed' ynh_die 'Composer could not be installed'
fi fi
fi fi
@ -193,48 +193,48 @@ systemctl reload nginx
# Only if admin user or title were specified # Only if admin user or title were specified
if [[ -n $admin && -n $title ]]; then if [[ -n $admin && -n $title ]]; then
finalflarumconf="$final_path/configuration.yml" finalflarumconf="$final_path/configuration.yml"
cp ../sources/configuration.yml $finalflarumconf cp ../sources/configuration.yml $finalflarumconf
admin_pwd=$(ynh_string_random 8) admin_pwd=$(ynh_string_random 8)
sed -i "s@YNH_APP_DOMAIN@$domain@g" $finalflarumconf sed -i "s@YNH_APP_DOMAIN@$domain@g" $finalflarumconf
sed -i "s@/YNH_WWW_PATH@$path_url@g" $finalflarumconf sed -i "s@/YNH_WWW_PATH@$path_url@g" $finalflarumconf
sed -i "s@YNH_WWW_APP@$app@g" $finalflarumconf sed -i "s@YNH_WWW_APP@$app@g" $finalflarumconf
sed -i "s@YNH_DB_PASS@$db_pwd@g" $finalflarumconf sed -i "s@YNH_DB_PASS@$db_pwd@g" $finalflarumconf
sed -i "s@YNH_ADMIN_USER@$admin@g" $finalflarumconf sed -i "s@YNH_ADMIN_USER@$admin@g" $finalflarumconf
sed -i "s@YNH_ADMIN_PASS@$admin_pwd@g" $finalflarumconf sed -i "s@YNH_ADMIN_PASS@$admin_pwd@g" $finalflarumconf
admin_mail=$(ynh_user_get_info $admin mail) admin_mail=$(ynh_user_get_info $admin mail)
sed -i "s%YNH_ADMIN_EMAIL%$admin_mail%g" $finalflarumconf sed -i "s%YNH_ADMIN_EMAIL%$admin_mail%g" $finalflarumconf
sed -i "s@YNH_FORUM_TITLE@$title@g" $finalflarumconf sed -i "s@YNH_FORUM_TITLE@$title@g" $finalflarumconf
cd "$final_path" cd "$final_path"
exec_as www-data \ exec_as www-data \
php -d memory_limit=-1 flarum install -f configuration.yml php -d memory_limit=-1 flarum install -f configuration.yml
# Generate and add root token for user creation and deletion # Generate and add root token for user creation and deletion
roottoken=$(ynh_string_random 40) roottoken=$(ynh_string_random 40)
apitablesql="CREATE TABLE IF NOT EXISTS api_keys (api_key TEXT(40) NOT NULL)" apitablesql="CREATE TABLE IF NOT EXISTS api_keys (api_key TEXT(40) NOT NULL)"
rootsql="INSERT INTO api_keys VALUES ('"$roottoken"')" rootsql="INSERT INTO api_keys VALUES ('"$roottoken"')"
ynh_mysql_execute_as_root "$apitablesql" $db_name ynh_mysql_execute_as_root "$apitablesql" $db_name
ynh_mysql_execute_as_root "$rootsql" $db_name ynh_mysql_execute_as_root "$rootsql" $db_name
ynh_app_setting_set "$app" root_token "$roottoken" ynh_app_setting_set "$app" root_token "$roottoken"
# Install the SSOwat auth extension # Install the SSOwat auth extension
#sudo su - www-data -s /bin/bash -c "cd $final_path && /opt/flarum_composer/composer require 'tituspijean/flarum-ext-auth-ssowat:*@dev'" #sudo su - www-data -s /bin/bash -c "cd $final_path && /opt/flarum_composer/composer require 'tituspijean/flarum-ext-auth-ssowat:*@dev'"
# Configure SSOwat auth extension # Configure SSOwat auth extension
#ssowatdomain=$(</etc/yunohost/current_host) #ssowatdomain=$(</etc/yunohost/current_host)
#data='{"flarum-ext-auth-ssowat.address": "'$ssowatdomain'","flarum-ext-auth-ssowat.onlyUse": true}' #data='{"flarum-ext-auth-ssowat.address": "'$ssowatdomain'","flarum-ext-auth-ssowat.onlyUse": true}'
#rep=$(curl -s -o /dev/null -w "%{http_code}" -k -i \ #rep=$(curl -s -o /dev/null -w "%{http_code}" -k -i \
# -H "Content-Type: application/json" \ # -H "Content-Type: application/json" \
# -H "Authorization: Token $roottoken; userId=1" \ # -H "Authorization: Token $roottoken; userId=1" \
# -X POST -d "$data" \ # -X POST -d "$data" \
# -L https://${domain}${path}/api/settings ) # -L https://${domain}${path}/api/settings )
# #
#if [[ $rep != 204 ]]; then #if [[ $rep != 204 ]]; then
# ynh_die "ERROR: Could not configure SSOwat extension" # ynh_die "ERROR: Could not configure SSOwat extension"
#fi #fi
# Create missing users # Create missing users
for username in $(ynh_user_list); do for username in $(ynh_user_list); do
if [ "$username" == "$admin" ]; then continue; else if [ "$username" == "$admin" ]; then continue; else
userpass=$(ynh_string_random 16) userpass=$(ynh_string_random 16)
usermail=$(ynh_user_get_info $username 'mail') usermail=$(ynh_user_get_info $username 'mail')
@ -248,8 +248,14 @@ for username in $(ynh_user_list); do
ynh_die "ERROR: Flarum account creation failed for $username" ynh_die "ERROR: Flarum account creation failed for $username"
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