You are not logged in.

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

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

[ WAYBAR MODULE v4.0.3 ] Notifications for Arch Linux package updates

DISCLAIMER:
This module requires waybar >= 0.9.24 ! (see also upstream issue (fixed): https://github.com/Alexays/Waybar/issues/2631 )

NOTE: If you came here by clicking on the link in my signature and expected to find desktop notifications, please have a look at post #3

Scope/Features:

  • Notifications/Information only (no 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)

  • Highlight most recent updates (fuzzy searchable)

  • Dynamic icon (5 different states, animated notifications)

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

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

  • Why?⁽¹⁾

Languages: Shell, Python, CSS

Run the script 'updatenotif.sh' at startup of your graphical environment (or you can use the systemd user service - see "Development" below). 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, *.py) inside '~/.local/bin/' and don't forget to make the shell scripts (*.sh) executable.
(It may be worth noting that I've appended comments to values that can be modified without breaking the module - given that the syntax is correct)

updatenotif.sh:

#!/bin/bash
#
#[v4.0.3]
#
# This script depends on 'pacman-contrib'


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

UPD=/tmp/upd/updates
UPV=/tmp/upd/versions
UPN=/tmp/upd/versions.new
UPO=/tmp/upd/versions.old
UBR=~/.local/bin/updbar.py

sed_pc() {
	sed -i -e "12s/percentage\ =\ [0-9]*/percentage\ =\ $1/" \
		   -e "24s/percentage\ =\ [0-9]*/percentage\ =\ $2/" ${UBR}
}

sed_cl() {
	sed -i "29s/clss =\ .*\ #/clss\ =\ \"$1\"\ #/" ${UBR}
}

sed_nw() {
	local IFS=$'\n'
	for i in $(< ${UPN})
		do sed -i "s/$i.*/&\ \ \ NEW/" ${UPV}
		done

	sed -i "s/NEW.*/NEW/g" ${UPV}
}

sig() {
	pkill -x -SIGRTMIN+9 waybar
}

mkdir -p /tmp/upd ; : > ${UPN} ; echo 0 > ${UPD}

echo "$$" > /tmp/upd/PID

while [ -f ${UPD} ]
	do
		echo "refreshing" > ${UPV} ; sig

		checkupdates -n > ${UPO}

		if ping -n -c 1 -W 5 archlinux.org >/dev/null 2>&1
		then
			sed_pc 100 0 ; checkupdates | tee ${UPV} | wc -l > ${UPD}

			if diff ${UPV} ${UPO} >/dev/null 2>&1
			then
				[ -s ${UPV} ] || : > ${UPN}

				sed_cl updates ; sed_nw ; sig
			else
				comm -23 ${UPV} ${UPO} 2>/dev/null | cut -d' ' -f 1,2 > ${UPN}

				sed_cl new-updates ; sed_nw ; sig

				# If you want to add an acoustic notification, this would be the place
				# (needs logging out/in to take effect):
				#paplay /path/to/sound.file &
			fi
			
			sleep 10 && sed_cl updates ; sig # Notification duration
			sleep 0.5h # Interval in which to check for updates
		else # 'offline' mode
			if checkupdates -n >/dev/null 2>&1
			then
				sed_pc 70 70 ; : > ${UPV} ; sig

				sleep 3m # Interval in which to retry ('updates' state)
			else
				sed_pc 30 30 ; : > ${UPV} ; sig

				sleep 3m # Interval in which to retry ('up-to-date' state)
			fi
		fi
	done

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

module (NOTE: in case you are on 'hyprland' or 'qtile', use "on-click-release" and disable "on-click"):

    "custom/updates": {
        "format": "{icon} {}", // normal size, count appended
    //    "format": "<span size='large'>{icon}</span>", // large size, no count appended
        "format-icons": ["", "", "", "", ""],
        "return-type":"json",
        "exec-if": "[ -f /tmp/upd/updates ]",
        "exec": "python ~/.local/bin/updbar.py",
        "on-click": "~/.local/bin/chckpds.sh", // menu feature
    //    "on-click-release": "~/.local/bin/chckpds.sh", // workaround for 'hyprland' (requires waybar >= 0.9.24)
        "on-click-right": "~/.local/bin/updbar_rst.sh", // refreshes the database
        "signal": 9,
        "tooltip": true
    },

updbar.py:

#!/usr/bin/python

from os import path, stat
from datetime import datetime as dt

# clss = 'class'

upd = '/tmp/upd/updates'
upv = '/tmp/upd/versions'
upv_n = '/tmp/upd/versions.new'

percentage = 100 # don't move [12]
tooltip = open(upd, 'r').read().rstrip("\n")

with open(upv_n, 'r') as cn:
   new_c = sum(1 for _ in cn)

mod_tstamp_v = path.getmtime(upv)
mod_tstamp_n = path.getmtime(upv_n)
mod_datetime_v = dt.fromtimestamp(mod_tstamp_v).strftime("%H:%M %d %b")
mod_datetime_n = dt.fromtimestamp(mod_tstamp_n).strftime("%H:%M %d %b")

if stat(upv).st_size == 0:
    percentage = 0 # don't move [24]
    clss = "up-to-date"
else:
    if open(upv, 'r').read().rstrip("\n") != 'refreshing':
        percentage = 100
        clss = "updates" # don't move [29]
    else:
        percentage = 50
        clss = "refreshing"
        tooltip = "refreshing db..."

bttn = "[on click: view updates\\n right-click: refresh db]"

if percentage != 30 and percentage != 70:
    match clss:
        case 'refreshing':
            print(f'{{"class":"{clss}","percentage": {percentage},"tooltip": "{tooltip}"}}')
        case 'new-updates':
            print(f'{{"class":"{clss}","percentage": {percentage},"tooltip": "{new_c} '\
                  f'new update(s) found...","text":"<span color=\'#4CDD85\'>{new_c}</span>"}}')
        case _:
            print(f'{{"class":"{clss}","percentage": {percentage},"tooltip": "Total: '\
                  f'<span color=\'#1793D1\'>{tooltip}</span>  @{mod_datetime_v}\\nNew: '\
                  f'<span color=\'#4CDD85\'>{new_c}</span>  @{mod_datetime_n}\\n\\n{bttn}",'\
                  f'"text":"<span color=\'#1793D1\'>{tooltip}</span>"}}')
else:
    clss = "offline"
    print(f'{{"class":"{clss}","percentage": {percentage},"tooltip": "{clss}"}}')

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

updbar_rst.sh:

#!/bin/bash

[ -z $WAYLAND_DISPLAY ] && exit 0

UPD=/tmp/upd/updates
UPV=/tmp/upd/versions
UPN=/tmp/upd/versions.new
UPO=/tmp/upd/versions.old
UBR=~/.local/bin/updbar.py

sed_pc() {
	sed -i -e "12s/percentage\ =\ [0-9]*/percentage\ =\ $1/" \
		   -e "24s/percentage\ =\ [0-9]*/percentage\ =\ $2/" ${UBR}
}

sed_cl() {
	sed -i "29s/clss =\ .*\ #/clss\ =\ \"$1\"\ #/" ${UBR}
}

sed_nw() {
	local IFS=$'\n'
	for i in $(< ${UPN})
		do sed -i "s/$i.*/&\ \ \ NEW/" ${UPV}
		done

	sed -i "s/NEW.*/NEW/g" ${UPV}
}

sig() {
	pkill -x -SIGRTMIN+9 waybar
}

echo "refreshing" > ${UPV} ; sig

checkupdates -n > ${UPO}

if ping -n -c 1 -W 5 archlinux.org >/dev/null 2>&1
then
	sed_pc 100 0 ; checkupdates | tee ${UPV} | wc -l > ${UPD}

	if diff ${UPV} ${UPO} >/dev/null 2>&1
	then
		[ -s ${UPV} ] || : > ${UPN}

		sed_cl updates ; sed_nw ; sig
	else
		comm -23 ${UPV} ${UPO} 2>/dev/null | cut -d' ' -f 1,2 > ${UPN}

		sed_cl new-updates ; sed_nw ; sig
	fi

	sleep 10 && sed_cl updates ; sig # Notification duration
else
	if checkupdates -n >/dev/null 2>&1
	then
		sed_pc 70 70 ; : > ${UPV} ; sig
	else
		sed_pc 30 30 ; : > ${UPV} ; sig
	fi
fi

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

style:

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

@keyframes refreshing {
  from {color:#555555;}
    to {color:#1793D1;}
}

#custom-updates {
    color: #555555;
}

#custom-updates.up-to-date {
    color: #555555;
}

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

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

#custom-updates.refreshing {
    animation-name: refreshing;
    animation-duration: 1.5s;
    animation-direction: alternate;
    animation-iteration-count: infinite;
}

