nextcloud-updates.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # Version 1.3
  3. #
  4. # v1.3 CHANGES:
  5. # - Added check for configured apache-user and basepath exist.
  6. # v1.2 CHANGES:
  7. # - Updated nextcloud release check to actually get latest version from the release-url
  8. # v1.1 CHANGES:
  9. # - Updated query for installed version to versionstring instead of version
  10. #
  11. # WARNING: Current logic in the check will report wrong version as upgrade when a release is withdrawn from a/the release-url.
  12. # Installation:
  13. # This file should be place on a/the nextcloud host in /usr/lib/check_mk_agent/local
  14. # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/nextcloud-updates.sh
  15. #
  16. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  17. # License: GNU General Public License v2
  18. RELEASEURL="https://download.nextcloud.com/server/releases/"
  19. #basepath of Nextcloud's occ executable
  20. BASEPATH="/var/www/html"
  21. # set the correct user for running the commands ( either apache or www-data, this depends on your Linux-Distribution)
  22. APACHEUSER="apache"
  23. ######################
  24. # The code below should not be changed, unless you know EXACTLY what you are doing.
  25. # All confogureable parameters are above this section.
  26. ######################
  27. # check if jq package is present on the system
  28. /usr/bin/which jq >/dev/null 2>&1
  29. if [ $? -ne 0 ]; then
  30. echo "2 \"NextCloud\" - NextCloud localcheck requires jq package to be installed"
  31. echo "2 \"NextCloud Apps\" - NextCloud localcheck requires jq package to be installed"
  32. exit;
  33. fi
  34. # check if configured apache user exists
  35. if ! id -u "$APACHEUSER" >/dev/null 2>&1; then
  36. echo "2 \"NextCloud\" - NextCloud localcheck webserver user does not exist, check configuration!"
  37. echo "2 \"NextCloud Apps\" - NextCloud localcheck webserver user does not exist, check configuration!"
  38. exit;
  39. fi
  40. # check if configured basepath exists
  41. if [ ! -d "$BASEPATH" ]; then
  42. echo "2 \"NextCloud\" - NextCloud localcheck could not find configured basepath, check configuration!"
  43. echo "2 \"NextCloud Apps\" - NextCloud localcheck could not find configured basepath, check configuration!"
  44. exit;
  45. fi
  46. # Get current installed Nextcloud version-information
  47. # in v29.x.x version gives more detail, which is not given by the check on installed version, so switched to versionstring instead.
  48. NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')
  49. # Get latest avaiable version information
  50. # In v29.x.x this has changed outputs <name-of-instance> <version>,
  51. NCAVAILABLE=$(curl -s $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//')
  52. # compare resuts of installed and available version and report update available if they differ
  53. if [ $NCINSTALLED != $NCAVAILABLE ]; then
  54. echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
  55. else
  56. sudo -u $APACHEUSER php $BASEPATH/occ status -e
  57. if [ $? -eq 0 ]; then
  58. echo "0 \"NextCloud\" - NextCloud all up to date"
  59. elif [ $? -eq 1 ]; then
  60. echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
  61. elif [ $? -eq 2 ]; then
  62. echo "2 \"NextCloud\" - NextCloud Core needs updating"
  63. fi
  64. fi
  65. APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
  66. if [[ $APPRESULT == *"All apps are up-to-date"* ]]; then
  67. echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
  68. else
  69. UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
  70. echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
  71. fi