Skip to content

Commit

Permalink
nc-notify-updates: fix repeated lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Oct 26, 2017
1 parent 2f1a9c9 commit d8b6eb3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion etc/nextcloudpi-config.d/nc-notify-updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ 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=\$( grep "INFO Packages that will be upgraded" "\$LOGFILE" | tail -1 )
[[ "\$LINE" == "" ]] && { echo "no new upgrades"; touch "\$STAMPFILE"; exit 0; }
Expand Down
28 changes: 28 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ EOF
grep -q actionstop_ "$F" || sed -i 's|actionstop|actionstop_|' "$F"
type whois &>/dev/null || { apt-get update; apt-get install --no-install-recommends -y whois; }

# fix notify unattended upgrades repeating lines
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" | tail -1 )
[[ "\$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
}

# License
Expand Down

0 comments on commit d8b6eb3

Please sign in to comment.