Skip to content

Commit

Permalink
nc-notify-updates: notify also of unattended upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Sep 1, 2017
1 parent e29c417 commit 3f4baa7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
33 changes: 31 additions & 2 deletions etc/nextcloudpi-config.d/nc-notify-updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 14 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3f4baa7

Please sign in to comment.