sudo
does remember the authentication for a number of minutes ─ I think it’s five minutes by default ─ so two subsequent sudo
calls should only require your password once, provided that the first call finishes within the allotted time.
But I don’t understand why you’ve included a wait
after the first sudo
. You can simply use a condition instead, like so…
sudo pacman-mirrors [and all that jazz] && sudo pacman -Syyu
The &&
is a logical AND operand. So the update process will only run once the mirror list has been updated, and will not run if the mirror list update fails for whatever reason.
That said, instead of sudo pacman -Syyu
, you can also use pamac update
, which doesn’t require sudo
. But it’ll still ask you for a password, of course.
And speaking of which, if you specifically want to update AUR packages with the pamac
command, then it might be wise to also add --devel
, just in case some of your AUR packages are -git
packages.
Also, you don’t need to put a quoted space after echo
. An echo
without parameters will simply print a blank line.
The above all said, I would do it like this…
#!/bin/bash
read -n1 -p "Refresh Mirrors? [y/N] "
case ${REPLY} in
"Y" | "y" )
sudo pacman-mirrors --continent --api --protocols all --set-branch stable
echo
echo
;;
esac
pamac update && pamac update --aur --devel && pamac remove -o && pacmac clean
sudo flatpak update -y && snap refresh
echo
echo
unset REPLY
read -n1 -p "Refresh Keys? [y/N] "
case ${REPLY} in
"Y" | "y" )
sudo pacman-key --refresh-keys && sudo pacman-key --populate archlinux manjaro
echo
echo
;;
esac
unset REPLY
return
I don’t know why you’re trying to invoke the shell there. If your intent is to get a simple interactive shell, then just let the script execute, and it’ll return to the command prompt after running.
The return
command that I’ve added also isn’t necessary, but it allows for the script to be called from within another script or from within a subroutine. It’s just scripting hygiene.