2023-08-31 05:43:42 -04:00
|
|
|
#!/bin/sh
|
|
|
|
# _ _ _ _
|
|
|
|
# | | | |_ __ __| | __ _| |_ ___ ___
|
|
|
|
# | | | | '_ \ / _` |/ _` | __/ _ \/ __|
|
|
|
|
# | |_| | |_) | (_| | (_| | || __/\__ \
|
|
|
|
# \___/| .__/ \__,_|\__,_|\__\___||___/
|
|
|
|
# |_|
|
|
|
|
#
|
|
|
|
# by Stephan Raabe (2023)
|
|
|
|
# -----------------------------------------------------
|
2023-09-12 09:13:41 -04:00
|
|
|
# Requires pacman-contrib trizen
|
2023-08-31 05:43:42 -04:00
|
|
|
|
2023-09-10 09:03:57 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Define threshholds for color indicators
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
|
|
threshhold_green=0
|
|
|
|
threshhold_yellow=25
|
|
|
|
threshhold_red=100
|
|
|
|
|
|
|
|
# -----------------------------------------------------
|
|
|
|
# Calculate available updates pacman and aur (with trizen)
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
2023-08-31 05:43:42 -04:00
|
|
|
if ! updates_arch=$(checkupdates 2> /dev/null | wc -l ); then
|
|
|
|
updates_arch=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
|
|
|
|
updates_aur=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
updates=$(("$updates_arch" + "$updates_aur"))
|
|
|
|
|
2023-09-10 09:03:57 -04:00
|
|
|
# -----------------------------------------------------
|
2023-09-13 05:20:50 -04:00
|
|
|
# Testing
|
2023-09-10 09:03:57 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
|
2023-09-13 05:20:50 -04:00
|
|
|
# Overwrite updates with numbers for testing
|
|
|
|
# updates=100
|
2023-09-10 09:03:57 -04:00
|
|
|
|
2023-09-13 05:20:50 -04:00
|
|
|
# test JSON output
|
2023-09-10 09:03:57 -04:00
|
|
|
# printf '{"text": "0", "alt": "0", "tooltip": "0 Updates", "class": "red"}'
|
|
|
|
# exit
|
|
|
|
|
2023-09-13 05:20:50 -04:00
|
|
|
# -----------------------------------------------------
|
|
|
|
# Output in JSON format for Waybar Module custom-updates
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
|
|
css_class="green"
|
|
|
|
|
2023-09-10 09:03:57 -04:00
|
|
|
if [ "$updates" -gt $threshhold_yellow ]; then
|
|
|
|
css_class="yellow"
|
2023-09-12 09:13:41 -04:00
|
|
|
fi
|
2023-09-13 05:20:50 -04:00
|
|
|
|
2023-09-12 09:13:41 -04:00
|
|
|
if [ "$updates" -gt $threshhold_red ]; then
|
2023-09-10 09:03:57 -04:00
|
|
|
css_class="red"
|
|
|
|
fi
|
2023-09-13 05:20:50 -04:00
|
|
|
|
2023-09-10 09:03:57 -04:00
|
|
|
if [ "$updates" -gt $threshhold_green ]; then
|
|
|
|
printf '{"text": "%s", "alt": "%s", "tooltip": "%s Updates", "class": "%s"}' "$updates" "$updates" "$updates" "$css_class"
|
2023-08-31 05:43:42 -04:00
|
|
|
else
|
2023-09-10 09:03:57 -04:00
|
|
|
printf '{"text": "0", "alt": "0", "tooltip": "0 Updates", "class": "green"}'
|
2023-08-31 05:43:42 -04:00
|
|
|
fi
|