浏览代码

Added 'nextcloud-updates.sh'

Michael Honkoop 9 月之前
父节点
当前提交
264e026932
共有 1 个文件被更改,包括 60 次插入0 次删除
  1. 60 0
      nextcloud-updates.sh

+ 60 - 0
nextcloud-updates.sh

@@ -0,0 +1,60 @@
+#!/bin/bash
+
+# Version 1.2
+#
+# v1.2 CHANGES:
+# - updated nextcloud release check to actually get latest version from the release-url
+# v1.1 CHANGES:
+# - Updated query for installed version to versionstring instead of version
+#
+
+RELEASEURL="https://download.nextcloud.com/server/releases/"
+
+#basepath of Nextcloud's occ executable
+
+BASEPATH="/var/www/html"
+
+# set the correct user for running the commands ( either apache or www-data )
+
+APACHEUSER="apache"
+
+# check if jq package is present on the system
+
+/usr/bin/which jq >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+    echo "2 \"NextCloud\" - NextCloud localcheck requires jq package to be installed"
+    echo "2 \"NextCloud Apps\" - NextCloud localcheck requires jq package to be installed"
+    exit;
+fi
+
+# Get current installed Nextcloud version-information
+# in v29.x.x version gives more detail, which is not given by the check on installed version, so switched to versionstring instead.
+
+NCINSTALLED=$(sudo -u $APACHEUSER php $BASEPATH/occ status --output=json | jq -r '.versionstring')
+
+# Get latest avaiable version information
+# In v29.x.x this has changed outputs <name-of-instance> <version,
+
+NCAVAILABLE=$(curl -s $RELEASEURL | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//')
+
+# compare resuts of installed and available version and report update available if they differ
+if [ $NCINSTALLED != $NCAVAILABLE ]; then
+   echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
+else
+    sudo -u $APACHEUSER php $BASEPATH/occ status -e
+    if [ $? -eq 0 ]; then
+        echo "0 \"NextCloud\" - NextCloud all up to date"
+    elif [ $? -eq 1 ]; then
+        echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
+    elif [ $? -eq 2 ]; then
+        echo "2 \"NextCloud\" - NextCloud Core needs updating"
+    fi
+fi
+
+APPRESULT=$(sudo -u $APACHEUSER php $BASEPATH/occ app:update --showonly)
+if [[ $APPRESULT == *"All apps are up-to-date"* ]]; then
+    echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
+else
+    UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
+    echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
+fi