d0tfiles

*nix dotfiles for arch linux setup
Log | Files | Refs | README | LICENSE

updates.sh (1398B)


      1 #!/usr/bin/env bash
      2 
      3 BAR_ICON=""
      4 NOTIFY_ICON=/usr/share/icons/Papirus/32x32/apps/system-software-update.svg
      5 
      6 get_total_updates() { UPDATES=$(checkupdates 2>/dev/null | wc -l); }
      7 
      8 while true; do
      9     get_total_updates
     10 
     11     # notify user of updates
     12     if hash notify-send &>/dev/null; then
     13         if (( UPDATES > 50 )); then
     14             notify-send -u critical -i $NOTIFY_ICON \
     15                 "You really need to update!!" "$UPDATES New packages"
     16         elif (( UPDATES > 25 )); then
     17             notify-send -u normal -i $NOTIFY_ICON \
     18                 "You should update soon" "$UPDATES New packages"
     19         elif (( UPDATES > 2 )); then
     20             notify-send -u low -i $NOTIFY_ICON \
     21                 "$UPDATES New packages"
     22         fi
     23     fi
     24 
     25     # when there are updates available
     26     # every 10 seconds another check for updates is done
     27     while (( UPDATES > 0 )); do
     28         if (( UPDATES == 1 )); then
     29             echo " $UPDATES Update"
     30         elif (( UPDATES > 1 )); then
     31             echo " $UPDATES Updates"
     32         else
     33             echo $BAR_ICON
     34         fi
     35         sleep 10
     36         get_total_updates
     37     done
     38 
     39     # when no updates are available, use a longer loop, this saves on CPU
     40     # and network uptime, only checking once every 30 min for new updates
     41     while (( UPDATES == 0 )); do
     42         echo $BAR_ICON
     43         sleep 1800
     44         get_total_updates
     45     done
     46 done