show_updates.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "$amount_updates\n$updates")
  13. fi
  14. if [[ $amount_updates -lt 31 ]]; then
  15. notify-send -i software-update-available "Updates: $updates_output"
  16. else
  17. $terminal --hold -e echo "Updates: $updates_output"
  18. # --hold option exists for terminals: alacritty, xfce4-terminal
  19. fi
  20. }
  21. show_updates_arch() {
  22. # Show updates for Arch Linux.
  23. amount_updates=0
  24. # Check community and AUR repos.
  25. updates_community=$(checkupdates)
  26. updates_aur=$(yay -Q -u -a)
  27. if [[ -z "$updates_community" ]]; then
  28. community_output=
  29. else
  30. updates_community_count=$(echo "$updates_community" | wc -l)
  31. community_output=$(echo -e "\n\nCommunity: $updates_community_count\n$updates_community")
  32. let "amount_updates += $updates_community_count"
  33. fi
  34. if [[ -z "$updates_aur" ]]; then
  35. aur_output=
  36. else
  37. updates_aur_count=$(echo "$updates_aur" | wc -l)
  38. aur_output=$(echo -e "\n\nAUR: $updates_aur_count\n$updates_aur")
  39. let "amount_updates += $updates_aur_count"
  40. fi
  41. if [[ $amount_updates -lt 31 ]]; then
  42. notify-send -i software-update-available "Updates: $amount_updates $community_output $aur_output"
  43. else
  44. $terminal --hold -e echo "Updates: $amount_updates $community_output $aur_output"
  45. # --hold option exists for terminals: alacritty, xfce4-terminal
  46. fi
  47. }
  48. show_updates_void() {
  49. # Show updates for Void Linux.
  50. updates=$(xbps-install -nuMS)
  51. if [[ -z "$updates" ]]; then
  52. updates_output=
  53. else
  54. amount_updates=$(echo "$updates" | wc -l)
  55. updates_output=$(echo -e "$amount_updates\n\n$updates" | awk '{print $1}')
  56. fi
  57. if [[ $amount_updates -lt 31 ]]; then
  58. notify-send -i software-update-available "Updates: $updates_output"
  59. else
  60. $terminal --hold -e echo "Updates: $updates_output"
  61. # --hold option exists for terminals: alacritty, xfce4-terminal
  62. fi
  63. }
  64. terminal="alacritty"
  65. distro=$(lsb_release -a 2>/dev/null | grep -i 'distributor id' | awk '{print $3}')
  66. case $distro in
  67. "Debian") show_updates_debian;;
  68. "Arch"|"ManjaroLinux") show_updates_arch;;
  69. "VoidLinux") show_updates_void;;
  70. *) notify-send -i dialog-error "Error:" "Unknown distro $distro.";;
  71. esac
  72. exit 0