1
0
Fork 0
dotfiles/.local/bin/cron/checkup

36 lines
1 KiB
Text
Raw Normal View History

2022-07-04 21:36:33 +02:00
#!/bin/sh
# Syncs repositories and downloads updates, meant to be run as a cronjob.
notify-send " Repository Sync" "Checking for package updates..."
2023-02-20 12:23:39 +01:00
askupgrade() {
[ "$(notify-send -c updates --action=Yes=Yes --action=No=No " Repository Sync" "Updates available. Update now?")" = 'Yes' ] && $TERMINAL -e upgrades
}
2022-07-04 21:36:33 +02:00
2023-02-20 12:23:39 +01:00
confirmcheck() {
notify-send " Repository Sync" "Sync complete. No new packages for update."
}
failcheck() {
notify-send "Error downloading updates." "Check your internet connection, if $1 is already running, or run update manually to see errors."
}
if command -v pacman 1>/dev/null 2>&1; then
sudo pacman -Syyuw --noconfirm || failcheck pacman
2023-02-16 18:59:33 +01:00
if pacman -Qu | grep -v "\[ignored\]"; then
2023-02-20 12:23:39 +01:00
askupgrade
2023-02-16 18:59:33 +01:00
else
2023-02-20 12:23:39 +01:00
confirmcheck
2023-02-16 18:59:33 +01:00
fi
2023-02-20 12:23:39 +01:00
elif command -v apt 1>/dev/null 2>&1; then
2023-02-16 18:59:33 +01:00
n=$(sudo apt upgrade -dy 2>/dev/null | grep -m1 '^[0-9]\+ upgraded,' | tr -cd '0-9' | cut -c1-2)
if [ "$n" = '' ]; then
2023-02-20 12:23:39 +01:00
failcheck apt
2023-02-16 18:59:33 +01:00
elif [ "$n" = 00 ]; then
2023-02-20 12:23:39 +01:00
confirmcheck
2023-02-16 18:59:33 +01:00
else
2023-02-20 12:23:39 +01:00
askupgrade
2023-02-16 18:59:33 +01:00
fi
2022-07-04 21:36:33 +02:00
fi