1
0

nextcloud-updates.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. # check if configured basepath exists
  23. if [ ! -d "$BASEPATH" ]; then
  24. echo "2 \"NextCloud\" - NextCloud localcheck could not find configured basepath"
  25. echo "2 \"NextCloud Apps\" - NextCloud localcheck could not find configured basepath"
  26. exit;
  27. fi
  28. # Get current installed Nextcloud version-information
  29. # in v29.x.x version gives more detail, which is not given by the check on installed version, so switched to versionstring instead.
  30. NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')
  31. # Get latest avaiable version information
  32. # In v29.x.x this has changed outputs <name-of-instance> <version>,
  33. NCAVAILABLE=$(curl -s $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//')
  34. # compare resuts of installed and available version and report update available if they differ
  35. if [ $NCINSTALLED != $NCAVAILABLE ]; then
  36. echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
  37. else
  38. sudo -u $APACHEUSER php $BASEPATH/occ status -e
  39. if [ $? -eq 0 ]; then
  40. echo "0 \"NextCloud\" - NextCloud all up to date"
  41. elif [ $? -eq 1 ]; then
  42. echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
  43. elif [ $? -eq 2 ]; then
  44. echo "2 \"NextCloud\" - NextCloud Core needs updating"
  45. fi
  46. fi
  47. APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
  48. if [[ $APPRESULT == *"All apps are up-to-date"* ]]; then
  49. echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
  50. else
  51. UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
  52. echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
  53. fi