diff options
-rw-r--r-- | etc/nextcloudpi-config.d/nc-notify-updates.sh | 18 | ||||
-rwxr-xr-x | update.sh | 27 |
2 files changed, 41 insertions, 4 deletions
diff --git a/etc/nextcloudpi-config.d/nc-notify-updates.sh b/etc/nextcloudpi-config.d/nc-notify-updates.sh index 54441b6e..2955e295 100644 --- a/etc/nextcloudpi-config.d/nc-notify-updates.sh +++ b/etc/nextcloudpi-config.d/nc-notify-updates.sh @@ -35,18 +35,28 @@ install() # code cat > /usr/local/bin/ncp-notify-update <<'EOF' #!/bin/bash -ncp-test-updates || { echo "NextCloudPi up to date"; exit 0; } - VERFILE=/usr/local/etc/ncp-version LATEST=/var/run/.ncp-latest-version -IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) -IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) +NOTIFIED=/var/run/.ncp-version-notified + +test -e $LATEST || exit 0; +ncp-test-updates || { echo "NextCloudPi up to date"; exit 0; } + +test -e $NOTIFIED && [[ "$( cat $LATEST )" == "$( cat $NOTIFIED )" ]] && { + echo "Found update from $( cat $VERFILE ) to $( cat $LATEST ). Already notified" + exit 0 +} echo "Found update from $( cat $VERFILE ) to $( cat $LATEST ). Sending notification..." +IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) +IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) + sudo -u www-data php /var/www/nextcloud/occ notification:generate \ admin "NextCloudPi $( cat $VERFILE )" \ -l "NextCloudPi $( cat $LATEST ) is available. Update from https://$IP:4443" + +cat $LATEST > $NOTIFIED EOF chmod +x /usr/local/bin/ncp-notify-update @@ -86,6 +86,33 @@ exit 1 EOF chmod +x /usr/local/etc/blknum + # fix ncp-notify-update + cat > /usr/local/bin/ncp-notify-update <<'EOF' +#!/bin/bash +VERFILE=/usr/local/etc/ncp-version +LATEST=/var/run/.ncp-latest-version +NOTIFIED=/var/run/.ncp-version-notified + +test -e $LATEST || exit 0; +ncp-test-updates || { echo "NextCloudPi up to date"; exit 0; } + +test -e $NOTIFIED && [[ "$( cat $LATEST )" == "$( cat $NOTIFIED )" ]] && { + echo "Found update from $( cat $VERFILE ) to $( cat $LATEST ). Already notified" + exit 0 +} + +echo "Found update from $( cat $VERFILE ) to $( cat $LATEST ). Sending notification..." + +IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) +IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) + +sudo -u www-data php /var/www/nextcloud/occ notification:generate \ + admin "NextCloudPi $( cat $VERFILE )" \ + -l "NextCloudPi $( cat $LATEST ) is available. Update from https://$IP:4443" + +cat $LATEST > $NOTIFIED +EOF + chmod +x /usr/local/bin/ncp-notify-update # License # |