Skip to content

Commit 3f4baa7

Browse files
author
nacho
committed
nc-notify-updates: notify also of unattended upgrades
1 parent e29c417 commit 3f4baa7

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

etc/nextcloudpi-config.d/nc-notify-updates.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Description=Notify in NC when a NextCloudPi update is available
4040
[Service]
4141
Type=simple
4242
ExecStart=/usr/local/bin/ncp-notify-update
43+
ExecStartPost=/usr/local/bin/ncp-notify-unattended-upgrade
4344
4445
[Install]
4546
WantedBy=default.target
@@ -76,13 +77,41 @@ IFACE=\$( ip r | grep "default via" | awk '{ print \$5 }' )
7677
IP=\$( ip a | grep "global \$IFACE" | grep -oP '\d{1,3}(\.\d{1,3}){3}' | head -1 )
7778
7879
sudo -u www-data php /var/www/nextcloud/occ notification:generate \
79-
$USER_ "NextCloudPi \$( cat \$VERFILE )" \
80-
-l "NextCloudPi \$( cat \$LATEST ) is available. Update from https://\$IP:4443"
80+
$USER_ "NextCloudPi update" \
81+
-l "Update from \$( cat \$VERFILE ) to \$( cat \$LATEST ) is available. Update from https://\$IP:4443"
8182
8283
cat \$LATEST > \$NOTIFIED
8384
EOF
8485
chmod +x /usr/local/bin/ncp-notify-update
8586

87+
cat > /usr/local/bin/ncp-notify-unattended-upgrade <<EOF
88+
#!/bin/bash
89+
LOGFILE=/var/log/unattended-upgrades/unattended-upgrades.log
90+
STAMPFILE=/var/run/.ncp-notify-unattended-upgrades
91+
VERFILE=/usr/local/etc/ncp-version
92+
93+
test -e "\$LOGFILE" || { echo "\$LOGFILE not found"; exit 1; }
94+
95+
test -e "\$STAMPFILE" || touch "\$STAMPFILE"
96+
97+
[ \$( 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; }
98+
99+
LINE=\$( grep "INFO Packages that will be upgraded" "\$LOGFILE" )
100+
101+
[[ "\$LINE" == "" ]] && { echo "no new upgrades"; touch "\$STAMPFILE"; exit 0; }
102+
103+
PKGS=\$( sed 's|^.*Packages that will be upgraded: ||' <<< "\$LINE" )
104+
105+
echo "Packages automatically upgraded: \$PKGS"
106+
107+
touch "\$STAMPFILE"
108+
109+
sudo -u www-data php /var/www/nextcloud/occ notification:generate \
110+
$USER_ "NextCloudPi Unattended Upgrades" \
111+
-l "Packages automatically upgraded \$PKGS"
112+
EOF
113+
chmod +x /usr/local/bin/ncp-notify-unattended-upgrade
114+
86115
# timer
87116
cat > /etc/systemd/system/nc-notify-updates.timer <<EOF
88117
[Unit]

update.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ launch_script $1 &> /run/ncp.log
8686
EOF
8787
chmod 700 /home/www/ncp-launcher.sh
8888

89+
# update notify-updates to also notify about unattended upgrades
90+
cat > /etc/systemd/system/nc-notify-updates.service <<EOF
91+
[Unit]
92+
Description=Notify in NC when a NextCloudPi update is available
93+
94+
[Service]
95+
Type=simple
96+
ExecStart=/usr/local/bin/ncp-notify-update
97+
ExecStartPost=/usr/local/bin/ncp-notify-unattended-upgrade
98+
99+
[Install]
100+
WantedBy=default.target
101+
EOF
102+
89103
# adjust max PHP processes so Apps don't overload the board (#146)
90104
sed -i 's|pm.max_children =.*|pm.max_children = 3|' /etc/php/7.0/fpm/pool.d/www.conf
91105

0 commit comments

Comments
 (0)