_common.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #=================================================
  3. # COMMON VARIABLES
  4. #=================================================
  5. YNH_PHP_VERSION="7.3"
  6. extra_php_dependencies="php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-fpm php${YNH_PHP_VERSION}-common php${YNH_PHP_VERSION}-curl php${YNH_PHP_VERSION}-intl php${YNH_PHP_VERSION}-xmlrpc php${YNH_PHP_VERSION}-mysql php${YNH_PHP_VERSION}-gd php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-zip"
  7. #=================================================
  8. # PERSONAL HELPERS
  9. #=================================================
  10. #=================================================
  11. # EXPERIMENTAL HELPERS
  12. #=================================================
  13. #=================================================
  14. # FUTURE OFFICIAL HELPERS
  15. #=================================================
  16. # Send an email to inform the administrator
  17. #
  18. # usage: ynh_send_readme_to_admin app_message [recipients]
  19. # | arg: app_message - The message to send to the administrator.
  20. # | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
  21. # example: "root admin@domain"
  22. # If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
  23. # example: "root admin@domain user1 user2"
  24. ynh_send_readme_to_admin() {
  25. local app_message="${1:-...No specific information...}"
  26. local recipients="${2:-root}"
  27. # Retrieve the email of users
  28. find_mails () {
  29. local list_mails="$1"
  30. local mail
  31. local recipients=" "
  32. # Read each mail in argument
  33. for mail in $list_mails
  34. do
  35. # Keep root or a real email address as it is
  36. if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
  37. then
  38. recipients="$recipients $mail"
  39. else
  40. # But replace an user name without a domain after by its email
  41. if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
  42. then
  43. recipients="$recipients $mail"
  44. fi
  45. fi
  46. done
  47. echo "$recipients"
  48. }
  49. recipients=$(find_mails "$recipients")
  50. local mail_subject="☁️🆈🅽🅷☁️: \`$app\` has important message for you"
  51. local mail_message="This is an automated message from your beloved YunoHost server.
  52. Specific information for the application $app.
  53. $app_message
  54. ---
  55. Automatic diagnosis data from YunoHost
  56. $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
  57. # Define binary to use for mail command
  58. if [ -e /usr/bin/bsd-mailx ]
  59. then
  60. local mail_bin=/usr/bin/bsd-mailx
  61. else
  62. local mail_bin=/usr/bin/mail.mailutils
  63. fi
  64. # Send the email to the recipients
  65. echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
  66. }