From a17e7b37418c64f59c2b5cb3e9e597c611f961d1 Mon Sep 17 00:00:00 2001 From: anmol Date: Thu, 15 Oct 2020 08:44:09 +0530 Subject: [PATCH] Updated .env and send message to admin on fresh install --- conf/.env | 46 +++++++---------------- scripts/_common.sh | 2 +- scripts/install | 42 +++++++++++++++++---- scripts/send_readme_to_admin.sh | 66 +++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 40 deletions(-) create mode 100644 scripts/send_readme_to_admin.sh diff --git a/conf/.env b/conf/.env index b7bde89..458308b 100644 --- a/conf/.env +++ b/conf/.env @@ -13,7 +13,7 @@ APP_DEBUG=false # The encryption key. This is the most important part of the application. Keep # this secure otherwise, everyone will be able to access your application. # Must be 32 characters long exactly. -# Use `php artisan key:generate` to generate a random key. +# Use `php artisan key:generate` or `pwgen -s 32 1` to generate a random key. APP_KEY=random_key # Prevent information leakage by referring to IDs with hashIds instead of @@ -24,8 +24,13 @@ HASH_LENGTH=18 # The URL of your application. APP_URL=https://__DOMAIN__ +# Force using APP_URL as base url of your application. +# You should not need this, unless you are using subdirectory config. +APP_FORCE_URL=false + # Database information # To keep this information secure, we urge you to change the default password +# Currently only "mysql" compatible servers are working DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 @@ -45,7 +50,7 @@ DB_TEST_PASSWORD=secret DB_USE_UTF8MB4=true # Mail credentials used to send emails from the application. -MAIL_DRIVER=mail +MAIL_MAILER=smtp MAIL_HOST=127.0.0.1 MAIL_PORT=25 MAIL_USERNAME= @@ -54,6 +59,7 @@ MAIL_ENCRYPTION= # Outgoing emails will be sent with these identity MAIL_FROM_ADDRESS=monica@yunodomain MAIL_FROM_NAME="Monica" +# New registration notification sent to this email APP_EMAIL_NEW_USERS_NOTIFICATION=yunomail @@ -104,7 +110,7 @@ SESSION_LIFETIME=120 QUEUE_CONNECTION=sync # If you use redis, set the redis host or ip, like: -#REDIS_HOST=redis +REDIS_HOST=redis # Maximum allowed size for uploaded files, in kilobytes. # Make sure this is an integer, without commas or spaces. @@ -126,17 +132,14 @@ AWS_BUCKET= AWS_SERVER= # Allow Two Factor Authentication feature on your instance -MFA_ENABLED=false +MFA_ENABLED=true # Enable DAV support DAV_ENABLED=true -# CLIENT ID and SECRET used for the official mobile application -# This is to make sure that only the mobile application that you approve can -# access the route to let your users sign in with their credentials -# Note: the official mobile application is not currently available on the stores. -MOBILE_CLIENT_ID=__IDENTITY__ -MOBILE_CLIENT_SECRET=__KEY__ +# CLIENT ID and SECRET used for OAuth authentication +PASSPORT_PERSONAL_ACCESS_CLIENT_ID=__IDENTITY__ +PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET==__KEY__ # Allow to access general statistics about your instance through a public API # call @@ -146,27 +149,6 @@ ALLOW_STATISTICS_THROUGH_PUBLIC_API_ACCESS=false # like CASL or GDPR POLICY_COMPLIANT=true -# Have access to paid features available on https://monicahq.com, for free. -# Can be true or false. Default to false. -# If set to true, that means your users will have to pay to access the paid -# features. We use Stripe to do this. -REQUIRES_SUBSCRIPTION=false - -# Number of contacts allowed in the Free version if the instance requires -# a subscription -NUMBER_OF_ALLOWED_CONTACTS_FREE_ACCOUNT=10 - -# ONLY NECESSARY IF MONICA REQUIRES A SUBSCRIPTION TO WORK -# Leave blank unless you know what you are doing. -STRIPE_KEY= -STRIPE_SECRET= -PAID_PLAN_MONTHLY_FRIENDLY_NAME= -PAID_PLAN_MONTHLY_ID= -PAID_PLAN_MONTHLY_PRICE= -PAID_PLAN_ANNUAL_FRIENDLY_NAME= -PAID_PLAN_ANNUAL_ID= -PAID_PLAN_ANNUAL_PRICE= - # Enable geolocation services # This is used to translate addresses to GPS coordinates. ENABLE_GEOLOCATION=false @@ -187,4 +169,4 @@ ENABLE_WEATHER=false # https://darksky.net/dev/register # Darksky provides an api with 1000 free API calls per day # You need to enable the weather above if you provide an API key here. -DARKSKY_API_KEY= +DARKSKY_API_KEY= \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index 0f97942..094fc02 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="" +pkg_dependencies="redis-server" YNH_PHP_VERSION="7.3" diff --git a/scripts/install b/scripts/install index 14420d7..e450a67 100755 --- a/scripts/install +++ b/scripts/install @@ -9,6 +9,8 @@ source _common.sh source ynh_composer__2 source /usr/share/yunohost/helpers +source send_readme_to_admin.sh +source ynh_package_version #================================================= # MANAGE SCRIPT FAILURE @@ -28,6 +30,7 @@ is_public=$YNH_APP_ARG_IS_PUBLIC language=$YNH_APP_ARG_LANGUAGE random_key=$(ynh_string_random --length=32) email=$(ynh_user_get_info $admin 'mail') +password=$(ynh_string_random --length=8) app=$YNH_APP_INSTANCE_NAME @@ -59,14 +62,14 @@ ynh_app_setting_set --app=$app --key=random_key --value=$random_key #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A MYSQL DATABASE #================================================= -ynh_script_progression --message="Creating a MySQL database..." +ynh_script_progression --message="Creating a MySQL database..." db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name @@ -85,7 +88,7 @@ ynh_setup_source --dest_dir="$final_path" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." +ynh_script_progression --message="Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config @@ -93,7 +96,7 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." +ynh_script_progression --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app @@ -139,7 +142,7 @@ ynh_replace_string --match_string="language" --replace_string="$language" --targ ynh_script_progression --message="Deploying..." pushd "$final_path" - php$phpversion artisan monica:update --force + php$phpversion artisan setup:production --email=$email --password=$password -vvv -n php$phpversion artisan passport:keys php$phpversion artisan passport:client --password -n > key.txt mobile_id=$( cd $final_path && tail -2 key.txt | head -1 | cut -c 12- ) @@ -180,7 +183,7 @@ chown -R $app: $final_path #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -192,10 +195,35 @@ fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# SEND A README FOR THE ADMIN +#================================================= +# WARNING : theses command are used in INSTALL +# For any update do it in all files + +echo "Hi, +----------------------------------------------------------- +| +| Welcome to Monica v${last_version} +| +----------------------------------------------------------- +| You can now sign in to your account: +| username: $email +| password: $password +| URL: https://monica.anmol.net.in +| It is advised to change your password after first login. +----------------------------------------------------------- +Setup is done. Have fun. + + +" > mail_to_send + +ynh_send_readme_to_admin --app_message="$mail_to_send" --recipients="$email" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/send_readme_to_admin.sh b/scripts/send_readme_to_admin.sh new file mode 100644 index 0000000..ecc8959 --- /dev/null +++ b/scripts/send_readme_to_admin.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args + +# Send an email to inform the administrator +# +# usage: ynh_send_readme_to_admin app_message [recipients] +# | arg: -m --app_message= - The message to send to the administrator. +# | arg: -r, --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() { + # Declare an array to define the options of this helper. + declare -Ar args_array=( [m]=app_message= [r]=recipients= ) + local app_message + local recipients + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + local app_message="${app_message:-...No specific information...}" + local recipients="${recipients:-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')" + + # Define binary to use for mail command + if [ -e /usr/bin/bsd-mailx ] + then + local mail_bin=/usr/bin/bsd-mailx + else + local mail_bin=/usr/bin/mail.mailutils + fi + + # Send the email to the recipients + echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" +} \ No newline at end of file