update-notifier/pacman-update-count.sh

28 lines
706 B
Bash
Executable File

#!/bin/sh
_updates_available="0"
_target_file="/tmp/pacman-update-count"
_user="ray"
_user_id=$(id -u)
if ! [ "$_user_id" -eq 0 ] ; then
echo "pacman-update-count.sh: insufficient priviliges: must be run as root"
exit 1
fi
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
echo "Adding $_updates_available available updates to $_target_file"
echo "$_updates_available" > "$_target_file"
chown "$_user": "$_target_file"