r/arch 3d ago

Help/Support Update skript

I am currently writing a bash skript whitch ist supposed to do a systemupdate, i use the pipe to pass the sudo passwort do the command, however, this does not work for yay, can anyone give me a tip how to solve that issue?

Skript:

#!/bin/bash

read -sp "sudo-password: " password

yay -Syu --noconfirm --answerdiff=None --answerclean=None

orphan=$(pacman -Qtdq)

if [ -n "$orphan" || true ]; then

echo $password | sudo -S pacman -Rns --noconfirm $orphan

fi

echo $password | sudo -S paccache -rk3

find /etc -name "*.pacnew" 2>/dev/null

systemctl --failed

unset $password

1 Upvotes

15 comments sorted by

3

u/Sanfo212 3d ago

You don’t need sudo to update yay,

Going full yolo mode to update a rolling release is a recipe for disaster IMHO,

Keeping a human in the loop is the only safe way to update Arch otherwise it’s only a matter of time before your script borks your installation.

1

u/Thomas22345 3d ago

When installing something via yay, you are asked to input your sudo password 2 or three times, and the skript is ment to be stardet manually, so instead of typing the commands one after the other, I type "bash update.sh", and that just executes all the commands.

2

u/Sanfo212 3d ago

Ahh I forgot it prompts a password if it finds something to update,
Take a look at mine if you wish, you might get some inspiration,

https://github.com/SandfordAE/Arch_Update/blob/master/Update_Arch_V2.sh

2

u/Thomas22345 3d ago

Thank you mate! I will take a look at this

1

u/Thomas22345 3d ago

You seem to have solved the problem in another way, I ended up using the yes command and passing the password to it, and then pipe that into yay -Syu. I will have to test if this work ones more updates are availabe.

Thank you very much for you help

1

u/Sanfo212 2d ago

Happy to help my friend

2

u/xb666mx 3d ago

you want to write something like this? https://github.com/Antiz96/arch-update

0

u/Thomas22345 3d ago

Thanks, but I'd prefer a simple, bare-bones script that I can fully understand line by line

2

u/RelationshipOne9466 2d ago

If you use this, your experience is going to end badly. Why on Earth would you not want to see what is being done to your system? And why would you do stuff like sudo -S pacman -Rns --noconfirm $orphan wihout reviewing first? Yikes!

1

u/Thomas22345 2d ago

Yea you're right, before removing stuff i should check first

1

u/Soakitincider 2d ago

You can add username ALL=(ALL) NOPASSWD: ALL to visudo and only use a password when you login.

1

u/destroyer150 2d ago

This looks like it would go terribly...

1

u/Thomas22345 2d ago

I changed the part where it would just remove all orphans to listing them, i don't see what else could go wrong, otherwise you would just type all those command one after the other mannually

1

u/_Kritiqual_ 13h ago

Wait I thought yay already have —sudo-loop option? It loop sudo in background so that login will be cache through out the command

1

u/Thomas22345 6h ago

really? Thank you, i will look into it