Random question: How often do you update your packages?

I can see I bugged with the regex - it should have been

reboot="(ucode|cryptsetup|linux|nvidia|mesa|systemd|wayland|xf86-video|xorg)"

Then this check

[[ $updates =~ "$reboot" ]]

I tested with https://regex101.com/r/A5wv9k/1 - and I can’t see why bash won’t parse it.


Edit got it … never quote the regex :man_facepalming:

#!/usr/bin/env bash
reboot="(ucode|cryptsetup|linux|nvidia|mesa|systemd|wayland|xf86-video|xorg)"
updates=$(checkupdates)
echo "$updates"
if [[ $updates =~ $reboot ]]; then
    echo "Needs reboot .."
fi

Your function

cu() { # check for updates, needs "pacman-contrib" and "yay"
  local UPDATES=$(checkupdates; yay -Qua)
  [[ "$UPDATES" == "" ]] && return 2 || echo "$UPDATES" 
  # assume packages containing these strings in name need reboot after updating
  local REBOOT="(ucode|cryptsetup|linux|nvidia|mesa|systemd|wayland|xf86-video|xorg)"
  if [[ $UPDATES =~ $REBOOT ]]; then
    echo -n "\nWarning: reboot after updating, just in case.\n"
    return 1
  fi
  return 0
}

2020-08-25T06:50:00Z EDIT: Refactored to work if yay is not installed

#!/usr/bin/env bash
reboot="(ucode|cryptsetup|linux|nvidia|mesa|systemd|wayland|xf86-video|xorg)"
if [[ $(which yay) =~ (yay) ]]; then
    updates=$(checkupdates; yay -Qua)
else
    updates=$(checkupdates)
fi
echo "$updates"
if [[ $updates =~ $reboot ]]; then
    echo "Updating possibly requires system restart ..."
fi

Cross posted to Manjaro Forum

1 Like