#!/bin/bash

if [ "$#" -eq 1 ]; then
    threshold=$1
else
    threshold=30
fi

arch_updates=$(checkupdates | wc -l)
aur_updates=$(aur repo -u -d aur-local | wc -l)
kernel_update=$(checkupdates | grep linux | grep -v custom | grep -v archlinux | grep -v api | grep -v firmware | wc -l)
built_kernel=$(checkupdates | grep linux-custom | wc -l)

updates=$(($arch_updates + $aur_updates))

if [ "$kernel_update" -ge 1 ] && [ "$built_kernel" -eq 0 ]; then
    notify-send "Kernel update available" "Rebuild custom kernel"
fi

if [ "$updates" -ge "$threshold" ]; then
    notify-send "Updates available" "Arch: $arch_updates, AUR: $aur_updates"
fi
