nickvergessen

Joas Schilling

Nextcloud Software Engineer

Public key: 8A14 2308 4188 5D5C 5F46 C189 E166 FD89 76B3 BAC8

Howto get notifications for system updates
March 17, 2017

Keep your server up to date and receive a notification in your Nextcloud when php, apache, etc. need an update with this little script.

Update 21/Apr/17: Also works on Raspbian and others now.

Notifications for system updates

  1. Install the admin_notifications app
  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
    

Leave comments in the Nextcloud forum.

[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.