Last active 2 months ago

Simple script to check for number of updates for use with polybar

totori revised this gist 2 months ago. Go to revision

No changes

totori revised this gist 2 months ago. Go to revision

1 file changed, 93 insertions

update-checker.sh(file created)

@@ -0,0 +1,93 @@
1 + #!/bin/bash
2 +
3 + LIST_UPDATES_FOR="all"
4 +
5 + get-base-updates() {
6 + pacman -Qu | wc -l
7 + }
8 +
9 + get-aur-updates() {
10 + base=$(get-base-updates)
11 + all=$(yay -Qu | wc -l)
12 + echo $(( ${all} - ${base} ))
13 + }
14 +
15 + usage() {
16 + exitcode=0
17 +
18 + if [ $1 != "" ]; then
19 + exitcode=$1
20 + fi
21 +
22 + echo "USAGE: update-checker.sh [ flag ]"
23 + echo "DESCRIPTION:"
24 + echo "Returns the number of packages available for update."
25 + echo "If no flag is provided, both base and aur package update"
26 + echo "values will be returned."
27 + echo ""
28 + echo "FLAGS"
29 + echo "-b pacman repository packages only"
30 + echo "-a aur packages only"
31 + echo "-h print this message"
32 +
33 + exit $exitcode
34 + }
35 +
36 + PARSED_ARGS=$(getopt -o bah -- "$@")
37 + VALID_ARGS=$?
38 + if [ "$VALID_ARGS" != 0 ]; then
39 + usage 1
40 + fi
41 +
42 + eval set -- "$PARSED_ARGS"
43 + PRINT_USAGE=0
44 +
45 + while :
46 + do
47 + case $1 in
48 + -b)
49 + if [ "$LIST_UPDATES_FOR" != "all" ]; then
50 + echo "ERROR: invalid flag combination used, must be either -a OR -b, not both"
51 + usage 1
52 + fi
53 +
54 + LIST_UPDATES_FOR="base"
55 + shift
56 + ;;
57 + -a)
58 + if [ "$LIST_UPDATES_FOR" != "all" ]; then
59 + echo "ERROR: invalid flag combination used, must be either -a OR -b, not both"
60 + echo ""
61 + usage 1
62 + fi
63 +
64 + LIST_UPDATES_FOR="aur"
65 + shift
66 + ;;
67 + -h)
68 + usage
69 + ;;
70 + --)
71 + shift
72 + break
73 + ;;
74 + *)
75 + echo "invalid option $1"
76 + usage 1
77 + ;;
78 + esac
79 + done
80 +
81 + case $LIST_UPDATES_FOR in
82 + aur)
83 + get-aur-updates
84 + ;;
85 + base)
86 + get-base-updates
87 + ;;
88 + all)
89 + base=$(get-base-updates)
90 + aur=$(get-aur-updates)
91 + echo "base: $base"
92 + echo "aur: $aur"
93 + esac
Newer Older