summaryrefslogtreecommitdiff
path: root/bin/extra/upds
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-04-15 17:37:53 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-04-15 17:37:53 +0200
commit25a2605405d8ec7645d0664914c3b7290745afec (patch)
tree8afe0d8828a3909bfe2774385c8bebc039cf6d6e /bin/extra/upds
parentc9a06111585c189607ff1e81b77bb32f0a25a992 (diff)
synced
Diffstat (limited to 'bin/extra/upds')
-rwxr-xr-xbin/extra/upds51
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