Yet another simple system updater (CLI)

Hi all!

Here’s a tiny terminal based EndeavourOS software updater for those that are a bit unsure how it should be done.
It updates packages from Arch and EndeavourOS repos, and AUR packages.
It also checks that you have an internet connection.

The script

#!/bin/bash
#
# EndeavourOS software tiny updater.
# - Verifies internet connection.
# - Installs official updates.
# - If no official updates, installs AUR updates.
#

DIE() { echo "Error: $1" >&2 ; exit 1 ; }

Main() {
    echo "Connection check..."
    eos-connection-checker || DIE "internet connection problem!"

    echo "Official updates..."
    checkupdates && { sudo pacman -Syu ; return ; }

    echo "AUR updates..."
    local aurHelper=yay
    [ -x /usr/bin/paru ] && aurHelper=paru  # for 'paru' users!
    local updates=$($aurHelper -Qua)
    [ -n "$updates" ] && $aurHelper -Sua
}

Main

Install

Simply copy the script above e.g. into file /usr/local/bin/U and make it executable (all under sudo or su):

  sudo nano /usr/local/bin/U      # may use another editor as well
  sudo chmod +x /usr/local/bin/U

Usage

To update your system in terminal, give command: U

Some details

Note that it separates “official” and AUR updates. So if there are official updates, you’ll have to run U another time for updating your AUR packages.

AUR updates are handled by an AUR helper called yay. However, another AUR helper paru will be used if you have it installed.

5 Likes

Here’s the output when all is already updated (with timing too!):

$ time U
Connection check...
Official updates...
AUR updates...

real   0m2,378s
user   0m0,597s
sys    0m0,092s
$
2 Likes

Topgrade is your friend, it updates and upgrades EVERYTHING.

Is the comment true?

Doesn’t it install official updates if available and then install AUR updates if available?

FWIW:

2 Likes

I use topgrade, and it works really well other than if there’s a bunch of updates and walk away while updating, must if the time i come back to find it stopped at some point to ask for my password again and didn’t finish. I usually have to run it at least two, maybe 3x before I’m done. It is nice it checks firmware though.

I like the general idea, but it does look like the implementation’s end result is no different to just running yay or paru ?

For example:

This runs checkupdates, and if there are no updates skips an update, otherwise run an update if there are updates. This is the same end result as just running pacman -Syu.

Same thing again, but for the AUR helper: run an update if there are updates.

Taken together, running yay will end up with the same end result: update packages if there are updates available.

1 Like

I believe @manuel is simply supplying new users (and those not that script savy) a way of updating all via a simple input of a U. It also uses the proper way of checking for updates via checkupdates. This may also encourage new users to examine the script, see how it works, and then apply what they have learned to writing their own scripts for such purposes.
I agree yay will return very similar results. As far as topgrade is concerned I would rather run a simple script then load in yet another aur package I would have to check the pkbuild of to see if I want it on my system.

The only thing I would say is that using checkupdates is only useful if you want to check without running updates. If you are going to immediately follow it with updating the system I am not sure it is doing anything except consuming bandwidth.

3 Likes

Sure, and as I say, I like the general idea.

However:

  • U is not much shorter than yay (minor point), and
  • using checkupdates in this context is not more correct than just running pacman -Syu.

checkupdates is there to check for updates without altering the package list. Immediately following it with pacman -Syu means there is no reason for using checkupdates; that is, if you update as soon as there are updates then there’s no reason to use checkupdates to check for updates!

7 Likes

Beauty of arch always more than one way to do something. Most of this has been discussed here:

Very good information in there.

2 Likes

$ topgrade

Once topgrade is invoked, it will perform the following tasks one by one depending upon the OS you use. You will be asked to enter root/sudo user password wherever necessary.

On Linux:

  1. Run your Linux system’s package manager and do the following operations:
  • Arch based: Run yay or fall back to pacman
  • Redhat based: Run yum upgrade (or dnf if present)
  • Debian based: Run apt update && apt dist-upgrade
  • Gentoo: Run layman -s ALL && emerge --sync -q && eix-update && emerge -uDNa world
  • openSUSE: Run zypper refresh && zypper dist-upgrade
  • Void: Run xbps-install -Su

source: https://ostechnix.com/how-to-upgrade-everything-using-a-single-command-in-linux/

I don’t get the point of using topgrade if it will invoke yay on Arch based systems. Or am I missing somerhing?

1 Like

Yes.

No (unless I made a typo…). If official updates are available, it installs them and stops. In that case updating AUR packages needs another run of U.

Almost, but this implementation does not ask for password if there are no updates available.
If you run sudo pacman -Syu or yay or paru, it will usually ask for password.

This only avoids some extra output when there are no updates available. One could run only

  $aurHelper -Sua

as well if the extra output doesn’t bother in case when no updates are available.

Out of curiosity, why would anyone want that behavior?

It can create some really odd situations where you have to run it a variable number of times to actually get all your packages updated.

You could run updates and when you try to run it again there could be additional updates so the second run wouldn’t update the AUR packages but the repo packages again.

Basically, when you run it, you don’t actually know what it is going to do until runtime.

Because updating official packages fully before updating (potentially unsafe) AUR stuff helps keeping system in order.

I don’t think there would ever be more than two consecutive runs. First the official packages (and possible reboot), then the AUR packages (if you have any).

Even if that would happen, what’s the problem? Always official packages first.

Please explain.

That would be true even if you did them one after another in the same run.

It will be more than two if additional updates come in while the first set of updates are running. Given that Arch updates aren’t really batched together this isn’t an unthinkable scenario.

Basically, before you run it you don’t know if it will update repo packages or AUR packages.

I would say simply typing yay is both more efficient and far simpler for a new user.

Having to put in your password even if there are no updates seems like a small price to pay in return. Especially on a system which will likely have updates every day.

That’s what checkupdates if for. If there are no repo it will go to aur.

Yes but arguably riskier. Lastly the threat of an update coming down the pipe at the same time you are updating is true for any method you use.

:man_shrugging:

I understand what it does but a utility that does something different each time you run it is not intuitive.

Please describe a situation in which it is riskier.

But normally it wouldn’t matter. Sure there might be an update after you are done but it would still update the repos and then AUR.

I never questioned your understanding. So what you are saying is a package included in the base arch install is not intuitive. Neither is the wiki welcome to arch :crazy_face:

Read through the thread I linked.