nextcloud-updates.sh 2.2 KB

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