Skip to content

Commit

Permalink
nc-notify-updates: only notify once
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Aug 16, 2017
1 parent b95f6d5 commit e10bf3b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
18 changes: 14 additions & 4 deletions etc/nextcloudpi-config.d/nc-notify-updates.sh
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions update.sh
Expand Up @@ -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
#
Expand Down

0 comments on commit e10bf3b

Please sign in to comment.