You are not logged in.

#1 2022-09-07 14:17:51

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

[ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

Maybe you're new to Arch Linux, or you simply like - or possibly miss - the warm feeling of something (greenish) popping up whenever updates have arrived, this might be for you. There are probably countless ways of achieving the same thing out there already. Well - here's another one...

Scope (features):

  • Notifications/Information only - no update/install shortcuts etc.

  • Official packages only (I prefer handling the AUR separately)

  • Quick access to information about all available updates
    (waybar's tooltip is not meant for large amounts of info, imho)

  • Dynamic icon (waybar)

  • Modularity (by using temporary files, which can be accessed by additional tools/scripts)

  • Simplicity (just a few lines of code, really)

For more details about my small contribution please see the prologue in the script below.
Please place script file(s) (*.sh) inside '~/.local/bin/' and don't forget to make them executable.

updatenotif.sh:

#!/bin/sh
#
#[v2.1.6]
#
### Description:
#
# This script - let's call it 'updatenotif.sh' - 
# can be used as a standalone as well as part
# of a waybar module in order to notify about
# Arch Linux package updates.
# 
# Run this script at startup of your graphical
# environment. It will check for updates every
# 30 minutes.
#
#
### Dependencies:
#
# 'libnotify'
# 'pacman-contrib'
# 'fnott' (or a notification daemon of your choice),
# please also see: "https://wiki.archlinux.org/title/Desktop_notifications"
# 'papirus-icon-theme' (optional)
# 'fuzzel' (optional)


[ "${ULOCKER}" != "$0" ] &&
	exec env ULOCKER="$0" flock -en "$0" "$0" "$@" || :

UPD=/tmp/updates
UPV=/tmp/upd_versions

rm -f ${UPV}

sleep 9 && echo 0 > ${UPD}

while [ -f ${UPD} ]
	do
		if ping -n -c 1 www.archlinux.org >/dev/null 2>&1
		then  
			checkupdates > ${UPV} ; cat ${UPV} | wc -l >> ${UPD}

			[ ! "$(tail -n 1 ${UPD})" -le "$(tail -n 2 ${UPD} | head -n 1)" ] &&
				notify-send -t 10000 "UPDATES" "$(tail -n 1 ${UPD})" \
					--icon=/usr/share/icons/Papirus-Dark/48x48/apps/mx-updater.svg

			sleep 0.5h
		else
			sleep 5m
		fi
	done

# Source code: "https://bbs.archlinux.org/viewtopic.php?id=279522"

###

Waybar module

### Run the script 'updatenotif.sh' at startup of your graphical environment. It will check for updates every 30 minutes (You can manually refresh the database any time by right-clicking on the icon). Please place script files (*.sh) inside '~/.local/bin/' and don't forget to make them executable ###

updatenotif.sh (waybar-only version):

#!/bin/sh
#
#[v2.1.6]
#
# This script depends on 'pacman-contrib'


[ "${ULOCKER}" != "$0" ] &&
	exec env ULOCKER="$0" flock -en "$0" "$0" "$@" || :

UPD=/tmp/updates
UPV=/tmp/upd_versions

rm -f ${UPV}

sleep 9 && echo 0 > ${UPD}

while [ -f ${UPD} ]
	do
		if ping -n -c 1 www.archlinux.org >/dev/null 2>&1
		then
			checkupdates > ${UPV} ; cat ${UPV} | wc -l >> ${UPD}

			sleep 0.5h
		else
			sleep 5m
		fi
	done

# Source code: "https://bbs.archlinux.org/viewtopic.php?id=279522"

module:

	"custom/updates": {
		"format": "{icon}{}",
		"format-icons": ["", ""],
		"interval": 10,
		"return-type":"json",
		"exec": "~/.local/bin/updbar.sh",
		"on-click": "[ -x /usr/bin/fuzzel ] && ~/.local/bin/chckpds.sh",
		"on-click-right": "checkupdates > /tmp/upd_versions ; cat /tmp/upd_versions | wc -l >> /tmp/updates",
		"tooltip": true
	},

updbar.sh:

#!/bin/sh

UPD=/tmp/updates
UPV=/tmp/upd_versions
percentage="100"

[ -x /usr/bin/fuzzel ] &&
	menu="(on click: view updates)" ||
	menu="(on click: *please install 'fuzzel'*)"

if [ -s ${UPV} ]
then
	[ "$(tail -n 1 ${UPD})" -gt "$(tail -n 2 ${UPD} | head -n 1)" ] &&
		class="new-updates" ||
		class="updates"

	tooltip=$(tail -n 1 ${UPD})
else
	percentage="0"
	class="up-to-date"
	tooltip="0"
fi

printf '%s\n' "{\"class\":\"$class\",\"percentage\": $percentage,\"tooltip\":\"Updates: $tooltip\n\n$menu\n(right-click: refresh db)\"}"

# Alternatively, if you want the number of updates to be shown on the bar,
# comment the command above and uncomment the one below:
#printf '%s\n' "{\"class\":\"$class\",\"percentage\": $percentage,\"tooltip\":\"$menu\n(right-click: refresh db)\",\"text\":\"$tooltip\"}"

if [ "${class}" = "new-updates" ]
then
	cat ${UPV} | wc -l > ${UPD}
fi

# Source code: "https://bbs.archlinux.org/viewtopic.php?id=279522"

style:

@keyframes new-updates {
    to {
        color: #4CDD85;
    }
}

#custom-updates {
/*    color: #555555;*/
}

#custom-updates.updates {
/*    color: #00CF52;*/
}

