aboutsummaryrefslogtreecommitdiff
path: root/.config/eww/scripts/freebsd-updates.sh
diff options
context:
space:
mode:
Diffstat (limited to '.config/eww/scripts/freebsd-updates.sh')
-rwxr-xr-x.config/eww/scripts/freebsd-updates.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/.config/eww/scripts/freebsd-updates.sh b/.config/eww/scripts/freebsd-updates.sh
new file mode 100755
index 0000000..aadb5cf
--- /dev/null
+++ b/.config/eww/scripts/freebsd-updates.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+
+function CheckUpdates() {
+pkg upgrade -n | awk '/Installed packages to be UPGRADED:/{p=1}/^ *$/{p=0}p' | tail -n +2 1> /tmp/freebsd-updates
+updates="$(cat /tmp/freebsd-updates | awk '{ print $1 }')"
+number=$(cat /tmp/freebsd-updates | wc -l | xargs)
+
+if [ "$number" -gt 0 ]; then
+ text=" $number"
+else
+ text=""
+fi
+
+echo "$text"
+}
+
+function RefreshUpdates() {
+ value="$(CheckUpdates)"
+ eww update freebsd-updates="$value"
+}
+
+function Update() {
+ foot bash -c 'doas pkg upgrade'
+ RefreshUpdates
+}
+
+case "$1" in
+ Refresh)
+ RefreshUpdates
+ exit 0
+ ;;
+ Update)
+ Update
+ exit 0
+ ;;
+ *)
+ CheckUpdates
+ exit 0
+esac