changed waybar with backup
This commit is contained in:
@@ -1,86 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Check for available updates and optionally upgrade packages on Arch Linux.
|
||||
#
|
||||
# Requirements:
|
||||
# - checkupdates (pacman-contrib)
|
||||
# - notify-send (libnotify)
|
||||
# - optional: an AUR helper (aura, paru, pikaur, trizen, yay)
|
||||
#
|
||||
# Author: Jesse Mirabel <sejjymvm@gmail.com>
|
||||
# Created: August 16, 2025
|
||||
# License: MIT
|
||||
|
||||
# Check release
|
||||
if [ ! -f /etc/arch-release ]; then
|
||||
exit 0
|
||||
fi
|
||||
GRN='\033[1;32m'
|
||||
BLU='\033[1;34m'
|
||||
RST='\033[0m'
|
||||
|
||||
pkg_installed() {
|
||||
local pkg=$1
|
||||
TIMEOUT=5
|
||||
|
||||
if pacman -Qi "${pkg}" &>/dev/null; then
|
||||
return 0
|
||||
elif pacman -Qi "flatpak" &>/dev/null && flatpak info "${pkg}" &>/dev/null; then
|
||||
return 0
|
||||
elif command -v "${pkg}" &>/dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
check-updates() {
|
||||
repo=$(timeout $TIMEOUT checkupdates 2> /dev/null | wc -l)
|
||||
|
||||
if [[ -n $helper ]]; then
|
||||
aur=$(timeout $TIMEOUT "$helper" -Quaq 2> /dev/null | wc -l)
|
||||
fi
|
||||
}
|
||||
|
||||
get_aur_helper() {
|
||||
if pkg_installed yay; then
|
||||
aur_helper="yay"
|
||||
elif pkg_installed paru; then
|
||||
aur_helper="paru"
|
||||
fi
|
||||
update-packages() {
|
||||
printf '\n%bUpdating pacman packages...%b\n' "$BLU" "$RST"
|
||||
sudo pacman -Syu
|
||||
|
||||
printf '\n%bUpdating AUR packages...%b\n' "$BLU" "$RST"
|
||||
"$helper" -Syu
|
||||
|
||||
# use signal to update the module
|
||||
pkill -RTMIN+1 waybar
|
||||
|
||||
notify-send 'Update Complete' -i 'package-install'
|
||||
printf '\n%bUpdate Complete!%b\n' "$GRN" "$RST"
|
||||
read -rs -n 1 -p 'Press any key to exit...'
|
||||
}
|
||||
|
||||
get_aur_helper
|
||||
export -f pkg_installed
|
||||
display-module() {
|
||||
local tooltip="Official: $repo"
|
||||
|
||||
# Trigger upgrade
|
||||
if [ "$1" == "up" ]; then
|
||||
trap 'pkill -RTMIN+20 waybar' EXIT
|
||||
command="
|
||||
$0 upgrade
|
||||
${aur_helper} -Syu
|
||||
if pkg_installed flatpak; then flatpak update; fi
|
||||
printf '\n'
|
||||
read -n 1 -p 'Press any key to continue...'
|
||||
"
|
||||
kitty --title " System Update" sh -c "${command}"
|
||||
fi
|
||||
if [[ -n $helper ]]; then
|
||||
tooltip+="\nAUR($helper): $aur"
|
||||
fi
|
||||
|
||||
# Check for AUR updates
|
||||
if [ -n "$aur_helper" ]; then
|
||||
aur_updates=$(${aur_helper} -Qua | grep -c '^')
|
||||
else
|
||||
aur_updates=0
|
||||
fi
|
||||
local total=$((repo + aur))
|
||||
|
||||
# Check for official repository updates
|
||||
official_updates=$(
|
||||
(while pgrep -x checkupdates >/dev/null; do sleep 1; done)
|
||||
checkupdates | grep -c '^'
|
||||
)
|
||||
if ((total == 0)); then
|
||||
echo "{ \"text\": \"\", \"tooltip\": \"No updates available\" }"
|
||||
else
|
||||
echo "{ \"text\": \"\", \"tooltip\": \"$tooltip\" }"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check for Flatpak updates
|
||||
if pkg_installed flatpak; then
|
||||
flatpak_updates=$(flatpak remote-ls --updates | grep -c '^')
|
||||
else
|
||||
flatpak_updates=0
|
||||
fi
|
||||
main() {
|
||||
local arg=$1
|
||||
local helpers=(aura paru pikaur trizen yay)
|
||||
local bin
|
||||
|
||||
# Calculate total available updates
|
||||
total_updates=$((official_updates + aur_updates + flatpak_updates))
|
||||
bin=$(command -v "${helpers[@]}" | head -n 1)
|
||||
helper=${bin##*/}
|
||||
repo=0
|
||||
aur=0
|
||||
|
||||
# Handle formatting based on AUR helper
|
||||
if [ "$aur_helper" == "yay" ]; then
|
||||
[ "${1}" == upgrade ] && printf "Official: %-10s\nAUR ($aur_helper): %-10s\nFlatpak: %-10s\n\n" "$official_updates" "$aur_updates" "$flatpak_updates" && exit
|
||||
case $arg in
|
||||
'module')
|
||||
check-updates
|
||||
display-module
|
||||
;;
|
||||
*)
|
||||
printf '%bChecking for updates...%b' "$BLU" "$RST"
|
||||
check-updates
|
||||
update-packages
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
tooltip="Official: $official_updates\nAUR ($aur_helper): $aur_updates\nFlatpak: $flatpak_updates"
|
||||
|
||||
elif [ "$aur_helper" == "paru" ]; then
|
||||
[ "${1}" == upgrade ] && printf "Official: %-10s\nAUR ($aur_helper): %-10s\nFlatpak: %-10s\n\n" "$official_updates" "$aur_updates" "$flatpak_updates" && exit
|
||||
|
||||
tooltip="Official: $official_updates\nAUR ($aur_helper): $aur_updates\nFlatpak: $flatpak_updates"
|
||||
fi
|
||||
|
||||
# Module and tooltip
|
||||
if [ $total_updates -eq 0 ]; then
|
||||
echo "{\"text\":\"\", \"tooltip\":\"Packages are up to date\"}"
|
||||
else
|
||||
echo "{\"text\":\"\", \"tooltip\":\"${tooltip//\"/\\\"}\"}"
|
||||
fi
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user