# BASH. Parallel uninteractive update script. Flatpak Pacman AUR Yay

**URL:** <https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156>\
**Category:** Community contributions\
**Created:** [September 10, 2024, 2:05pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156 "2024-09-10T14:05:35Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 10, 2024, 2:05pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/1 "2024-09-10T14:05:35Z")

</div>

Context current shell script:

```bash
[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 ?

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [September 10, 2024, 2:09pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/2 "2024-09-10T14:09:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 10, 2024, 2:10pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/3 "2024-09-10T14:10:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![I0F](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/i0f/32/47182_2.png) [@I0F](https://forum.endeavouros.com/u/I0F)\
**Post date:** [September 10, 2024, 2:13pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/4 "2024-09-10T14:13:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 10, 2024, 2:14pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/5 "2024-09-10T14:14:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![I0F](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/i0f/32/47182_2.png) [@I0F](https://forum.endeavouros.com/u/I0F)\
**Post date:** [September 10, 2024, 2:14pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/6 "2024-09-10T14:14:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 10, 2024, 2:18pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/7 "2024-09-10T14:18:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![I0F](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/i0f/32/47182_2.png) [@I0F](https://forum.endeavouros.com/u/I0F)\
**Post date:** [September 10, 2024, 2:24pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/8 "2024-09-10T14:24:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [September 10, 2024, 2:39pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/9 "2024-09-10T14:39:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 10, 2024, 2:45pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/10 "2024-09-10T14:45:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [September 10, 2024, 2:52pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/11 "2024-09-10T14:52:46Z")

</div>

You can use `mkfifo` to create a named pipe.

---

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 10, 2024, 5:25pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/12 "2024-09-10T17:25:39Z")

</div>

Current result:

```bash
#!/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

```

---

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 10, 2024, 7:05pm UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/13 "2024-09-10T19:05:39Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![vini.nu](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/vini.nu/32/97538_2.png) [@vini.nu](https://forum.endeavouros.com/u/vini.nu)\
**Post date:** [September 12, 2024, 5:52am UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/14 "2024-09-12T05:52:06Z")

</div>

Yea so to allow for pipe writer to not freeze and do process asynchronously, I used [mbuffer - measuring buffer](https://man.archlinux.org/man/extra/mbuffer/mbuffer.1.en) . 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.

```bash
#!/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:

> [@BASH. Parallel uninteractive update script. Flatpak Pacman AUR Yay](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/15):
>
> 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.

---

<div class="post-metadata">

**Author:** ![wordler](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/wordler/32/14412_2.png) [@wordler](https://forum.endeavouros.com/u/wordler)\
**Post date:** [September 12, 2024, 6:31am UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/15 "2024-09-12T06:31:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.endeavouros.com/uploads/default/original/2X/9/9ea52f9fd5ef8e609e593c362d61a36295f48be8.png) [@system](https://forum.endeavouros.com/u/system)\
**Post date:** [September 14, 2024, 6:32am UTC](https://forum.endeavouros.com/t/bash-parallel-uninteractive-update-script-flatpak-pacman-aur-yay/60156/16 "2024-09-14T06:32:03Z")

</div>

Closed on September 14, 2024, 6:32am UTC

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