#custom-updates.new-updates {
    color: #555555;
    animation-name: new-updates;
    animation-iteration-count: 20;
    animation-direction: alternate;
    animation-duration: 0.5s;
}

style #alternative (icon stays green if updates are available):

@keyframes new-updates {
    to {
        color: #4CDD85;
    }
}

#custom-updates {
/*    color: #555555;*/
}

#custom-updates.updates {
    color: #00CF52;
}

#custom-updates.new-updates {
    color: #555555;
    animation-name: new-updates;
    animation-iteration-count: 20;
    animation-direction: alternate;
    animation-duration: 0.5s;
}

chckpds.sh (menu feature - can also be used without waybar by e.g. assigning a key binding to it):

#!/bin/sh
#
#
# This script depends on 'fuzzel'


UPV=/tmp/upd_versions

fuzzel -d -w 80 -R --prompt="[Updates: $(cat ${UPV} | wc -l)] " --font=monospace:size=9 \
	--background=111111EE --border-color=111111FF --selection-color=111111EE \
	--text-color=999999AA --selection-text-color=999999DA --log-level=none < ${UPV} > /dev/null

# Source code: "https://bbs.archlinux.org/viewtopic.php?id=279522"

Screenshots (waybar):
HZPn.png

Animated (pulsing for 10s) whenever new updates have arrived:
HZPR.png
(The update count can also be shown on the bar - see comment inside 'updbar.sh')

HZP5.png

For more info on how to add the module to waybar, please consult:
https://github.com/Alexays/Waybar

NOTE: The update of 'ttf-nerd-fonts-symbols' to v3.0.0 messed up the codepoints of the old icons used, hence I replaced them with the "(smiley) face" ones. The "package" ones including their old and new codepoints can be found here (search term: "package").
Inside the module, their order is "closed" to "opened".

Additional links:
https://gitlab.archlinux.org/pacman/pacman-contrib
https://codeberg.org/dnkl/fuzzel
https://gitlab.gnome.org/GNOME/libnotify

