You are not logged in.

#1 2012-03-18 19:41:36

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,174

[solved but questions] Lightweight alternative to alunn

I was wondering if there was a lighter alternative to alunn. I know that there are a lot of GUI frontends for pacman and I've looked into those which looked promising from the list on the wiki but most of them do too much or they don't do it correctly (in my opinion smile).

Essentially, I would like something which would just notify me of updates to installed apps from at least the official repositories. Ideally, it would do the same for apps installed from AUR. I absolutely do not want something with the ability to upgrade my system. Nor do I want something which will update the package databases. That is, it must not run pacman -Sy (or pacman -Syu) unless in a fakeroot environment. It should not need root privileges for anything, ever.

A systray icon would be nice but is not absolutely essential.

The main problem with alunn is that it pulls in a lot of gnome dependencies, including gvfs and various other gnome things. gvfs is creating problems for rsync backup and, while I'm sure this is avoidable, it made me realise that the only reason I have it installed is for alunn and I thought maybe I could find something which was either generally lighter or hooked into kde/qt dependencies which I've already got installed. If it could also check for AUR updates, that would be the icing on the cake.

I was also wondering about just scripting a cron job but I'm not sure how to run a cron job as an ordinary user in Linux and I've had no luck getting notifications to work from cron jobs.

Last edited by cfr (2012-06-11 20:36:56)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#2 2012-03-18 20:05:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved but questions] Lightweight alternative to alunn

Offline

#3 2012-05-27 23:39:13

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,174

Re: [solved but questions] Lightweight alternative to alunn

Thanks very much indeed. I've finally got around to actually playing with this. I've needed to edit them a bit e.g. I don't have cower. But the basic idea looks perfect.

I'm just wondering: do you know why the hourly cron script and the notification script are separate? How is the notification script supposed to get triggered?

EDIT: Turns out although the link to the previous post on the blog is broken, it does exist and it is possible to navigate to it indirectly:
http://www.andreascarpino.it/blog/posts … -packages/
This explains what to do with the second script. (But note that this older post has the *unsafe* version of the database check on it.)

Last edited by cfr (2012-05-27 23:48:15)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#4 2012-05-29 00:42:50

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,174

Re: [solved but questions] Lightweight alternative to alunn

So I now have this sort of working but not quite right. I can get popups with kdialog but notify-send doesn't work. notify-send is fine if I just execute my script but once it is executed as a cron job, it fails.

With kdialog, executing the script by hand behaves as expected but as a cron job, it ignores my customisations to KDE. I get a bare popup in default colours, without close button etc. Worse, it is plonked in the middle of my screen rather than top right.

Here's what I'm using:

$ cat /usr/local/bin/pacmandbcheck-notifications 
#!/bin/bash -
# ref.: http://www.andreascarpino.it/blog/posts/hey-youve-n-outofdated-packages-part-ii/
# instructions: add to user crontab
# mangled by cfr

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
DISPLAY=:0
export DISPLAY

if test -x /usr/bin/on_ac_power; then
        /usr/bin/on_ac_power &> /dev/null
        if test $? -eq 1; then
                exit 0
        fi
fi

fakedb=/dev/shm/fakepacdb

[[ -d "$fakedb" ]] || exit 0

enwau=$(pacman --dbpath "$fakedb" -Qqu)
#pkgs=$(pacman --dbpath "$fakedb" -Qqu | wc -l)
pkgs=$(echo $enwau | wc -w)
#aurpkgs=$(cower -udf 2> /dev/null | wc -l)
aurpkgs=0

unset msg1
unset msg2
unset packages

if [[ ${pkgs} -gt 0 ]]; then
        msg1="${pkgs} in pacman"
fi 

if [[ ${aurpkgs} -gt 0 ]]; then
        msg2=" ${aurpkgs} in AUR"
fi 

let packages=${pkgs}+${aurpkgs}

if [[ ${packages} -gt 0 ]]; then
        kdialog --icon "arch-logo" --title "Out-Of-Date packages" --passivepopup "There are ${packages} outofdated packages (${msg1}${msg2})" 10
        notify-send -u normal -i arch-logo "Out-Of-Date packages" "There are ${packages} outofdated packages (${msg1}${msg2})"
fi