#custom-updates.offline {
    color: #E2426C;
}

# Menu

Two examples shown below - or simply create your own based on these scripts (NOTE: pick 'bemenu' if you consider using the 'RI module')

chckpds.sh ('fuzzel' version - needs workaround for 'hyprland', see 'module' above):

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

set -e

UPV=/tmp/upd/versions
UPN=/tmp/upd/versions.new

[[ "$(< ${UPV})" = "refreshing" ]] && exit
[ $(pidof fuzzel) ] && pkill -x fuzzel && exit

ps -q $(< /tmp/upd/PID) >/dev/null 2>&1 &&
	STT="running" || STT="stopped"

fzz() {
	fuzzel -d -w 80 --font=monospace:size=9 \
		--background=111111EE --border-color=111111FF --text-color=999999FF \
			--selection-text-color=FFFFFFBB --log-level=none --log-no-syslog "$1"
}

pcl() {
	[[ $(ps -ef | grep '[f]oot --server') ]] &&
		footclient -w 1800x900 ~/.local/bin/pclinf.sh &
}

if [ -s ${UPV} ]
then
	fzz --prompt="[Total: $(cat ${UPV} | wc -l) |New: $(cat ${UPN} | wc -l) |${STT}] " < ${UPV} > /dev/null 

	pcl
