dotfiles/home/private_bin/executable_get-updates

77 lines
1.3 KiB
Text
Raw Permalink 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
2023-09-26 11:53:27 -05:00
paru -Syu
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
;;
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
2023-11-07 09:41:59 -06:00
updates_arch="$(checkupdates 2>/dev/null | awk '{print $1}' | column)"
updates_aur="$(paru -Qua 2>/dev/null | awk '{print $1}' | column)"
updates_info="$(updates_output "$notify")"
2022-06-13 12:25:29 -05:00
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
2023-01-07 10:41:44 -06:00
notify-send -w "System Updates Available!" "$updates_info" &
2022-06-13 12:25:29 -05:00
else
2023-01-07 10:41:44 -06:00
echo "System Updates Available!"
2022-06-15 14:28:16 -05:00
echo "$updates_info"
update_system
2022-06-13 12:25:29 -05:00
fi