exit 0
$ cat /etc/cron.hourly/20pacmandbcheck 
#!/bin/bash -
# ref.: http://www.andreascarpino.it/blog/posts/hey-youve-n-outofdated-packages-part-ii/
# instructions: install in /etc/cron.hourly/
# mangled by cfr

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

if test -x /usr/bin/on_ac_power; then
        /usr/bin/on_ac_power &> /dev/null
        if test $? -eq 1; then
                exit 0
        fi
fi

fakedb=/dev/shm/fakepacdb
realdb=/var/lib/pacman

[[ ! -d $fakedb ]] && { mkdir -p "$fakedb/sync" || exit 1; }
[[ ! -L $fakedb/local ]] && { ln -s "$realdb/local" "$fakedb" || exit 2; }

exec fakeroot pacman --dbpath "$fakedb" -Sy

exit $?
$ crontab -l
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# munud awr     dyddiad mis     dydd    command
26      *       *       *       *       nice /usr/local/bin/pacmandbcheck-notifications

Any ideas how to get kdialog to behave as "normal" or how to get notify-send working? Stuff works fine in regular scripts...

I realised I've changed the scripts Karol directed me to a bit but I don't think any of my changes should be causing kdialog to behave weirdly...

EDIT: I know kdialog has a --geometry option but nothing I do results in its having any effect.

Last edited by cfr (2012-05-29 00:48:10)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#5 2012-06-05 16:44:17

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,174

Re: [solved but questions] Lightweight alternative to alunn

I realise that, actually, kdialog probably isn't even using default settings as there are no window controls e.g. no close button - just the bare box. I'm assuming that there is some environmental variable set when I'm in the shell but not set when the cron job runs. I created a list of such variables - for the cron job, it is very short. I'm not sure what might be relevant.

Does anybody know if there is any documentation available concerning kdialog which covers the influence of environmental variables? (Or the same for notify-send - just since I can't get that to work at all, I figure working on kdialog is the more hopeful looking option, though I'd really rather use notify-send if I could.)

I've found some stuff (e.g. http://techbase.kde.org/Development/Tut … E_Dialogs) but it doesn't cover the effect of environmental variables - just the various options for the different sorts of dialog available.

I also tried setting Xauthority (as suggested at http://www.commandlinefu.com/commands/v … ine-Fu%29) for notify-send but it didn't seem to have any effect.

I'd be really grateful for any pointers or suggestions (or even possible pointers to possible pointers!). growl's notify is one of the things I really miss from OS X (though it isn't part of OS X itself). I'm sure I should be able to get notify-send (and kdialog) to do even more (kdialog is more flexible) but I must be missing something really basic...


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#6 2012-06-09 02:46:27

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,174

Re: [solved but questions] Lightweight alternative to alunn

OK. So I eventually found http://unix.stackexchange.com/questions … session-id via a slightly circuitous route. This looked really hopeful, I have to say, but I'm still missing something.

I tried following the first suggestion, using ~/.dbus/session-bus/<machine-id>-<display-number> to set DBUS_SESSION_BUS_ADDRESS and DBUS_SESSION_BUS_PID. I haven't actually got as far as trying this in a cron job. Rather, I've already got stuck just trying to fiddle with it from the command line.

So I created a file of commands as follows:

export DISPLAY=:0
export XAUTHORITY=~/.Xauthority
dbus_session_file=~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0
if [ -e "$dbus_session_file" ]
then
        . "$dbus_session_file"
        export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
else
        printf %b "Gwall! Allwn i ddim canfod "$dbus_session_file".\n"
fi
printenv > /tmp/z.$$
DISPLAY=:0 XAUTHORITY=~/.Xauthority notify-send test
notify-send prawf
kdialog --display=":0" --passivepopup test 0
kdialog --passivepopup prawf 0

This did change things but not, unfortunately, in the right direction. Without setting these environmental variables, this script will produce notifications using both notify-send and kdialog as expected, complete with all the GUI niceties of close buttons etc.

With the environmental variables set, notify-send works not at all and kdialog works but shorn of its usual GUI glitter. That is, with these variables set, the script produces the same results I get anyway from the cron job.

It turns out that my usual environment does have DBUS_SESSION_BUS_ADDRESS set but does not have the value contained in ~/.dbus/session-bus/<machine-id>-<display-number> and DBUS_SESSION_BUS_PID is not set at all.

So I assume that for some reason I have multiple dbus sessions running and that the one defined in the standard session file isn't the one KDE uses. So probably I should be trying to set the values for the session KDE is using. However, I can't figure out where this information is stored. I tried looking in ~/.kde4/ ~/.kde/, ~/.local/share/, ~/.config/ but nothing so far looks to be related.

So I have at least 2 questions I can't currently answer about this:
1) where is the session id for the dbus session used by KDE stored?
2) what is the relationship between the session identified under ~/.dbus and the session used by KDE? Or is this just a bad question and different things create different sessions as a matter of course, without there being any relationship between them?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#7 2012-06-10 15:34:30

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,174

