BASH. Parallel uninteractive update script. Flatpak Pacman AUR Yay

Context current shell script:

[v1n1@ttt ~]$ echo $PATH
~/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/home/v1n1/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin:/home/v1n1/.dotnet/tools
[v1n1@ttt ~]$ cat ~/bin/update
#!/bin/sh

[[ "$(id -u)" -ne 0 ]] && sudo $0 && exit # Ask for sudo on-demand

flatpak update --noninteractive 2>&1> /tmp/user-update-flatpak.log & \
    echo "==Pacman===========================================================================================" && \
    sudo pacman -Syu --noconfirm --color always && \
    echo "==Yay==============================================================================================" && \
    yay --noconfirm
    echo "==Flatpak=========================================================================================="

wait
cat /tmp/user-update-flatpak.log
rm /tmp/user-update-flatpak.log

Maybe there are better way than storing it to /tmp/user-update-flatpak.log and then removing it ?

Since you are dumping it to the screen anyway, couldn’t you just not redirect it at all?

I want to run flatpak update parallel to pacman+yay sequential execution. Because they can execute parallel. Faster update with parallel execution.

If I simply dump all flatpak parallel execution output to screen, then it mixes up with pacman+yay output. Results to unorganized output mess.

I don’t think so. But you could remove the pacman call, because yay will do the same again.

Yes, I know. But I want to update pacman packages first before any AUR packages are touched. Because AUR packages are more prune to update errors, at least pacman packages will be updated guarrantee this way. There have been cases when YAY could not update packages, but PACMAN could. So I don’t care if both commands will check pacman.db twice for the sake of it.

Anyways that’s off-topic.

That should always be the case if you update via yay, AFAIK. But there is nothing wrong with using a log file. I don’t think you can make that any better if you want the output to be displayed properly.

I was thinking about using temporary sockets/stream/pipeline or shell variable. Not sure yet how to make it.

I would argue that it’s overkill for such a simple task. You want the information and you get it this way without any hassle. You could even omit deleting the log file, because it gets deleted anyway inside the /tmp folder.

But if you find another way, keep us updated.

You could do it in a variety of ways. If /tmp is mounted on a tmpfs, I am not sure they would actually add any value though. A tmpfs is already in memory.

Well, the main difference between file output and collective stream output would be that I would not use wait command anymore. And would output already collected stream data to screen and the rest that comes after, in a live manner.

File output method I’m currently using, need to wait for flatpak to finish fully and only then outputs snapshot of what has happenned in all that time. No live outputing of flatpak after yay finishes.

You can use mkfifo to create a named pipe.

1 Like

Current result:

#!/bin/sh

[[ "$(id -u)" -ne 0 ]] && { sudo $0; exit; } # Ask for sudo on-demand

#------------------------------------------------------------------------------------------------------------------

tmppipe=
cleanup () {
  trap - EXIT
  if [ -n "$tmppipe" ] ; then rm -rf "$tmppipe"; fi
  if [ -n "$1" ]; then trap - $1; kill -$1 $$; fi
}
tmppipe=$(mktemp -u)
trap 'cleanup' EXIT
trap 'cleanup HUP' HUP
trap 'cleanup TERM' TERM
trap 'cleanup INT' INT
mkfifo -m 600 "$tmppipe"

#------------------------------------------------------------------------------------------------------------------

flatpak update -y --noninteractive 2>&1> $tmppipe &

#------------------------------------------------------------------------------------------------------------------

echo "==Pacman===========================================================================================" && \
sudo pacman -Syu --noconfirm --color always && \

echo "==Yay==============================================================================================" && \
yay --noconfirm

echo "==Flatpak=========================================================================================="
cat < $tmppipe

Does named pipe stores writer’s data in memory until reader connect, or does named pipe simply halts the writer process until reader process will pick up the writer’s content?

Because looks like it halt the writer’s pipe…

Yea so to allow for pipe writer to not freeze and do process asynchronously, I used mbuffer - measuring buffer . Probably should choose some other more specialized buffer program, but I don’t know/care about mini efficiency too much; I just wanted to make update process faster by parallelizing it and without gibberish result output.

#!/bin/sh

#------------------------------------------------------------------------------------------------------------------

tmppipe=
cleanup () {
  trap - EXIT
  if [ -n "$tmppipe" ] ; then rm -rf "$tmppipe"; fi
  if [ -n "$1" ]; then trap - $1; kill -$1 $$; fi
}
tmppipe=$(mktemp -u)
trap 'cleanup' EXIT
trap 'cleanup HUP' HUP
trap 'cleanup TERM' TERM
trap 'cleanup INT' INT
mkfifo -m 0600 "$tmppipe"

#------------------------------------------------------------------------------------------------------------------

flatpak update -y --noninteractive | mbuffer -q --append --no-direct > $tmppipe &

#------------------------------------------------------------------------------------------------------------------

echo "==Pacman===========================================================================================" && \

[[ "$(id -u)" -ne 0 ]] && { sudo pacman -Syu --noconfirm --color always; } # Ask for sudo on-demand
[[ "$(id -u)" -eq 0 ]] && {      pacman -Syu --noconfirm --color always; }

echo "==Yay==============================================================================================" && \
yay --noconfirm -Sua

echo "==Flatpak=========================================================================================="
cat < $tmppipe

Edits:

Perhaps something to add here. After sudo pacman -Syu you can run yay -Sua. Doing this tells yay to only update AUR packages and ignore the main repos.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.