Just for fun (experimental):
Script that checks for updates of this module (if you're using this, make sure to bump the version number found at the top of 'updatenotif.sh' after you updated in order for this to work - basically do the update according to the changelog...):

#!/bin/sh

SCR=$(find ~ -name "updatenotif.sh")
#SCR=~/.local/bin/updatenotif.sh
URL=https://bbs.archlinux.org/viewtopic.php?id=279522

nsd() {
	[ -x /usr/bin/notify-send ] &&
		notify-send -t 3000 "$@"
}

ping -n -c 1 www.archlinux.org >/dev/null 2>&1 || exit 2

if grep $(curl -s "${URL}" | head -n 6 | grep "MODULE" |
	cut -d' ' -f 4) ${SCR} >/dev/null 2>&1
then
	echo "Up-to-date"

	nsd "MODULE" "Up-to-date" --urgency=low
else
	echo "Update available:"
	echo "(${URL})"

	nsd "MODULE" "Update available"
fi

CHANGELOG: 'Refactored for modularity purposes - please apply update in its entirety. Make sure to have 'fuzzel' installed in order to get access to the new waybar module feature... ; #updbar.sh: replaced 'echo' with 'printf', code cleanup; #updatenotif.sh: re-added a network check so as not to reset the update count if there was no connectivity; #updbar.sh: added option to show update count on the bar; #module: enabled script output - (the last two changes need to be applied together); #module: new icons (higher compatibility with different fonts - see "NOTE" above); #chckpds.sh: replaced icon with text; #updbar.sh: do not repeat update count inside tooltip when count is shown on the bar; #updbar.sh #style: added animation for new updates; added experimental script which checks for updates of the module itself; #updatenotif.sh: initial version '2.1.0'; #style(s): increased animation time span to 10s, colour adjustments; #updatenotif.sh: bump version to '2.1.1'; #module: re-added the "package" icons as a commented option; #updatenotif.sh: bump version to '2.1.2; #module: reverted the last commit, since the icons (new codepoints) couldn't be pasted here on 'bbs forums'; #updatenotif.sh: bump version to '2.1.3'; #updbar.sh: (line 28) "[...] line above [...]" -> "[...] command above [...]"; #updatenotif.sh: bump version to '2.1.4'; #updbar.sh: remove redundant "text" variable; #updatenotif.sh: bump version to '2.1.5'; #updatenotif.sh: start "clean" into a new session, bump version to '2.1.6''

Last edited by dogknowsnx (2023-05-27 17:42:56)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#2 2022-09-07 15:27:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 28,362
Website

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

You shouldn't need to store an endless string of numbers in the temp file, just one would suffice (which simplifies all the head|tail work):

#!/bin/sh

UPD=/tmp/updates

cur=$(checkupdates | wc -l)
read prev 2>/dev/null <$UPD

[ $cur -le ${prev:-0} ] && exit
echo $cur >| $UPD

notify-send -t 10000 \
	--icon=/usr/share/icons/Papirus-Dark/48x48/apps/mx-updater.svg \
	"Updates:" "$cur"

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-09-07 15:42:07

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

@Trilby Cool - thanks.

EDIT: I will leave the original script as is, since I've gotten used to checking '/tmp/updates' for the number of packages I've updated at a time...
EDIT#2: I also deliberately avoided issuing 'checkupdates' more than once.

Last edited by dogknowsnx (2022-09-07 16:32:02)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#4 2023-05-01 16:00:46

arnavgr
Member
Registered: 2023-05-01
Posts: 6

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

@dogknowsnx this didnt work for me. When i try to run chckpds.sh i get:

cat: /tmp/upd_versions: No such file or directory
./chckpds.sh: line 8: /tmp/upd_versions: No such file or directory

do i have to create these directories or should they be present by default?

Offline

#5 2023-05-01 18:54:33

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

arnavgr wrote:

do i have to create these directories or should they be present by default?

If 'updatenotif.sh' is properly launched at startup of your graphical environment, both files will be created "by default" - '/tmp/upd_versions' won't be created unless there is a network connection - the script will retry fetching updates every 5 minutes.

Which DE/Window Manager are you running and how do you start 'updatenotif.sh'?

EDIT: If it's only 'chckpds.sh' that fails for you, there's a chance that you're running an older version of 'updatenotif.sh' and you would have updated partially - which is not supported on Arch tongue
Please also make sure to have read the notes at the bottom of post #1 before posting...

Last edited by dogknowsnx (2023-05-02 07:40:33)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#6 2023-05-02 12:42:34

arnavgr
Member
Registered: 2023-05-01
Posts: 6

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

dogknowsnx wrote:
arnavgr wrote:

do i have to create these directories or should they be present by default?

If 'updatenotif.sh' is properly launched at startup of your graphical environment, both files will be created "by default" - '/tmp/upd_versions' won't be created unless there is a network connection - the script will retry fetching updates every 5 minutes.

Which DE/Window Manager are you running and how do you start 'updatenotif.sh'?

EDIT: If it's only 'chckpds.sh' that fails for you, there's a chance that you're running an older version of 'updatenotif.sh' and you would have updated partially - which is not supported on Arch tongue
Please also make sure to have read the notes at the bottom of post #1 before posting...

Ok i use hyprland i have placed updatenotif.sh in ~/.bin ( which is added to $PATH)

i added the line exec-once = ~/bin/updatenotif.sh & in hyprland.conf

https://github.com/arnavgr/dotfiles/tre … fig/waybar is where i have it setup. If theres anything wrong that im doing please help me

Offline

#7 2023-05-02 12:58:26

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

arnavgr wrote:

Ok i use hyprland i have placed updatenotif.sh in ~/.bin ( which is added to $PATH)

i added the line exec-once = ~/bin/updatenotif.sh & in hyprland.conf

https://github.com/arnavgr/dotfiles/tre … fig/waybar is where i have it setup. If theres anything wrong that im doing please help me

Well, there are already a couple of problems. First, you are stating two paths ('~/bin' and '~/.bin'), which one is in your $PATH? And second, for convenience (and to prevent issues like you're describing) I picked '~/.local/bin/' as the location where additional scripts will be looked for - $PATH is irrelevant in this use case. If you want to use $PATH, you can grep -n the code above for '~/.local/bin/' and remove that part and only leave the script's name in place (untested on my part and possibly error-prone, but *should* work). Or you can simply place the scripts inside '~/.local/bin/' and your issue *should* be solved...

EDIT: Third, looking over the scripts in your .dotfiles I can tell you that you're running a partial update - please replace the scripts by the ones from post #1.

EDIT#2: You may want to also check your waybar config, since there appear to be a few too many open brackets...

Last edited by dogknowsnx (2023-05-02 13:44:28)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#8 2023-05-02 14:09:19

arnavgr
Member
Registered: 2023-05-01
Posts: 6

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

dogknowsnx wrote:
arnavgr wrote:

Ok i use hyprland i have placed updatenotif.sh in ~/.bin ( which is added to $PATH)

i added the line exec-once = ~/bin/updatenotif.sh & in hyprland.conf

https://github.com/arnavgr/dotfiles/tre … fig/waybar is where i have it setup. If theres anything wrong that im doing please help me

Well, there are already a couple of problems. First, you are stating two paths ('~/bin' and '~/.bin'), which one is in your $PATH? And second, for convenience (and to prevent issues like you're describing) I picked '~/.local/bin/' as the location where additional scripts will be looked for - $PATH is irrelevant in this use case. If you want to use $PATH, you can grep -n the code above for '~/.local/bin/' and remove that part and only leave the script's name in place (untested on my part and possibly error-prone, but *should* work). Or you can simply place the scripts inside '~/.local/bin/' and your issue *should* be solved...

EDIT: Third, looking over the scripts in your .dotfiles I can tell you that you're running a partial update - please replace the scripts by the ones from post #1.

EDIT#2: You may want to also check your waybar config, since there appear to be a few too many open brackets...

1) im sorry i accidentally wrote ~/.bin i meant ~/bin (~/bin has been added to $PATH using   PATH="$HOME/bin:$PATH")
2) does adding scripts to ~/.local/bin automatically adds the scripts to $PATH, if so that solves a lot of my problems
3)i see what you mean, i usually just add }, instead of } and then }, because it works. i will fix it and see if things change

