dotfiles/home/private_bin/executable_get-updates

78 lines
1.3 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
}
2022-08-13 14:40:50 -05:00
header() {
2022-08-15 13:01:58 -05:00
echo "============="
2022-08-13 14:40:50 -05:00
}
2022-06-13 12:25:29 -05:00
updates_output() {
2022-06-15 14:28:16 -05:00
notify=$1
2022-11-14 11:40:05 -06:00
if [[ -n $updates_arch ]]; then
2022-08-15 13:01:58 -05:00
header
2022-06-15 14:28:16 -05:00
echo "ARCH: $(echo "$updates_arch" | wc -l)"
2022-08-15 13:01:58 -05:00
header
2022-06-15 14:28:16 -05:00
[[ -z $notify ]] && echo "$updates_arch"
fi
2022-11-14 11:40:05 -06:00
if [[ -n $updates_aur ]]; then
2022-08-15 13:01:58 -05:00
header
2022-06-15 14:28:16 -05:00
echo "AUR: $(echo "$updates_aur" | wc -l)"
2022-08-15 13:01:58 -05:00
header
2022-06-15 14:28:16 -05:00
[[ -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() {
2022-08-15 13:01:58 -05:00
echo
2022-11-14 11:40:05 -06:00
read -r -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
;;
2022-11-14 11:40:05 -06:00
-*)
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..."
2022-08-13 14:40:50 -05:00
echo
2022-06-15 14:28:16 -05:00
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
2022-11-14 11:40:05 -06:00
if [[ -n $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-11-14 11:40:05 -06:00
echo "nystem Updates Available!"
2022-06-15 14:28:16 -05:00
echo "$updates_info"
update_system
2022-06-13 12:25:29 -05:00
fi