Howto get notifications for system updates


#1

Original blog post: https://www.schilljs.com/2017/03/17/howto-get-notifications-for-system-updates.html


  1. Install the admin_notifications app (Note: this is not needed anymore with Nextcloud 14)
  2. Create system-notifications.sh with the following content on your system, and make sure to adjust the path to your nextcloud /var/www/nextcloud/occ as well as your admin account name:
#!/usr/bin/env bash
#
# @license MIT
# @copyright 2017 Joas Schilling coding@schilljs.com

ADMIN="admin"
OCC_PATH="/var/www/nextcloud/occ"

PACKAGES=$(/usr/lib/update-notifier/apt-check -p 2>&1)
NUM_PACKAGES=$(echo "$PACKAGES" | wc -l)

if [ "$PACKAGES" != "" ]; then
	UPDATE_MESSAGE=$(echo "Packages to update: $PACKAGES" | sed -r ':a;N;$!ba;s/\n/, /g')
	$OCC_PATH notification:generate $ADMIN "$NUM_PACKAGES packages require to be updated" -l "$UPDATE_MESSAGE"

elif [ -f /var/run/reboot-required ]; then
	$OCC_PATH notification:generate $ADMIN "System requires a reboot"
fi

3. Add the script to the cronjob crontab -u www-data -e:

0 10 * * * /path/to/file/system-notifications.sh

[Update] Raspbian and other systems

If your operating system does not support apt-check, you can also try to replace the line:

PACKAGES=$(/usr/lib/update-notifier/apt-check -p 2>&1)

with:

PACKAGES=$(apt-get -s dist-upgrade | awk '/^Inst/ { print $2 }' 2>&1)

This at least made it work on my Raspberry Pi which runs Raspbian.


#2

nice feature!
any way to make this work for debian?


#3

SUPER cool, @nickvergessen !!!


#4

I think it should work on debian as well?
At least that’s what the docs said.


#5

Now it does. My mistake…
I had to install “update-notifier-common” and put "php " before “$OCC_PATH”.

Thanks!


#6

Too bad pacman doesn’t have an equivalent to apt-check - this is really nice!


#7

I published a little update: https://www.schilljs.com/2017/03/17/howto-get-notifications-for-system-updates.html


If your operating system does not support apt-check, you can also try to replace the line:

PACKAGES=$(/usr/lib/update-notifier/apt-check -p 2>&1)

with:

PACKAGES=$(apt-get -s dist-upgrade | awk '/^Inst/ { print $2 }' 2>&1)

This at least made it work on my Raspberry Pi which runs Raspbian.


#8

@nickvergessen :sunglasses: cool!


#10

Thanks a lot! :+1: I’d love to have that feature.
But :sweat_smile: i cant seem to get it working.

I installed admin-notifications,
the cron task (space at the end of the line, empty line at eof),
and changed the path and admin vars in the script.

I can see that cron was running in syslog and i can manually set a notification
(sudo -u www-data php /path/to/nextcloud/occ notification:generate admin “test”).
And i checked that apt-check works for www-data.

Nonetheless they wont show up :rage:
Any idea what i might be missing?

System is Nextcloud 12.0.3; Ubuntu 14.04; php 7.1.9


#11

Can you run sudo -u www-data /path/to/file/system-notifications.sh manually? Or does that maybe error?


#12

If i mark it as executable i get “not authorized” on line 15
($OCC_PATH notification:generate $ADMIN “$NUM_PACKAGES packages require to be updated” -l “$UPDATE_MESSAGE”).

But as i know it shouldnt be necessary to mark it as such?!
(due to #! )

ps.: owner of the file is www-data as i use apache
pss: copypasted the wrong line, now its right


#13

great and many thanks!
but i had to add “php” to the OCC_PATH variable?!

“OCC_PATH=“php /var/www/nextcloud/occ””

should that be fixed or is it just related to my setup?


#14

For reference: i think it’s possible to edit the script for arch linux using checkupdates instead of apt-check.
See https://wiki.archlinux.org/index.php/System_maintenance#Partial_upgrades_are_unsupported