Offline

#9 2023-05-02 14:20:34

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

arnavgr wrote:

1) im sorry i accidentally wrote ~/.bin i meant ~/bin (~/bin has been added to $PATH using   PATH="$HOME/bin:$PATH")
2) does adding scripts to ~/.local/bin automatically adds the scripts to $PATH, if so that solves a lot of my problems
3)i see what you mean, i usually just add }, instead of } and then }, because it works. i will fix it and see if things change

2) No, you would have to export it e.g. in your shell's rc file

export PATH=$PATH:$HOME/.local/bin/

but that's a different issue.

I'd suggest you try the whole thing as is (and as is intended) without editions/customizations first and see if it's working for you. Then It'll be easier to troubleshoot (for me, but also for you).

Last edited by dogknowsnx (2023-05-02 14:21:25)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#10 2023-05-02 14:49:52

arnavgr
Member
Registered: 2023-05-01
Posts: 6

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

dogknowsnx wrote:
arnavgr wrote:

1) im sorry i accidentally wrote ~/.bin i meant ~/bin (~/bin has been added to $PATH using   PATH="$HOME/bin:$PATH")
2) does adding scripts to ~/.local/bin automatically adds the scripts to $PATH, if so that solves a lot of my problems
3)i see what you mean, i usually just add }, instead of } and then }, because it works. i will fix it and see if things change

