nextcloud-updates.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # Version 1.3
  3. #
  4. # v1.3 CHANGES:
  5. # - Added check for configured apoache-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. RELEASEURL="https://download.nextcloud.com/server/releases/"
  17. #basepath of Nextcloud's occ executable
  18. BASEPATH="/var/www/html"
  19. # set the correct user for running the commands ( either apache or www-data, this depends on your Linux-Distribution)
  20. APACHEUSER="apache"
  21. # check if jq package is present on the system
  22. /usr/bin/which jq >/dev/null 2>&1
  23. if [ $? -ne 0 ]; then
  24. echo "2 \"NextCloud\" - NextCloud localcheck requires jq package to be installed"
  25. echo "2 \"NextCloud Apps\" - NextCloud localcheck requires jq package to be installed"
  26. exit;
  27. fi
  28. # check if configured apache user exists
  29. if ! id -u "$APACHEUSER" >/dev/null 2>&1; then
  30. echo "2 \"NextCloud\" - NextCloud localcheck webserver user does not exist, check configuration!"
  31. echo "2 \"NextCloud Apps\" - NextCloud localcheck webserver user does not exist, check configuration!"
  32. exit;
  33. fi
  34. # check if configured basepath exists
  35. if [ ! -d "$BASEPATH" ]; then
  36. echo "2 \"NextCloud\" - NextCloud localcheck could not find configured basepath, check configuration!"
  37. echo "2 \"NextCloud Apps\" - NextCloud localcheck could not find configured basepath, check configuration!"
  38. exit;
  39. fi
  40. # Get current installed Nextcloud version-information
  41. # in v29.x.x version gives more detail, which is not given by the check on installed version, so switched to versionstring instead.
  42. NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')
  43. # Get latest avaiable version information
  44. # In v29.x.x this has changed outputs <name-of-instance> <version>,
  45. NCAVAILABLE=$(curl -s $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//')
  46. # compare resuts of installed and available version and report update available if they differ
  47. if [ $NCINSTALLED != $NCAVAILABLE ]; then
  48. echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
  49. else
  50. sudo -u $APACHEUSER php $BASEPATH/occ status -e
  51. if [ $? -eq 0 ]; then
  52. echo "0 \"NextCloud\" - NextCloud all up to date"
  53. elif [ $? -eq 1 ]; then
  54. echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
  55. elif [ $? -eq 2 ]; then
  56. echo "2 \"NextCloud\" - NextCloud Core needs updating"
  57. fi
  58. fi
  59. APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
  60. if [[ $APPRESULT == *"All apps are up-to-date"* ]]; then
  61. echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
  62. else
  63. UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
  64. echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
  65. fi