You are not logged in.

#26 2016-02-05 22:56:35

damo
....moderator....
Registered: 2015-08-20
Posts: 5,823

Re: automatic notification of updates?

pvsage wrote:

Regarding the need to run apt-get update as root/su, how do utilities like unattended-upgrades get around this?  I'm looking at that package's wiki page and I don't see...

Probably it installs a rules file.

EDIT `/etc/apt/apt.conf.d/50unattended-upgrades`?

The postinst file in the deb sets up a systemd unattended-upgrades.service

Last edited by damo (2016-02-05 23:03:53)


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#27 2016-02-05 23:11:32

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: automatic notification of updates?

I took the time to build up an update notifcation system using systemd unit files and output parsed to conky today.
First, I created a simple bash script that runs sudo apt update, then redirects the output to journalctl. I saved this file to /usr/local/bin/debupdates.

#!/bin/bash
systemd-cat sudo apt update
exit 0;

Next, comes the systemd service file save to /etc/systemd/system/debupdates.service. Please note the lack of an Install portion to this unit file. That is because the timer will handle the stopping and starting of the service.

[Unit]
Description=Service file to run Debian Updates
After=network-online.target
Wants=network-online.target
[Service]
type=oneshot
ExecStart=/usr/local/bin/debupdates

Next, I needed a timer unit file which will handle starting and stopping the debupdates.service. It is set to run once, 15s after boot, then every 24 hours after that. If you find that systemd is not running the service on boot, then it is likely you will need to up the OnBootSec=15s value some more. Since debupdates.service requires network-online.target, I would set that value based on how long it takes to boot to desktop and get connected to the internet. This file is saved as /etc/systemd/system/debupdates.timer

[Unit]
Description=Checking for Debian Updates.....

[Timer]
OnBootSec=15s
OnUnitActiveSec=24h

[Install]
WantedBy=timers.target

Finally, I created a shell script save to ~/bin/list-updates that runs apt list --upgradable, then outputs a count of the number of available updates, along with a listing of the packages. apt outputs a number of informational lines that I had to remove from the output and also had to reduce the count to account for those extra informational lines. One thing I noticed, is that apt list --upgradable is outputting the wrong count in it's output. For instance, it was showing me 11 packages needing to be upgraded but the list only held 10 packages. This is likely due to the fact that somebody ran a count based on a 1-based index as a opposed to a 0-based index. I have double-checked this with the raw output from the command line and it has nothing to do with my code.

#!/bin/bash
oldfifs="$IFS"
IFS=$'n'
updates=($(apt list --upgradable))
IFS="$oldifs"
echo -e "$((${#updates[*]}-6)) updates available.\n"
echo "${updates[@]:2}"
exit 0;

Finally, the code that you put in your conky.

${execpi 43200 $HOME/bin/list-updates}

I will gather all of the various files I created up and publish them to my github.

Offline

#28 2016-02-05 23:25:11

damo
....moderator....
Registered: 2015-08-20
Posts: 5,823

Re: automatic notification of updates?

tknomanzr wrote:

....
I will gather all of the various files I created up and publish them to my github.

Awesome! smile


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#29 2016-02-05 23:26:29

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: automatic notification of updates?

Done. I suppose I ought to learn how to package things now.

Forgot the link, though the link to the main repository is in my sig
list-updated github

Last edited by tknomanzr (2016-02-05 23:31:07)

Offline

#30 2016-02-06 10:20:49

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: automatic notification of updates?

Small corrections to your script:

#!/bin/bash
oldifs="$IFS"
IFS=$'\n'
updates=($(apt list --upgradable 2>/dev/null))
IFS="$oldifs"
echo -e "$((${#updates[*]}-1)) updates available.\n"
echo "${updates[@]:1}"
exit 0

Typo in IFS=$'n' - missing \
typo in oldfifs="$IFS" - should be oldifs, but has no influence on the results.
But you should only exclude the first element of the array - "${updates[@]:1}"

Offline

#31 2016-02-06 15:57:26

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,029

Re: automatic notification of updates?