else
	if python ~/.local/bin/updbar.py | grep "up-to-date" >/dev/null 2>&1
	then
		echo " " | fzz --prompt="[${STT}] " > /dev/null
	else
		checkupdates -n | fzz --prompt="[offline|${STT}] " > /dev/null
	
		pcl
	fi
fi

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

chckpds.sh ('bemenu' version - needs workaround for 'hyprland', see 'module' above):

#!/bin/bash
#
#
# This script depends on 'bemenu-wayland'

set -e

UPV=/tmp/upd/versions
UPN=/tmp/upd/versions.new

[[ "$(< ${UPV})" = "refreshing" ]] && exit
[ $(pidof bemenu) ] && pkill -x bemenu && exit

ps -q $(< /tmp/upd/PID) >/dev/null 2>&1 &&
	STT="running" || STT="stopped"

bmn() {
	bemenu --fn 'monospace 12' -i -l 15 -n -s -w -W 0.5 \
		--cw 1 --cf \#555555 --nf \#999999 --hf \#FFFFFF --tf \#999999 "$1"
}

pcl() {
	footclient -w 1800x900 --title=pclinfo ~/.local/bin/pclinf.sh &
}

if [ -s ${UPV} ]
then
	bmn --prompt="[Total: $(cat ${UPV} | wc -l) |New: $(cat ${UPN} | wc -l) |${STT}] " < ${UPV} > /dev/null 

	pcl
else
	if python ~/.local/bin/updbar.py | grep "up-to-date" >/dev/null 2>&1
	then
		echo " " | bmn --prompt="[${STT}] " > /dev/null
	else
		checkupdates -n | bmn --prompt="[offline|${STT}] " > /dev/null

		pcl
	fi
fi

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

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

# Screenshots (depicted icons differ from those used in the module - see "NOTE" below):
HfF-.png

Animated notifications:
HfFz.png HfFi.png

Tooltip: Total count is followed by the timestamp of the last sync, new updates count is followed by the timestamp of their notification - in case you missed it smile:
HfFr.png
(The update count can either be hidden or shown (new default) on the bar - see "format" examples inside the module)

Menu feature (fuzzel):
Hfhh.png

HfFs.png

NOTE: Since the update of 'ttf-nerd-fonts-symbols' to v3 the codepoints of the original icons used cannot be pasted here on bbs anymore, hence I replaced them with the more generic "(smiley) face" ones. The "package" ones including their old and new codepoints can be found here (search terms: "package", "hexagon").
Inside the module, their order is:
HfFc.png
Placeholders used in the module:
HfFT.png
In case some icons are missing/aren't rendered correctly, you may want to install a 'nerd-font'...

