show_updates.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. ###################################################
  3. # Shows available updates for Arch or Debian Linux.
  4. ###################################################
  5. show_updates_debian() {
  6. # Show updates for Debian Linux.
  7. updates=$(apt-show-versions -u -b)
  8. if [[ -z "$updates" ]]; then
  9. updates_output=
  10. else
  11. amount_updates=$(echo "$updates" | wc -l)
  12. updates_output=$(echo -e "Updates: $amount_updates\n$updates")
  13. fi
  14. notify-send -i software-update-available "Updates: $updates_output"
  15. }
  16. show_updates_arch() {
  17. # Show updates for Arch Linux.
  18. amount_updates=0
  19. # Check community and AUR repos.
  20. updates_community=$(checkupdates)
  21. updates_aur=$(yay -Q -u -a)
  22. if [[ -z "$updates_community" ]]; then
  23. community_output=
  24. else
  25. updates_community_count=$(echo "$updates_community" | wc -l)
  26. community_output=$(echo -e "\n\nCommunity: $updates_community_count\n$updates_community")
  27. let "amount_updates += $updates_community_count"
  28. fi
  29. if [[ -z "$updates_aur" ]]; then
  30. aur_output=
  31. else
  32. updates_aur_count=$(echo "$updates_aur" | wc -l)
  33. aur_output=$(echo -e "\n\nAUR: $updates_aur_count\n$updates_aur")
  34. let "amount_updates += $updates_aur_count"
  35. fi
  36. if [[ $amount_updates -lt 31 ]]; then
  37. notify-send -i software-update-available "Updates: $amount_updates $community_output $aur_output"
  38. else
  39. $terminal --hold -e echo "Updates: $amount_updates $community_output $aur_output"
  40. # --hold option exists for terminals: alacritty, xfce4-terminal
  41. fi
  42. }
  43. terminal="alacritty"
  44. distro=$(lsb_release -a 2>/dev/null | grep -i 'distributor id' | awk '{print $3}')
  45. case $distro in
  46. "Debian") show_updates_debian;;
  47. "Arch"|"ManjaroLinux") show_updates_arch;;
  48. *) notify-send -i dialog-error "Error:" "Unknown distro $distro.";;
  49. esac
  50. exit 0