wp_update_site.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # v.0.0.0.1
  3. # 23.4.2024
  4. # scripts check wordpress site for updates and if updates avalable, updates site. Finally send notification.
  5. # syntax:
  6. # wp_update_site
  7. # <path_to_dir> - path to site direcory. Directory must exists and be acessible
  8. # <recipient> - email address to notify
  9. # <custom_subject> - optional. Custom subject text. If not defined uses default.
  10. . ./qbashlib.sh
  11. # Zkontroluj, zda je zadán první argument
  12. argument_exists "$1" "<path_to_dir>"
  13. # Zkontroluj, zda existuje adresář s instalací Wordpressu
  14. if [ ! -d "$1" ]; then
  15. echo "<path_to_dir> directory '$1' not found or not accssible."
  16. exit 1
  17. fi
  18. # Zkontroluj, zda je zadán třetí argument
  19. is_email $2
  20. if [ $? -eq 0 ]; then
  21. echo "<recipient> argument '$3' is not valid email address."
  22. exit 1
  23. fi
  24. site_name=$(dir_get_name "$1")
  25. default_subject="Update notification - $site_name"
  26. subject=$default_subject
  27. # Zkontroluj, zda je zadán třetí argument
  28. if [ ! -z "$3" ]; then
  29. subject=$4
  30. fi
  31. cd $1
  32. # Zkontrolujte aktualizace pro WordPress, pluginy a šablony
  33. wp_core_updates=$(wp core check-update)
  34. wp_plugin_updates=$(wp plugin list --update=available)
  35. wp_theme_updates=$(wp theme list --update=available)
  36. # Pokud jsou dostupné aktualizace, proveďte zálohu
  37. if [[ -n "$wp_core_updates" ]] || [[ -n "$wp_plugin_updates" ]] || [[ -n "$wp_theme_updates" ]]; then
  38. # Proveďte všechny aktualizace
  39. wp_result=$(wp core update)
  40. wp_result="$wp_result\n$(wp plugin update --all)"
  41. wp_result="$wp_result\n$(wp theme update --all)"
  42. body="Available updates:\n$wp_core_updates\n$wp_plugin_updates\n$wp_theme_updates\n"
  43. body="$body Processed updates:\n$wp_result"
  44. #echo "$body" | mail -s "$subject" $recipient
  45. echo "$subject -> $2\n$body"
  46. echo "Updates complete."
  47. else
  48. echo "No updates available."
  49. fi