diff options
author | nachoparker <nacho@ownyourbits.com> | 2017-09-01 13:20:57 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2017-09-02 00:32:24 +0300 |
commit | ee748758713a746863d6936e65bb1051d82507ef (patch) | |
tree | 3f6f1908d180c76d08bc4094e58033a1b42984ed /etc/nextcloudpi-config.d/nc-notify-updates.sh | |
parent | bb58ac7501d717e04c30e3f5267429f50e06ba02 (diff) |
nc-notify-updates: notify also of unattended upgradesv0.25.1
Diffstat (limited to 'etc/nextcloudpi-config.d/nc-notify-updates.sh')
-rw-r--r-- | etc/nextcloudpi-config.d/nc-notify-updates.sh | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/etc/nextcloudpi-config.d/nc-notify-updates.sh b/etc/nextcloudpi-config.d/nc-notify-updates.sh index 147f346e..f96436cb 100644 --- a/etc/nextcloudpi-config.d/nc-notify-updates.sh +++ b/etc/nextcloudpi-config.d/nc-notify-updates.sh @@ -40,6 +40,7 @@ Description=Notify in NC when a NextCloudPi update is available [Service] Type=simple ExecStart=/usr/local/bin/ncp-notify-update +ExecStartPost=/usr/local/bin/ncp-notify-unattended-upgrade [Install] WantedBy=default.target @@ -76,13 +77,41 @@ 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 \ - $USER_ "NextCloudPi \$( cat \$VERFILE )" \ - -l "NextCloudPi \$( cat \$LATEST ) is available. Update from https://\$IP:4443" + $USER_ "NextCloudPi update" \ + -l "Update from \$( cat \$VERFILE ) to \$( cat \$LATEST ) is available. Update from https://\$IP:4443" cat \$LATEST > \$NOTIFIED EOF chmod +x /usr/local/bin/ncp-notify-update + cat > /usr/local/bin/ncp-notify-unattended-upgrade <<EOF +#!/bin/bash +LOGFILE=/var/log/unattended-upgrades/unattended-upgrades.log +STAMPFILE=/var/run/.ncp-notify-unattended-upgrades +VERFILE=/usr/local/etc/ncp-version + +test -e "\$LOGFILE" || { echo "\$LOGFILE not found"; exit 1; } + +test -e "\$STAMPFILE" || touch "\$STAMPFILE" + +[ \$( date -r "\$LOGFILE" +'%y%m%d%H%M' ) -le \$( date -r "\$STAMPFILE" +'%y%m%d%H%M' ) ] && { echo "info is up to date"; exit 0; } + +LINE=\$( grep "INFO Packages that will be upgraded" "\$LOGFILE" ) + +[[ "\$LINE" == "" ]] && { echo "no new upgrades"; touch "\$STAMPFILE"; exit 0; } + +PKGS=\$( sed 's|^.*Packages that will be upgraded: ||' <<< "\$LINE" ) + +echo "Packages automatically upgraded: \$PKGS" + +touch "\$STAMPFILE" + +sudo -u www-data php /var/www/nextcloud/occ notification:generate \ + $USER_ "NextCloudPi Unattended Upgrades" \ + -l "Packages automatically upgraded \$PKGS" +EOF + chmod +x /usr/local/bin/ncp-notify-unattended-upgrade + # timer cat > /etc/systemd/system/nc-notify-updates.timer <<EOF [Unit] |