dotfiles/home/private_bin/executable_get-updates

68 lines
1.2 KiB
Text
Raw Normal View History

2022-06-13 12:25:29 -05:00
#!/usr/bin/env bash
usage() {
cat <<HELP
get-updates [option]
--notify send a notification with available packages
-h,--help print this page and exit
HELP
exit 0
}
updates_output() {
2022-06-15 14:28:16 -05:00
notify=$1
if ! [[ -z $updates_arch ]]; then
echo "ARCH: $(echo "$updates_arch" | wc -l)"
[[ -z $notify ]] && echo "$updates_arch"
fi
if ! [[ -z $updates_aur ]]; then
echo "AUR: $(echo "$updates_aur" | wc -l)"
[[ -z $notify ]] && echo "$updates_aur"
fi
echo
2022-06-13 12:25:29 -05:00
}
2022-06-15 14:28:16 -05:00
update_system() {
read -p "Would you like to update? (y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
2022-07-18 10:39:03 -05:00
pikaur -Syu --noedit --nodiff
2022-06-15 14:28:16 -05:00
}
2022-06-13 12:25:29 -05:00
for opt in "$@"; do
case $opt in
-h | --help)
usage
;;
--notify)
2022-06-15 14:28:16 -05:00
notify=1
shift
2022-06-13 12:25:29 -05:00
;;
-* | --*)
echo "Invalid option: $opt"
usage
exit 1
;;
esac
done
2022-06-15 14:28:16 -05:00
echo "fetching updates..."
updates_arch="$(checkupdates 2>/dev/null | awk '{print $1}')"
updates_aur="$(pikaur -Qua 2>/dev/null | awk '{print $1}')"
2022-06-13 12:25:29 -05:00
updates_info="$(updates_output $notify)"
2022-06-15 14:28:16 -05:00
if [[ -z $updates_info ]]; then
echo "system up to date"
exit 0
2022-06-13 12:25:29 -05:00
fi
if ! [[ -z $notify ]]; then
2022-06-15 14:28:16 -05:00
notify-send -w "System Updates Available!" "$updates_info"
2022-06-13 12:25:29 -05:00
else
2022-06-15 14:28:16 -05:00
echo "System Updates Available!"
echo "$updates_info"
update_system
2022-06-13 12:25:29 -05:00
fi