diff --git a/check_process b/check_process index 9f8650a..fb678a9 100644 --- a/check_process +++ b/check_process @@ -3,9 +3,7 @@ domain="domain.tld" path="/path" is_public=1 - language="fr" - admin="john" - password="1Strong-Password" + with_mysql=1 ; Checks pkg_linter=1 setup_sub_dir=1 @@ -18,6 +16,16 @@ backup_restore=1 multi_instance=1 change_url=1 +;; Test without mysql + ; Manifest + domain="domain.tld" + path="/path" + is_public=1 + with_mysql=0 + ; Checks + setup_sub_dir=1 + upgrade=1 + backup_restore=1 ;;; Options Email= Notification=none diff --git a/manifest.json b/manifest.json index dc9cceb..c110408 100644 --- a/manifest.json +++ b/manifest.json @@ -45,6 +45,15 @@ "name": "is_public", "type": "boolean", "default": true + }, + { + "name": "with_mysql", + "type": "boolean", + "ask": { + "en": "Do you need a MySQL database?", + "fr": "Avez-vous besoin d'une base de données MySQL ?" + }, + "default": false } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index 6a10801..e6bb09d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -19,3 +19,60 @@ pkg_dependencies="php-uuid php${YNH_PHP_VERSION}-tidy php${YNH_PHP_VERSION}-redi #================================================= # FUTURE OFFICIAL HELPERS #================================================= + +# 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\` has important message for you" + + 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" +} diff --git a/scripts/backup b/scripts/backup index 4bae54f..7889fc2 100755 --- a/scripts/backup +++ b/scripts/backup @@ -32,6 +32,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -67,9 +68,12 @@ ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_print_info --message="Backing up the MySQL database..." -ynh_mysql_dump_db --database="$db_name" > db.sql +if [ $with_mysql -eq 1 ] +then + ynh_print_info --message="Backing up the MySQL database..." + ynh_mysql_dump_db --database="$db_name" > db.sql +fi #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 51a13fc..112b87c 100755 --- a/scripts/install +++ b/scripts/install @@ -28,6 +28,7 @@ domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC timezone="$(date +%:::z)" +with_mysql=$YNH_APP_ARG_WITH_MYSQL app=$YNH_APP_INSTANCE_NAME @@ -49,6 +50,7 @@ ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=with_mysql --value=$with_mysql #================================================= # INSTALL DEPENDENCIES @@ -68,12 +70,16 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # CREATE A MYSQL DATABASE #================================================= -ynh_script_progression --message="Creating a MySQL database..." --weight=2 -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name +if [ $with_mysql -eq 1 ] +then + ynh_script_progression --message="Creating a MySQL database..." --weight=2 + + db_name=$(ynh_sanitize_dbid --db_name=$app) + db_user=$db_name + ynh_app_setting_set --app=$app --key=db_name --value=$db_name + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name +fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -150,6 +156,29 @@ ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +if [ $with_mysql -eq 1 ] +then + ynh_script_progression --message="Sending a readme for the admin..." --weight=1 + + message="SnappyMail was successfully installed :) with the password found in + + Please open the admin UI https://$domain$path_url/?admin to configure your mail server settings. Login with user "admin" and password from the file /var/www/webmail/data/_data_/_default_/admin_password.txt. + + Details for MySQL database to be enterted while registration process: + + Database login: $db_user + Database name: $db_name + Database password: $db_pwd + + If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/YunoHost-Apps/snappymail_ynh/issues" + + ynh_send_readme_to_admin "$message" +fi + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index bb3b60b..1527743 100755 --- a/scripts/remove +++ b/scripts/remove @@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) +with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql) #================================================= # REMOVE LOGROTATE CONFIGURATION @@ -32,10 +33,13 @@ ynh_remove_logrotate #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Removing the MySQL database..." --weight=1 -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +if [ $with_mysql -eq 1 ]; then + ynh_script_progression --message="Removing the MySQL database..." --weight=2 + + # Remove a database if it exists, along with the associated user + ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +fi #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/restore b/scripts/restore index 53ebca6..48c8396 100755 --- a/scripts/restore +++ b/scripts/restore @@ -34,6 +34,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -91,11 +92,14 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=1 -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +if [ $with_mysql -eq 1 ]; then + ynh_script_progression --message="Restoring the MySQL database..." --weight=2 + + db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +fi #================================================= # RESTORE THE LOGROTATE CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index f9f5ca4..ef46f38 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +with_mysql=$(ynh_app_setting_get --app=$app --key=with_mysql) #================================================= # CHECK VERSION