The module has no immediate way of telling whether you issued 'pacman -Syu' (out-of-scope*), so you will have to let it know. This can either be achieved by simply right-clicking the icon, or by doing the update like this (I recommend the former - but, oh well - it's your system tongue):

# pacman -Syu && ~/.local/bin/updbar_rst.sh

*(Personally, I usually do the update while not being logged into a graphical environment, BUT if you must emulate the behavior of similar modules out there, I'll give you an inch: "on-click-middle" is unallocated by default... - please don't ask for a mile tongue)

Additional links:
https://gitlab.archlinux.org/pacman/pacman-contrib
https://codeberg.org/dnkl/fuzzel
https://github.com/Cloudef/bemenu


# Development


Systemd user service:

CAVEATS: can potentially freeze the module if stopped while processing, but can be reset by a right-click.

Usage:
Place 'updatenotif.service' inside '~/.config/systemd/user/' (do not replace "user" with your own user here), replace "username" with your user in the "ExecStart" array, then enable the service:

systemctl --user enable updatenotif.service

Or, if no other instance of 'updatenotif.sh' is running, you can start the service right away:

systemctl --user enable --now updatenotif.service

updatenotif.service (experimental):

[Unit]
Description=Notifications for Arch Linux package updates

[Service]
Type=simple
RemainAfterExit=no
ExecStart=/home/username/.local/bin/updatenotif.sh

[Install]
WantedBy=default.target

For more detailed info, please see: https://wiki.archlinux.org/title/Systemd/User


pclinf.sh (advanced menu, template/incentive - can be envoked from the default menu by pressing 'Enter'):

#!/bin/bash
#
#
cat <<MOS

──────────────────────────────────────────────────────────────────────────────

This script depends on:

'foot' (server)
'fzf'
'w3m'
'wl-clipboard'

If you intend to replace the "default" menu with this script,
then put it inside '~/.local/bin/', and edit the module like so:

		"on-click": "footclient -w 1800x1000 ~/.local/bin/pclinf.sh",
		
──────────────────────────────────────────────────────────────────────────────

MOS


_chg="Changelog ['q': return]"
_pct="pactree -r"
_pkk="pacman -Qkk"
_nqu="New query"

UPV=/tmp/upd/versions
URL=https://gitlab.archlinux.org/archlinux/packaging/packages/
PS3="q) Quit
───────────────────────────
: "

pmn() {
	echo "Package '$(wl-paste)':"
	echo
	echo "1) ${_chg}"
	echo "2) ${_pct}"
	echo "3) ${_pkk}"
	echo "4) ${_nqu}"
}

fzf_upd() {
	fzf --cycle --color=fg+:#1793D1 --preview='pacman -Qii {1}' \
		--preview-window=top,60% --bind 'right:toggle-preview-wrap' \
		--layout=reverse
}

wlp() {
	cut -d' ' -f 1 | wl-copy
}

if [ -s ${UPV} ]
then
	fzf_upd < ${UPV} | wlp
else
	checkupdates -n | fzf_upd | wlp
fi

if [ -z "$(wl-paste)" ]
then
	echo
	echo "Exiting..."
	sleep 0.5
	exit
fi

echo
echo "Package '$(wl-paste)':"
echo

select cmd in "${_chg}" \
			  "${_pct}" \
			  "${_pkk}" \
			  "${_nqu}"
	do case $cmd in

		"${_chg}")
				if curl -s ${URL}/$(wl-paste | cut -d'-' -f 1,2)/-/commits/main |
					grep "You are being\|redirected" >/dev/null 2>&1
				then
					echo
					echo "Sorry, the URL cannot be resolved."
					echo "Please use the search function on 'https://archlinux.org/packages/'"
					echo
				else
					w3m "${URL}/$(wl-paste | cut -d'-' -f 1,2)/-/commits/main"
					echo
				fi
				pmn
				;;
		"${_pct}")
				echo
				pactree -r $(wl-paste)
				echo
				pmn
				;;
		"${_pkk}")
				echo
				pacman -Qkk $(wl-paste)
				echo
				pmn
				;;
		"${_nqu}")
				[[ "$(< ${UPV})" = "refreshing" ]] && exit 1
													
				if [ -s ${UPV} ]
				then
					fzf_upd < ${UPV} | wlp
				else
					checkupdates -n | fzf_upd | wlp
				fi
				
				if [ -z "$(wl-paste)" ]
				then
					echo
					echo "Exiting..."
					sleep 0.5
					break
				fi

				echo
				pmn
				;;
		*)
				break
				;;
		esac
	done

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

Last edited (2023-11-03 10:41)


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

