Skip to content

Commit

Permalink
nc-notify-updates: rework for more accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Nov 6, 2017
1 parent 9212ecb commit 963542b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions etc/nextcloudpi-config.d/nc-notify-updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,28 @@ EOF

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; }
# find lines with package updates
LINE=\$( grep "INFO Packages that will be upgraded:" "\$LOGFILE" )
LINE=\$( grep "INFO Packages that will be upgraded" "\$LOGFILE" | tail -1 )
[[ "\$LINE" == "" ]] && { echo "no new upgrades"; exit 0; }
[[ "\$LINE" == "" ]] && { echo "no new upgrades"; touch "\$STAMPFILE"; exit 0; }
# extract package names
PKGS=\$( sed 's|^.*Packages that will be upgraded: ||' <<< "\$LINE" | tr '\\n' ' ' )
PKGS=\$( sed 's|^.*Packages that will be upgraded: ||' <<< "\$LINE" )
# mark lines as read
sed -i 's|INFO Packages that will be upgraded:|INFO Packages that will be upgraded :|' \$LOGFILE
echo "Packages automatically upgraded: \$PKGS"
echo -e "Packages automatically upgraded: \$PKGS\\n"
touch "\$STAMPFILE"
sudo -u www-data php /var/www/nextcloud/occ notification:generate \
$USER_ "NextCloudPi Unattended Upgrades" \
-l "Packages automatically upgraded \$PKGS"
# notify
sudo -u www-data php /var/www/nextcloud/occ notification:generate "NextCloudPi Unattended Upgrades" -l "Packages automatically upgraded $PKGS"
EOF
chmod +x /usr/local/bin/ncp-notify-unattended-upgrade

Expand Down

0 comments on commit 963542b

Please sign in to comment.