diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-04-16 10:09:29 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-04-16 10:09:29 +0200 |
commit | 692bc52c20da866630fa401be6740bc38f8f8574 (patch) | |
tree | be52e621dbbb15bfd2f43ec92053e4b0a817c392 /bin/extra/upds | |
parent | 197a1a74f468d9d69d624b19f90280a3946455e5 (diff) | |
parent | 19ea61db733c9152f2b334b0ae9871f81ac3664d (diff) |
Merge branch 'main' of debuc.com:dotfiles
Diffstat (limited to 'bin/extra/upds')
-rwxr-xr-x | bin/extra/upds | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/extra/upds b/bin/extra/upds new file mode 100755 index 0000000..38648ed --- /dev/null +++ b/bin/extra/upds @@ -0,0 +1,51 @@ +#!/bin/sh + +if [ "$1" = "install" ] +then + hook="/etc/pacman.d/hooks/upds.hook" + if [ "$(id -u)" -ne 0 ] + then + >&2 printf 'Please run as root.\n'; exit 1 + fi + + if [ -f "$hook" ] + then + >&2 printf 'Hook already installed.\n'; exit 1 + fi + + # Install the hook + cat <<EOF > "$hook" +# Hook for keeping available updates in sync after upgrade +# relies on 'upds' +[Trigger] +Operation = Upgrade +Type = Package +Target = * +[Action] +Description = Sync upds +When = PostTransaction +Exec = /usr/bin/sh -c '/usr/bin/kill -s USR1 "\$(/usr/bin/pgrep upds | /usr/bin/head -n 1)"' +EOF + >&2 printf 'Installed.\n' + + exit +fi + +count_updates() { checkupdates | wc -l > ~/.cache/updates; } + +# Periodically count updates in background +( + while true + do + count_updates + sleep 60m + done +) & + +# update on USR1 signal +trap count_updates USR1 + +# wait for signal +while true +do sleep 1s +done |