nextcloud-updates.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. 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. ######################
  22. # The code below should not be changed, unless you know EXACTLY what you are doing.
  23. # All confogureable parameters are above this section.
  24. ######################
  25. # check if jq package is present on the system
  26. /usr/bin/which jq >/dev/null 2>&1
  27. if [ $? -ne 0 ]; then
  28. echo "2 \"NextCloud\" - NextCloud localcheck requires jq package to be installed"
  29. echo "2 \"NextCloud Apps\" - NextCloud localcheck requires jq package to be installed"
  30. exit;
  31. fi
  32. # check if configured apache user exists
  33. if ! id -u "$APACHEUSER" >/dev/null 2>&1; then
  34. echo "2 \"NextCloud\" - NextCloud localcheck webserver user does not exist, check configuration!"
  35. echo "2 \"NextCloud Apps\" - NextCloud localcheck webserver user does not exist, check configuration!"
  36. exit;
  37. fi
  38. # check if configured basepath exists
  39. if [ ! -d "$BASEPATH" ]; then
  40. echo "2 \"NextCloud\" - NextCloud localcheck could not find configured basepath, check configuration!"
  41. echo "2 \"NextCloud Apps\" - NextCloud localcheck could not find configured basepath, check configuration!"
  42. exit;
  43. fi
  44. # Get current installed Nextcloud version-information
  45. # in v29.x.x version gives more detail, which is not given by the check on installed version, so switched to versionstring instead.
  46. NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')
  47. # Get latest avaiable version information
  48. # In v29.x.x this has changed outputs <name-of-instance> <version>,
  49. NCAVAILABLE=$(curl -s $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//')
  50. # compare resuts of installed and available version and report update available if they differ
  51. if [ $NCINSTALLED != $NCAVAILABLE ]; then
  52. echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
  53. else
  54. sudo -u $APACHEUSER php $BASEPATH/occ status -e
  55. if [ $? -eq 0 ]; then
  56. echo "0 \"NextCloud\" - NextCloud all up to date"
  57. elif [ $? -eq 1 ]; then
  58. echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
  59. elif [ $? -eq 2 ]; then
  60. echo "2 \"NextCloud\" - NextCloud Core needs updating"
  61. fi
  62. fi
  63. APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
  64. if [[ $APPRESULT == *"All apps are up-to-date"* ]]; then
  65. echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
  66. else
  67. UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
  68. echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
  69. fi