#!/usr/bin/env bash # Check release if [ ! -f /etc/arch-release ]; then exit 0 fi pkg_installed() { local pkg=$1 if pacman -Qi "${pkg}" &>/dev/null; then return 0 elif command -v "${pkg}" &>/dev/null; then return 0 else return 1 fi } get_aur_helper() { if command -v yay &>/dev/null; then aur_helper="yay" elif command -v paru &>/dev/null; then aur_helper="paru" else aur_helper="" fi } get_aur_helper # Trigger upgrade if [ "$1" == "up" ]; then trap 'pkill -RTMIN+20 waybar' EXIT command=" echo 'Starting system update...' $0 upgrade if [ -n '$aur_helper' ]; then echo 'Running AUR update with $aur_helper...' $aur_helper -Syu else echo 'Running official repository update...' sudo pacman -Syu fi if command -v flatpak &>/dev/null; then echo 'Running Flatpak update...' flatpak update -y fi echo '' echo 'Update complete! Press Enter to close...' read -r " ghostty -e bash -c "${command}" exit 0 fi # Check for official repository updates with timeout official_updates=$( (timeout 10 bash -c 'while pgrep -x checkupdates >/dev/null; do sleep 1; done') 2>/dev/null checkupdates 2>/dev/null | wc -l ) official_updates=$((official_updates + 0)) # Check for AUR updates with timeout if [ -n "$aur_helper" ]; then aur_updates=$(timeout 10 $aur_helper -Qua 2>/dev/null | wc -l) aur_updates=$((aur_updates + 0)) else aur_updates=0 fi # Check for Flatpak updates with timeout if pkg_installed flatpak; then flatpak_updates=$(timeout 10 flatpak remote-ls --updates 2>/dev/null | wc -l) flatpak_updates=$((flatpak_updates + 0)) else flatpak_updates=0 fi # Calculate total available updates total_updates=$((official_updates + aur_updates + flatpak_updates)) # Handle upgrade info display if [ "${1}" == "upgrade" ]; then if [ "$aur_helper" == "yay" ]; then printf "Official: %s\nAUR ($aur_helper): %s\nFlatpak: %s\n\n" "$official_updates" "$aur_updates" "$flatpak_updates" elif [ "$aur_helper" == "paru" ]; then printf "Official: %s\nAUR ($aur_helper): %s\nFlatpak: %s\n\n" "$official_updates" "$aur_updates" "$flatpak_updates" else printf "Official: %s\nFlatpak: %s\n\n" "$official_updates" "$flatpak_updates" fi exit 0 fi # Create tooltip text if [ "$aur_helper" == "yay" ]; then tooltip="Official: $official_updates\nAUR ($aur_helper): $aur_updates\nFlatpak: $flatpak_updates" elif [ "$aur_helper" == "paru" ]; then tooltip="Official: $official_updates\nAUR ($aur_helper): $aur_updates\nFlatpak: $flatpak_updates" else tooltip="Official: $official_updates\nFlatpak: $flatpak_updates" fi # Output compact JSON for Waybar if [ $total_updates -eq 0 ]; then echo '{"text":"󰸟","tooltip":"Packages are up to date"}' else printf '{"text":" %s","tooltip":"%s"}\n' "$total_updates" "$tooltip" fi