#!/bin/sh
#
#
# If you intend to integrate this script in the module,
# name it e.g. 'updatenotif_upd.sh', place it inside 
# '~/.local/bin/' and add:
#
#		"on-click-middle": "~/.local/bin/updatenotif_upd.sh",
#
# to the 'on-click-*' arrays inside the module.
# The method above requires working desktop notifications
# and 'libnotify'.
# Otherwise just run the script from your terminal.

UP="UPDATES module"
RI="RI module"
UTD="up-to-date"
UPD="update available"
SCR1=~/.local/bin/updatenotif.sh
SCR2=~/.local/bin/ri.sh
URL1=https://bbs.archlinux.org/viewtopic.php?id=279522
URL2=https://bbs.archlinux.org/viewtopic.php?id=290491

grp() {
	grep $(curl -s "$1" | head -n 6 | grep "MODULE" |
		cut -d' ' -f 4) "$2" >/dev/null 2>&1
}

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

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

echo

if [ -f ${SCR1} ]
then
	if grp ${URL1} ${SCR1}
	then
		echo "${UP}: ${UTD}"

		nsd "${UP}" "${UTD}" --urgency=low
	else
		echo "${UP}: ${UPD}:"
		echo "(${URL1})"
		
		nsd "${UP}" "${UPD}"
	fi
fi

echo

if [ -f ${SCR2} ]
then
	if grp ${URL2} ${SCR2}
	then
		echo "${RI}: ${UTD}"

		nsd "${RI}" "${UTD}" --urgency=low
	else
		echo "${RI}: ${UPD}:"
		echo "(${URL2})"
		
		nsd "${RI}" "${UPD}"
	fi
fi

Last edited (2023-11-22 10:07)


###


'v1.0.0': Refactored - please update all parts
'v0.1.0': New features - please see changelog for info on updated parts (updating all parts recommended)
'v0.0.1': Bug fixes - please see changelog for info on updated parts


CHANGELOG: ' ### Desktop notifications have been moved to post #3 - this is now waybar-only. ### ; #updbar.sh: code clean-up; #updbar_rst.sh: skip 'cat'; #updatenotif.sh: skip 'cat', bump version to 'v3.2.1'; style: keep it simple and provide only one template, '.new-updates': blink rather than pulse (higher contrast will draw one's attention - which is the point of a notification)'; #updatenotif.sh: bump version to 'v3.2.2'; #updbar.sh #updbar_rst.sh #updatenotif.sh: small improvements, bump version to 'v3.2.4' ! Please make sure to update all three scripts ! '; #updbar.sh: if we want to add an acoustic notification, we use '#updatenotif.sh' instead; #updatenotif.sh: added commented array for acoustic notifications, bump version to 'v3.2.5'; #chckpds.sh: adjusted wofi example; #style #updbar_rst.sh: small improvements; #updatenotif.sh: small improvements, bump version to 'v3.2.6'; #NEW: Highlight most recent updates, including "mere" version bumps (fuzzy searchable from the menu, as well); 'offline' mode: show both states (up-to-date/updates); bump version to 'v3.3.0'; The latest changes required a little bit of refactoring, so please make sure to update all parts (temp files have their own directory now, please refrain from patching your old scripts), and log out/in for the changes to take effect... - Please report bugs if you find any, since something may have been lost in copy-pasting tongue; #chckpds.sh: 'pclinf.sh'-ready; #updatenotif.sh: bump version to 'v3.3.1'; # New beta release: significant performance improvements; 'updbar.sh' got replaced by 'updbar.py', which will be called only on demand (no constant generating of json output; states are being updated in realtime); #updatenotif.sh: bump version to 'v4.0.b'; #updatenotif.sh: removed redundant sleep command for optional acoustic notifications; cleanup; #style, #updbar.py: minor adjustments; #updatenotif.sh: removed a leftover variable; minor adjustments; #updbar_rst.sh: minor adjustments; feature: added an experimental systemd user service; #updatenotif.sh: removed initial sleep command, since 'default.target' takes care of the network (systemd user service) - if the user is not using the service, let them decide whether to delay the start in their DE/WM config; #module: "exec-if" "/tmp/upd/updates" exists; #chckpds.sh: display background process state, hence allow to run if "empty"; #module: added comment on how to append update count to icon: #updbar.py: removed 'print' alternative detour, dummy!; #updatenotif.sh: bump version to 'v4.0.0' ### Please make sure to update all parts ###; #updbar.py: minor adjustments and optimizations; use "new" syntax whenever possible; a 'tab' snuck in there, sorry; #systemd user service: reverted latest commits; #updbar_rst.sh: minor adjustments; #menu: removed 'wofi' and 'wmenu' (AUR) examples; #updatenotif.sh: bump version to 'v4.0.1'; #updbar_rst.sh: properly reset new updates count when up-to-date; #updatenotif.sh: properly reset new updates count when up-to-date; bump version to 'v4.0.2'; #chckpds.sh: added 'bemenu' example; #module: show count on bar by default; removed "interval", since it's no longer needed; added "on-click-release" workaround for 'hyprland' *sigh*; ### requires waybar >= 0.9.24 (see also "DISCLAIMER" at top of page) ###; #chckpds.sh: check for process id instead of name; small fix and optimization; #updatenotif.sh: store PID; bump version to 'v4.0.3''