Re: [solved but questions] Lightweight alternative to alunn

I still really have the same questions. That is, I'd still like to know the answers. However, I found something which at least seems to work by finding a sort of answer to (1) though I'm far from sure that this is how it should be done...

This is very heavily based on the original versions. (The cron job is probably identical or almost so and the basic notification script will be similar. The main difference is the script I'm using to get the notifications to behave themselves. I'm just including everything here for completeness - I'm certainly not claiming authorship!)

I installed a script at /usr/local/bin/pacmandbcheck-notifications:

#!/bin/bash -
# ref.: http://www.andreascarpino.it/blog/posts/hey-youve-n-outofdated-packages-part-ii/
# instructions: add to user crontab
# mangled by cfr

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
DISPLAY=:0
export DISPLAY

if test -x /usr/bin/on_ac_power; then
        /usr/bin/on_ac_power &> /dev/null
        if test $? -eq 1; then
                exit 0
        fi
fi

fakedb=/dev/shm/fakepacdb

[[ -d "$fakedb" ]] || exit 0

enwau=$(pacman --dbpath "$fakedb" -Qqu)
#pkgs=$(pacman --dbpath "$fakedb" -Qqu | wc -l)
pkgs=$(echo $enwau | wc -w)
#aurpkgs=$(cower -udf 2> /dev/null | wc -l)
aurpkgs=0

unset msg1
unset msg2
unset packages

if [[ ${pkgs} -gt 0 ]]; then
        msg1="${pkgs} in pacman"
fi 

if [[ ${aurpkgs} -gt 0 ]]; then
        msg2=" ${aurpkgs} in AUR"
fi 

let packages=${pkgs}+${aurpkgs}

echo $enwau > /tmp/hysbysu.$$
enwau=$(cat /tmp/hysbysu.$$)
rm /tmp/hysbysu.$$

if [[ ${packages} -gt 0 ]]; then
#       kdialog --icon "arch-logo" --title "Out-Of-Date packages" --passivepopup "There are ${packages} outofdated packages (${msg1}${msg2})" 10
#       notify-send -u normal -i arch-logo "Out-Of-Date packages" "There are ${packages} outofdated packages (${msg1}${msg2})"
        hysbysu -u normal -i arch-logo -t 0 -s "${packages} outdated packages" -b "${enwau}"
fi

exit 0

and another at /usr/local/bin/hysbysu:

#!/bin/bash -
#set -x
export DISPLAY=:0
export XAUTHORITY=~/.Xauthority
PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
export PATH

allan=0

usage="Usage: $0 [OPTION]
Send a notification in a way which respects the KDE GUI but falls back to the standard setup (I think) if KDE isn't running. 
Options:
        -b --body               specify message                                         [empty]
        -c --category           specify category                                        [empty]
        -h --help               print this message and exit
           --hint               specify additional hints                                [empty]
        -i --icon               specify icon                                            [info]
        -o --options            options to pass to notification command                 [empty]
        -s --summary            specify summary                                         [\"Notification\"]
        -t --time               specify time to expire                                  [0 i.e. no expiry]
        -u --urgency            specify urgency (low, normal or critical)               [normal]
For cases where the default is "empty", the default will effectively be notify-send's default since all this script does is pass stuff onto the command."

error () {
        echo "$@" 1>&2
        ((allan++))
        usage_and_exit $allan
}
usage () {
        printf %b "$usage\n"
}
usage_and_exit () {
        usage
        exit $1
}

tempargs=$(getopt -o b:c:hi:o:s:t:u: --long body:,category:,help,hint:,icon:,options:,summary:,time:,urgency: -- "$@")
if [ $? != 0 ];
then
        usage_and_exit
fi
eval set -- "$tempargs"

body=""
cat=""
hint=""
icon=""
summ="Notification"
time="0"
urg="normal"

while true
do
        case "$1"
        in
                -b | --bo | --bod | --body)
                        body="$2"
                        shift;
                        shift;;
                -c | --ca | --cat | --cate | --categ | --catego | --categor | --category)
                        cat="$2"
                        shift;
                        shift;;
                -h | --help)
                        usage;
                        exit $allan;;
                --hi | --hin | --hint)
                        hint="$2"
                        shift;
                        shift;;
                -i | --ic | --ico | --icon)
                        icon="$2"
                        shift;
                        shift;;
                -o | --opt | --opts| --opti | --optn | --option | --options)
                        options="$2"
                        shift;
                        shift;;
                -s | --su | --sum | --summ | --summa | --summar | --summary)
                        summ="$2"
                        shift;
                        shift;;
                -t | --ti | --tim | --time)
                        time="$2"
                        shift;
                        shift;;
                -u | --ur | --urg | --urge | --urgen | --urgenc | --urgency)
                        urg="$2"
                        shift;
                        shift;;
                --)
                        shift;
                        break;;
                *)
                        error Unrecognised option "$1".
        esac