Fixed a couple of errors and made some changes to list-updates. For whatever reason, the script had stopped properly splitting elements via newlines. Also, I felt it wise to truncate list output for the available updates to some number so that lots of pending updates don't break conkies. For the moment I just hard-coded 20 elements in the printf statement. Given that this code is not meant to be run directly, I am not sure if an args parser is needed for this script. I could set a variable for the number of elements and/or an args parser to pass the maximum number of elements to display in. With all that being said, sooner or later a text file would need to be modified regardless how I choose to go about setting the max number of elements to display.

I found a small typo in the debupdates.service file. Those files are case-sensitive.

All changes are pushed to git.

Here's the new code for list-updates:

#!/bin/bash
readarray -t updates <<< "$(apt list --upgradable 2>/dev/null)"
numupdates=$((${#updates[*]}-1))
echo $numupdates "updates available."
echo "\${hr 1}"
printf -- "%s\n" "${updates[@]:1:20}"
if [ $numupdates -gt "20" ]; then
	echo -e "\${hr 1}"
	echo "\$alignr More Updates Available..."
fi
exit 0;

The horizontal rule statements are optional. They are just there to pretty up the formatting in my conky some.

Offline

#32 2016-02-06 20:57:24

Yannnd
New Member
From: The Netherlands
Registered: 2015-10-01
Posts: 2

Re: automatic notification of updates?

hhh wrote:

My 2 cents.

gnome-packagekit is broken in BunsenLabs and maybe even in GNOME, I don't know. When it worked, it was very cool to see the systray icon appear, but then it wouldn't work. And then you're running apt anyway to find out what's up, so just

sudo apt update && sudo apt upgrade

and be done with it. #firstworldproblems my auto-notification is busted

Another 2 cents:

Is gnome-packagekit really broken?
I succesfully managed to use it for notification of updates. It works fine for several weeks already. What I did:

sudo apt-get install gnome-packagekit
sudo apt-get install update-notifier
sudo apt-get install pk-update-icon

NOTE: pk-update-icon comes from jessie-backports, so the next line has to be present in /etc/apt/sources.list:

deb http://ftp.de.debian.org/debian jessie-backports main

At first it seemed not to work at all, but I didn't realize that the check for updates is done only once a day in the default configuration. The next day I was pleasantly surprised that after booting the packagekitd daemon was running and I automatically got notified about some pending updates... Since then it seems to work flawlessly. Just like the old update-notifier in Crunchbang Waldorf smile

To manually view pending updates, use:

gpk-update-viewer

To view installed/available software (an alternative for synaptic, however I prefer the last):

gpk-application

Some interesting info I found at: http://www.freedesktop.org/software/Pac … k-faq.html


Bunsenlabs Hydrogen - Solus 1.0 Shannon

Offline

#33 2016-02-06 21:29:39

toobuntu
Member
Registered: 2016-01-26
Posts: 6

Re: automatic notification of updates?

Might I suggest using the logic from the byobu package? (You folks do use tmux and byobu, right? smile) It's licensed GPLv3. Something like this for displaying the number of available updates:

renice 10 $$ >/dev/null 2>&1 || true
ionice -c3 -p $$ >/dev/null 2>&1 || true
flock -xn updates_available.lock apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst >updates_available.cache 2>/dev/null &

Then, you only need to "cat updates_available.cache" at regular intervals or "tail -F updates_available.cache". Have a look especially at the ___update_cache() and ___print_updates() functions in updates_available (from whence the foregoing is paraphrased) and reboot_required in the source code (shell scripts) at bzr:trunk/head:/usr/lib/byobu/

The result of updates_available is an integer followed by an exclamation point when an update is available and two exclamation points when security update is available, and the result of reboot_required is (R) when a reboot is required after an upgrade.

Here, the term cache seems internal to byobu's logic. The apt cache will still have to be updated periodically. This can be done by configuring apt to update daily, as follows:

cat << EOF | sudo tee /etc/apt/apt.conf.d/02periodic
// Do "apt-get update" automatically every n-days (0=disable)
APT::Periodic::Update-Package-Lists "1";
EOF

[edited to include apt periodic config, see /etc/cron.daily/apt and man apt.conf]

Last edited by toobuntu (2016-02-08 12:39:20)

Offline

#34 2016-02-11 06:01:53

toobuntu
Member
Registered: 2016-01-26
Posts: 6

Re: automatic notification of updates?

Just a note about granting sudo privileges: in general, it should be done only if necessary and with caution because of the security risks. In this case it is not necessary. /etc/cron.daily/apt already contains instructions for running apt-get update once a day. Even though the Debian archive is updated four times a day, a once daily update of the apt cache should still be sufficient. Finally, please see my post above with code glommed from the byobu package. If you delve into Dustin Kirkland's source code (he's a core-dev at Canonical, btw), you can see he makes some good points about renice-ing this process and using apt-get without apt's locking. As has been pointed out already, there's no need to have aptitude installed to accomplish this.

Offline

#35 2016-02-12 05:36:51

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,538
Website

Re: automatic notification of updates?


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#36 2016-02-23 14:01:53

searchone
Member
From: Walhalla
Registered: 2016-01-31
Posts: 107

Re: automatic notification of updates?

Hi @ all,
thanks for the many suggestions and ideas! Since I have kindled a really exciting discussion ...

@tknomanzr: nice idea to implement in Conky, have tried that same time and it works really great!

Auswahl_001.jpg

Thanks @ all


English by Google - blame them, Ich bin Deutscher.

Offline

#37 2016-04-30 13:55:15

pepemopap
Member
Registered: 2015-09-30
Posts: 41

Re: automatic notification of updates?

I use a script that check the updates in cron.weekly and exector (execp) plugin in tint2 (i beleave only available in v0.12, not in bunsen repos yet) to show in the bar the warning text with the pending updates if there.  When I click in the text bar terminator is open to install the updates.

forum.th.jpg

Mod Note: Oversized image replaced with thumbnail link, please limit images to ~250x250px
-HoaS

Last edited by pepemopap (2016-04-30 14:37:10)

Offline

#38 2016-05-02 16:28:02

ohnonot
...again
Registered: 2015-09-29
Posts: 4,405
Website

Re: automatic notification of updates?

^ sweet.

wanna share the script and tint2 config?

Offline

#39 2016-05-04 01:50:25

pepemopap
Member
Registered: 2015-09-30
Posts: 41

Re: automatic notification of updates?

Sure:

Script: /etc/cron.weekly/update-notification.sh
This script is executed weekly for checking updates and saving the output in /var/cache/update-notification/aptitude-updates:

#!/bin/bash

un_dir="/var/cache/update-notification"

# CHECK INTERNET CONNECTION
echo "Checking connection..."
nc -z 8.8.8.8 53 || exit 1

# UPDATE REPOSITORY AND SAVE RESULTS
echo "Updating package repository..."
aptitude update &> /dev/null
echo "Checking pending updates..."
aptitude search "~U" &> $un_dir/aptitude-updates

Tint2 config:
Version 0.12 is needed for execp plugin.

#Add E to panel_items:
panel_items = LTESC
...
execp = new
execp_command = [ -r /var/cache/update-notification/aptitude-updates ] && echo "| UPDATES: "$(wc /var/cache/update-notification/aptitude-updates -l | cut -f 1 -d " ")" | "
execp_interval = 0
execp_background_id = 2
execp_font = Droid Sans 9
execp_font_color = #FFFFFF 100
execp_centered = 1
execp_padding = 0 0 0
execp_tooltip = Pending updates
execp_lclick_command = x-terminal-emulator -b -e ~/bin/update-notification.sh

Script: ~/bin/update-notification.sh
This script is called when user clic on the taskbar message for install packages.

#!/bin/bash

un_dir="/var/cache/update-notification"

if ! [ -r $un_dir/aptitude-updates ]; then exit 0; fi

echo "PENDING SYSTEM UPDATES:"
cat $un_dir/aptitude-updates
echo
read -p "Press enter to continue installing..."

sudo aptitude full-upgrade
if ! [ $? -eq 0 ]; then read; exit 1; fi

sudo rm $un_dir/aptitude-updates; 
bl-tint2restart &>/dev/null & 
read

Last edited by pepemopap (2016-05-07 22:22:32)

Offline

#40 2016-05-06 23:57:59

damo
....moderator....
Registered: 2015-08-20
Posts: 5,823

Re: automatic notification of updates?

Typo on the first line - causes an error in the constructed filepath

un_dir="/var/cache/update-notification/"

Should be

un_dir="/var/cache/update-notification"

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#41 2016-05-07 16:49:48

pepemopap
Member
Registered: 2015-09-30
Posts: 41

Re: automatic notification of updates?

damo wrote:

Typo on the first line - causes an error in the constructed filepath

un_dir="/var/cache/update-notification/"

Should be

un_dir="/var/cache/update-notification"

Actually, bash works with /dir1/dir2/file same as /dir1/dir2//file
Bue it may not be a good practice... maybe in some versions of bash doesnt works?

Last edited by pepemopap (2016-05-07 16:50:17)

Offline

#42 2016-05-07 17:15:58

damo
....moderator....
Registered: 2015-08-20
Posts: 5,823

Re: automatic notification of updates?

pepemopap wrote:

...
Actually, bash works with /dir1/dir2/file same as /dir1/dir2//file
Bue it may not be a good practice... maybe in some versions of bash doesnt works?

Didn't work for me, which is why I posted wink


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#43 2016-05-07 22:15:18

pepemopap
Member
Registered: 2015-09-30
Posts: 41

Re: automatic notification of updates?

damo wrote:
pepemopap wrote:

...
Actually, bash works with /dir1/dir2/file same as /dir1/dir2//file
Bue it may not be a good practice... maybe in some versions of bash doesnt works?

Didn't work for me, which is why I posted wink

Then, obviusly, isnt a good practice.
Iam using bash 4.3.30, and you?

Offline

#44 2016-05-07 23:04:03

damo
....moderator....
Registered: 2015-08-20
Posts: 5,823

Re: automatic notification of updates?

pepemopap wrote:

...
Iam using bash 4.3.30, and you?

$ bash --version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)

The error was "No such file or directory", which didn't reoccur after I changed the line.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#45 2016-05-08 02:34:14

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,538
Website

Re: automatic notification of updates?

damo wrote:
pepemopap wrote:

...
Iam using bash 4.3.30, and you?

$ bash --version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)

