From bdb4a90fa300366031d0d52b289ecc47f6289196 Mon Sep 17 00:00:00 2001 From: ray Date: Mon, 17 Feb 2020 15:25:00 +0000 Subject: [PATCH] count number of packages require updates --- pacman-update-count.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pacman-update-count.sh b/pacman-update-count.sh index 5019783..183dd10 100755 --- a/pacman-update-count.sh +++ b/pacman-update-count.sh @@ -1,6 +1,8 @@ #!/bin/sh -_updates_available="0" +set -e + +_updates_available="-1" _target_file="/tmp/pacman-update-count" _user="ray" _user_id=$(id -u) @@ -10,17 +12,12 @@ if ! [ "$_user_id" -eq 0 ] ; then exit 1 fi +touch "$_target_file" +chown root: "$_target_file" +echo "$_updates_available" > "$_target_file" + pacman -Sy -_query_output=$(pacman -Qu) - -# 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 +_updates_available=$(pacman -Qu | wc -l) echo "Adding $_updates_available available updates to $_target_file" echo "$_updates_available" > "$_target_file"