1
0

nextcloud-updates.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # Version 1.2
  3. #
  4. # v1.2 CHANGES:
  5. # - updated nextcloud release check to actually get latest version from the release-url
  6. # v1.1 CHANGES:
  7. # - Updated query for installed version to versionstring instead of version
  8. #
  9. # WARNING: Current logic in the check will report wrong version as upgrade when a release is withdrawn from a/the release-url.
  10. RELEASEURL="https://download.nextcloud.com/server/releases/"
  11. #basepath of Nextcloud's occ executable
  12. BASEPATH="/var/www/html"
  13. # set the correct user for running the commands ( either apache or www-data, this depends on your Linux-Distribution)
  14. APACHEUSER="apache"
  15. # check if jq package is present on the system
  16. /usr/bin/which jq >/dev/null 2>&1
  17. if [ $? -ne 0 ]; then
  18. echo "2 \"NextCloud\" - NextCloud localcheck requires jq package to be installed"
  19. echo "2 \"NextCloud Apps\" - NextCloud localcheck requires jq package to be installed"
  20. exit;
  21. fi
  22. # Get current installed Nextcloud version-information
  23. # in v29.x.x version gives more detail, which is not given by the check on installed version, so switched to versionstring instead.
  24. NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')
  25. # Get latest avaiable version information
  26. # In v29.x.x this has changed outputs <name-of-instance> <version>,
  27. NCAVAILABLE=$(curl -s $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//')
  28. # compare resuts of installed and available version and report update available if they differ
  29. if [ $NCINSTALLED != $NCAVAILABLE ]; then
  30. echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
  31. else
  32. sudo -u $APACHEUSER php $BASEPATH/occ status -e
  33. if [ $? -eq 0 ]; then
  34. echo "0 \"NextCloud\" - NextCloud all up to date"
  35. elif [ $? -eq 1 ]; then
  36. echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
  37. elif [ $? -eq 2 ]; then
  38. echo "2 \"NextCloud\" - NextCloud Core needs updating"
  39. fi
  40. fi
  41. APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
  42. if [[ $APPRESULT == *"All apps are up-to-date"* ]]; then
  43. echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
  44. else
  45. UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
  46. echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
  47. fi