From ee748758713a746863d6936e65bb1051d82507ef Mon Sep 17 00:00:00 2001 From: nachoparker <nacho@ownyourbits.com> Date: Fri, 1 Sep 2017 12:20:57 +0200 Subject: [PATCH] nc-notify-updates: notify also of unattended upgrades --- etc/nextcloudpi-config.d/nc-notify-updates.sh | 33 +++++++++++++++++-- update.sh | 14 ++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/etc/nextcloudpi-config.d/nc-notify-updates.sh b/etc/nextcloudpi-config.d/nc-notify-updates.sh index 147f346e5..f96436cb1 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] diff --git a/update.sh b/update.sh index 88f1f3e58..fc58ed677 100755 --- a/update.sh +++ b/update.sh @@ -86,6 +86,20 @@ launch_script $1 &> /run/ncp.log EOF chmod 700 /home/www/ncp-launcher.sh +# update notify-updates to also notify about unattended upgrades +cat > /etc/systemd/system/nc-notify-updates.service <<EOF +[Unit] +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 +EOF + # adjust max PHP processes so Apps don't overload the board (#146) sed -i 's|pm.max_children =.*|pm.max_children = 3|' /etc/php/7.0/fpm/pool.d/www.conf