nextcloud-updates.sh 3.0 KB

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