From 5ebeaf12ec3d8c7c39030ae6e2530bf4339f45f3 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Sat, 12 Aug 2017 08:28:33 +0200 Subject: added nc-notify-updates --- etc/nextcloudpi-config.d/nc-notify-updates.sh | 113 ++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 etc/nextcloudpi-config.d/nc-notify-updates.sh diff --git a/etc/nextcloudpi-config.d/nc-notify-updates.sh b/etc/nextcloudpi-config.d/nc-notify-updates.sh new file mode 100644 index 00000000..54441b6e --- /dev/null +++ b/etc/nextcloudpi-config.d/nc-notify-updates.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +# Install the latest News third party app +# Tested with 2017-03-02-raspbian-jessie-lite.img +# +# Copyleft 2017 by Ignacio Nunez Hernanz +# GPL licensed (see end of file) * Use at your own risk! +# +# Usage: +# +# ./installer.sh nc-notify-updates.sh () +# +# See installer.sh instructions for details +# More at: https://ownyourbits.com +# + +ACTIVE_=yes +NOTIFYINTERVAL_=60 +DESCRIPTION="Notify in NC when a NextCloudPi update is available" + +NCDIR=/var/www/nextcloud + +install() +{ + # install app + local URL=$( curl -s https://api.github.com/repos/nextcloud/admin_notifications/releases | \ + grep browser_download_url | head -1 | cut -d '"' -f 4 ) + cd /var/www/nextcloud/apps + wget $URL -O admin_notifications.tar.gz + tar -xf admin_notifications.tar.gz + rm *.tar.gz + chown -R www-data:www-data * + sudo -u www-data php /var/www/nextcloud/occ app:enable admin_notifications + + # 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 ) + +echo "Found update from $( cat $VERFILE ) to $( cat $LATEST ). Sending notification..." + +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" +EOF + chmod +x /usr/local/bin/ncp-notify-update + + # timers + cat > /etc/systemd/system/nc-notify-updates.service < /etc/systemd/system/nc-notify-updates.timer <