The error was "No such file or directory", which didn't reoccur after I changed the line.

It must have been some other typo. Double slashes work fine here in file paths - just tested with bash 4.3.30 and sh. (They don't look nice though.)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#46 2016-05-08 06:22:51

ohnonot
...again
Registered: 2015-09-29
Posts: 4,405
Website

Re: automatic notification of updates?

johnraff wrote:

It must have been some other typo. Double slashes work fine here in file paths - just tested with bash 4.3.30 and sh. (They don't look nice though.)

same here (bash 4.3.42): i can change directories even with doubleslashes.
i haven't checked the conky script though; my guess is there's sth else amiss.

Offline

#47 2016-05-08 20:46:31

damo
....moderator....
Registered: 2015-08-20
Posts: 5,823

Re: automatic notification of updates?

@pepemopap

Ref your tint2 config:  bl-tint2restart shows an error

execp_interval must be an integer >= 1

The tint2rc has

execp_interval = 0

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#48 2016-05-09 07:22:31

pepemopap
Member
Registered: 2015-09-30
Posts: 41

Re: automatic notification of updates?

damo wrote:

@pepemopap

Ref your tint2 config:  bl-tint2restart shows an error

execp_interval must be an integer >= 1

The tint2rc has

execp_interval = 0

Ummm, i have the same error, but in documentation says:

execp_interval = integer : The command is executed again after execp_interval seconds from the moment it exits. If zero, the command is executed only once. (since 0.12.4)

Im using 0.12.7

Offline

#49 2016-05-10 06:49:42

ohnonot
...again
Registered: 2015-09-29
Posts: 4,405
Website

Re: automatic notification of updates?

well if the actually currently present version of tint2 throws that message, i'd say that takes precedence?
but o9000 is active on the forums, and if they didn't read it already, i'm sure you can drop a line on one of the tint2 threads here and ask for clarification.

Offline

Board footer

Powered by FluxBB