1
0

nextcloud-updates.sh 3.8 KB

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