directadmin.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  3. # License: GNU General Public License v2
  4. # Version 0.1 (initial release)
  5. #
  6. # Version 0.2
  7. # Updated output to have updateable compontents comma-sepoarated.
  8. # Installation:
  9. # This file should be place on a/the nextcloud host in /usr/lib/check_mk_agent/local
  10. #
  11. # (optional) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path
  12. # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400 for once per day.
  13. #
  14. # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/direactadmin.sh
  15. ##########################################################################
  16. # Global definitions for the script - change if needed to fit your needs #
  17. ##########################################################################
  18. # Custombuild switch , set to 1 if you are using it.
  19. CustomBuild=1
  20. #####################################################################
  21. # DO NOT CHANGE BELOW UNLESS YOU EXACTLY KNOW WHAT YOU ARE DOING #
  22. #####################################################################
  23. # Define global path of directAdmin
  24. if [ $CustomBuild -eq 1 ]
  25. then
  26. DirAdmin_Path="/usr/local/directadmin/custombuild"
  27. else
  28. DirAdmin_Path="/usr/local/directadmin"
  29. fi
  30. # Check DirectAdmin Core updates
  31. DirectAdmin_Core_Update=$($DirAdmin_Path/build update)
  32. if [[ $DirectAdmin_Core_Update == *"is already latest" ]]
  33. then
  34. echo "0 \"DirectAdmin_Core\" - DirectAdmin core all up to date"
  35. else
  36. echo "1 \"DirectAdmin_Core\" - DirectAdmin core has a newer version available - consider updating"
  37. fi
  38. # Check DirectAdmin Core updates
  39. DirectAdmin_Core_Update=$($DirAdmin_Path/build update)
  40. if [[ $DirectAdmin_Core_Update == *"is already latest" ]]
  41. then
  42. echo "0 \"DirectAdmin_Core\" - DirectAdmin core all up to date"
  43. else
  44. echo "1 \"DirectAdmin_Core\" - DirectAdmin core has a newer version available - consider updating"
  45. fi
  46. # store version information from DirectAdmin packages
  47. DirectAdmin_Versions_Update=$($DirAdmin_Path/build versions)
  48. #Define updates Array
  49. updates=()
  50. # iterate over the collected data to find possible updates
  51. while read -r line; do
  52. if [[ $line =~ ^Latest\ version\ of\ (.+):\ (.+)$ ]]; then
  53. component="${BASH_REMATCH[1]}"
  54. latest="${BASH_REMATCH[2]}"
  55. elif [[ $line =~ ^Installed\ version\ of\ (.+):\ (.+)$ ]]; then
  56. installed="${BASH_REMATCH[2]}"
  57. # Compare versions using sort -V
  58. if [[ "$(printf '%s\n%s\n' "$installed" "$latest" | sort -V | head -n1)" != "$latest" ]]; then
  59. updates+=("$component")
  60. fi
  61. fi
  62. done <<< "$DirectAdmin_Versions_Update"
  63. if [[ ${#updates[@]} -eq 0 ]]; then
  64. echo "0 \"DirectAdmin\" - All DirectAdmin Versions are up to date"
  65. else
  66. update_list=$(IFS=,; echo "${updates[*]}")
  67. echo "1 \"DirectAdmin\" - DirectAdmin Versions ${update_list} have updates"
  68. fi