count number of packages require updates

This commit is contained in:
ray 2020-02-17 15:25:00 +00:00
parent fa471fdf9f
commit bdb4a90fa3
1 changed files with 8 additions and 11 deletions

View File

@ -1,6 +1,8 @@
#!/bin/sh #!/bin/sh
_updates_available="0" set -e
_updates_available="-1"
_target_file="/tmp/pacman-update-count" _target_file="/tmp/pacman-update-count"
_user="ray" _user="ray"
_user_id=$(id -u) _user_id=$(id -u)
@ -10,17 +12,12 @@ if ! [ "$_user_id" -eq 0 ] ; then
exit 1 exit 1
fi fi
touch "$_target_file"
chown root: "$_target_file"
echo "$_updates_available" > "$_target_file"
pacman -Sy pacman -Sy
_query_output=$(pacman -Qu) _updates_available=$(pacman -Qu | wc -l)
# TODO - get update count from above
echo "$_query_output"
# check $_updates_available is algebraically equal to itself (i.e., is a number)
# https://unix.stackexchange.com/a/151655
if ! [ "$_updates_available" -eq "$_updates_available" ] 2> /dev/null ; then
_updates_available="-1"
fi
echo "Adding $_updates_available available updates to $_target_file" echo "Adding $_updates_available available updates to $_target_file"
echo "$_updates_available" > "$_target_file" echo "$_updates_available" > "$_target_file"