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

44 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
# Syncs repositories and downloads updates, meant to be run as a cronjob.
notify-send " Repository Sync" "Checking for package updates..."
askupgrade() {
[ "$(notify-send -c updates --action=Yes=Yes --action=No=No " Repository Sync" "Updates available. Update now?")" = 'Yes' ] && $TERMINAL -e upgrades
}
confirmcheck() {
notify-send " Repository Sync" "Sync complete. No new packages for update."
}
if command -v pacman 1>/dev/null 2>&1; then
sudo pacman -Syyuw --noconfirm || notify-send "Error downloading updates." "Check your internet connection, if pacman is already running, or run update manually to see errors."
if pacman -Qu | grep -v "\[ignored\]"; then
askupgrade
else
confirmcheck
fi
elif command -v apt 1>/dev/null 2>&1; then
n=$(sudo apt upgrade -dy 2>/dev/null | grep -m1 '^[0-9]\+ upgraded,' | tr -cd '0-9' | cut -c1-2)
if [ "$n" = '' ]; then
notify-send "Error downloading updates." "Check your internet connection, if apt is already running, or run update manually to see errors."
elif [ "$n" = 00 ]; then
confirmcheck
else
askupgrade
fi
elif command -v xbps-install 1>/dev/null 2>&1; then
xbps-install -nuM 1>/tmp/xbps_updates 2>/tmp/xbps_errors
n="$(wc -l < /tmp/xbps_updates)"
ne="$(grep broken /tmp/xbps_errors | wc -l)"
n="$(xbps-install -M -n -u | grep -Fe update -e install | wc -l)"
if [ "$n" = "0" ] && [ "$ne" = "0" ]; then
confirmcheck
elif [ "$n" -gt 1 ] && [ "$ne" = "0" ]; then
askupgrade
else
notify-send "Error downloading updates." "$(cut -d " " -f 1,5 /tmp/xbps_errors)"
fi
fi