───
⁽¹⁾Having an overview of updates and their versions one click away helps me in maintaining a mostly bug-free system, given that I follow the developement of specific applications, check bug reports regularly, as well as do some reading on these forums.
This module is taylored to my own preferences/needs. If you try it and come to find it useful, too, then that's just a bonus and I'm happy to contribute something to the awesome open-source community. Thanks

Last edited by dogknowsnx (2023-11-28 12:14:18)


Notifications for Arch Linux package updates
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: 29,100
Website

Re: [ WAYBAR MODULE v4.0.3 ] 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: 547

Re: [ WAYBAR MODULE v4.0.3 ] Notifications for Arch Linux package updates

### Desktop notifications ###

This script is not actively maintained, but I'm happy to address possible issues,
it *should* also still work with 'chckpds.sh' (menu script) from post #1...

updatenotif.sh:

#!/bin/bash
#
#
### Description:
#
# 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"
# 'fuzzel' (optional, menu feature)
# 'papirus-icon-theme' (optional)


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

UPV=/tmp/upd/versions
UPN=/tmp/upd/versions.new
UPO=/tmp/upd/versions.old

nsd() {
	notify-send -t 10000 \
		"UPDATES" "$(cat ${UPV} | wc -l) |NEW: $(cat ${UPN} | wc -l) " \
			--icon=/usr/share/icons/Papirus-Dark/48x48/apps/mx-updater.svg "$@"
}

sed_nw() {
	local IFS=$'\n'
	for i in $(< ${UPN})
		do sed -i "s/$i.*/&\ \ \ NEW/" ${UPV}
		done

	sed -i "s/NEW.*/NEW/g" ${UPV}
}

rm -fr /tmp/upd ; mkdir /tmp/upd ; : > ${UPN}

sleep 5

while [ -d /tmp/upd ]
	do
		checkupdates -n > ${UPO}
		
		if ping -n -c 1 -W 9 archlinux.org >/dev/null 2>&1
		then
			checkupdates > ${UPV}
			
			if [ -s ${UPV} ]
			then
				if diff ${UPV} ${UPO} >/dev/null 2>&1
				then
					sed_nw
				else
					comm -23 ${UPV} ${UPO} 2>/dev/null | cut -d' ' -f 1,2 > ${UPN}

					sed_nw ; nsd #--urgency=low # uncomment for silent popups			
				fi
			fi

			sleep 0.5h # Interval in which to check for updates
		else
			sleep 5m # Interval in which to retry
		fi
	done

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

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

Last edited by dogknowsnx (2023-10-12 15:41:48)


Notifications for Arch Linux package updates
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 v4.0.3 ] 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: 547

Re: [ WAYBAR MODULE v4.0.3 ] 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)


Notifications for Arch Linux package updates
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 v4.0.3 ] 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: 547

Re: [ WAYBAR MODULE v4.0.3 ] 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)


Notifications for Arch Linux package updates
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 v4.0.3 ] 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: 547

Re: [ WAYBAR MODULE v4.0.3 ] 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)


Notifications for Arch Linux package updates
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 v4.0.3 ] 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: 547

Re: [ WAYBAR MODULE v4.0.3 ] 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)


Notifications for Arch Linux package updates
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 v4.0.3 ] 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: 547

Re: [ WAYBAR MODULE v4.0.3 ] 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)


Notifications for Arch Linux package updates
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 v4.0.3 ] 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: 547

Re: [ WAYBAR MODULE v4.0.3 ] 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)


Notifications for Arch Linux package updates
Wayland.

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

Offline

Board footer

Powered by FluxBB