Zuletzt aktiv 2 months ago

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

update-checker.sh Originalformat
1#!/bin/bash
2
3LIST_UPDATES_FOR="all"
4
5get-base-updates() {
6 pacman -Qu | wc -l
7}
8
9get-aur-updates() {
10 base=$(get-base-updates)
11 all=$(yay -Qu | wc -l)
12 echo $(( ${all} - ${base} ))
13}
14
15usage() {
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
36PARSED_ARGS=$(getopt -o bah -- "$@")
37VALID_ARGS=$?
38if [ "$VALID_ARGS" != 0 ]; then
39 usage 1
40fi
41
42eval set -- "$PARSED_ARGS"
43PRINT_USAGE=0
44
45while :
46do
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
79done
80
81case $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"
93esac
94