2) No, you would have to export it e.g. in your shell's rc file

export PATH=$PATH:$HOME/.local/bin/

but that's a different issue.

I'd suggest you try the whole thing as is (and as is intended) without editions/customizations first and see if it's working for you. Then It'll be easier to troubleshoot (for me, but also for you).

OK so here's what i changed:

1) created .~/.local/bin and added all three scripts (updbar.sh, chckpds.sh, updatenotif.sh)
2) changed config module in waybar. changed hyprland.conf to exec ~/.local/bin/updatenotif.sh
3) restarted hyprland

the module does not show on my waybar but:

1) chckpds.sh opens fuzzel and shows updates
2) htop shows ./updatenotif.sh running
3) updbar.sh appends {"class":"new-updates","percentage": 100,"tooltip":"Updates: 12\n\n(on click: view updates)\n(right-click: refresh db)"}

2 things i wanted to clarify:

1) im using waybar-hypland-git package from aur(to display workspaces)
2) i have symlinked waybar from my git repo to ~/.config does that affect anything?

Offline

#11 2023-05-02 14:59:39

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

As to the last two points: i honestly have no idea and currently won't be able to test this.

What does waybar report, if you start it from your terminal (wild guess: you are still using the wrong path(s) in your waybar config...)?

EDIT: Ok, I saw you've changed it to '~/.local/bin/' - what about those brackets, then? And did you try with a local config file for waybar?

Anyway,

dogknowsnx wrote:

I'd suggest you try the whole thing as is (and as is intended) without editions/customizations first and see if it's working for you. Then It'll be easier to troubleshoot (for me, but also for you).

Last edited by dogknowsnx (2023-05-03 20:07:38)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#12 2023-05-02 16:04:00

arnavgr
Member
Registered: 2023-05-01
Posts: 6

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

dogknowsnx wrote:

As to the second last points: i honestly have no idea and currently won't be able to test this.

What does waybar report, if you start it from your terminal (wild guess: you are still using the wrong path(s) in your waybar config...)?

EDIT: Ok, I saw you've changed it to '~/.local/bin/' - what about those brackets, then? And did you try with a local config file for waybar?

Anyway,

dogknowsnx wrote:

I'd suggest you try the whole thing as is (and as is intended) without editions/customizations first and see if it's working for you. Then It'll be easier to troubleshoot (for me, but also for you).


i dont know what you mean by those brackets, can u elabolarte. btw thank you for helping me

Offline

#13 2023-05-02 16:10:02

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

Please try this: copy the module from post #1 and add it on top of your other modules in your config - also did you try starting waybar from the terminal to see what it reports?

Edited...

Last edited by dogknowsnx (2023-05-02 16:10:43)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

#14 2023-05-02 17:23:47

arnavgr
Member
Registered: 2023-05-01
Posts: 6

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

Yo PLACING THIS ON TOP OF ALL OTHER MODULES WORKED THANK YOU SO MUCH

Last edited by arnavgr (2023-05-02 17:39:10)

Offline

#15 2023-05-02 17:44:35

dogknowsnx
Member
Registered: 2021-04-12
Posts: 452

Re: [ WAYBAR MODULE v2.1.6 ] Notifications for Arch Linux package updates

arnavgr wrote:

Yo PLACING THIS ON TOP OF ALL OTHER MODULES WORKED THANK YOU SO MUCH

Great, enjoy!

Last edited by dogknowsnx (2023-05-02 17:45:22)


Wayland.

"We are eternal, all this pain is an illusion" - Maynard James Keenan

Offline

Board footer

Powered by FluxBB