done

args="$@"

if [ "$icon" = "" ]
then
        if [ "$urg" = "low" ]
        then
                icon="dialog-information"
        else
                if [ "$urg" = "normal" ]
                then
                        icon="dialog-warning"
                else
                        if [ "$urg" = "critical" ]
                        then
                                icon="dialog-error"
                        else
                                icon="specialcharacters-Character-Question"
                        fi
                fi
        fi
fi

ksession_pid=$(ps -o pid= -C 'kwin -session' | sed 's/ //g')

if [ "$ksession_pid" = "" ]
then
        dbus_session_file=~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0
        if [ -e "$dbus_session_file" ]
        then
                . "$dbus_session_file"
                [ $? == 0 ] || ((allan++))
                export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
        else
                error "Gwall! Allwn i ddim canfod $dbus_session_file."
        fi
else
        dbus_session_address=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$ksession_pid/environ | sed 's/^DBUS_SESSION_BUS_ADDRESS=//')
        [ "$dbus_session_address" != "" ] || error "Could not get DBUS_SESSION_BUS_ADDRESS for session." 
        export DBUS_SESSION_BUS_ADDRESS="$dbus_session_address"
fi

if [ "$hint" = "" ]
then
        notify-send -i "$icon" -u "$urg" -t "$time" -c "$cat" $options "$summ" "$body"
        [ $? == 0 ] || ((allan++))
else
        notify-send -i "$icon" -u "$urg" -t "$time" -c "$cat" -h "$hint" $options "$summ" "$body"
        [ $? == 0 ] || ((allan++))
fi
#notify-send $options $args
#kdialog --passivepopup prawf-kd 0



exit $allan

As I say, I'm far from sure that's a good way to get the DBUS variable KDE's session is using. I haven't tested what happens in the absence of KDE as that's the only environment I have available.

I also installed this at /etc/cron.hourly/pacmandbcheck:

#!/bin/bash -
# ref.: http://www.andreascarpino.it/blog/posts/hey-youve-n-outofdated-packages-part-ii/
# instructions: install in /etc/cron.hourly/
# mangled by cfr

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

if test -x /usr/bin/on_ac_power; then
        /usr/bin/on_ac_power &> /dev/null
        if test $? -eq 1; then
                exit 0
        fi
fi

fakedb=/dev/shm/fakepacdb
realdb=/var/lib/pacman

[[ ! -d $fakedb ]] && { mkdir -p "$fakedb/sync" || exit 1; }
[[ ! -L $fakedb/local ]] && { ln -s "$realdb/local" "$fakedb" || exit 2; }

exec fakeroot pacman --dbpath "$fakedb" -Sy

exit $?

Finally, I added this to my user crontab:

55      *       *       *       *       nice /usr/local/bin/pacmandbcheck-notifications

CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

Board footer

Powered by FluxBB