I have a script that executes three functions:
A && B && C.
B needs to be run as a super-user, while
I have several solutions but neither of these are satisfying:
sudo the entire script:
sudo 'A && B && C'
That seems like a bad idea to run
Cas super-user if it's not needed
make the script interactive:
A && sudo B && C
I might have to type-in my password, but I want my script to be non-interactive, as each function can take some time, and I don't want the script to wait for me. Well, that's also why it's a script in the first place, so I don't have to watch it run.
The stupid solution:
sudo : && A && sudo -n B && C
First it seems stupid to run a no-op
sudofirst, and also I must cross my finger that A is not going to take more than
Hypothetical solution (I wish you tell me it exists):
sudo --store-cred 'A && sudo --use-cred-from-parent-sudo B && C'
That would prompt for my password at the beginning, and then use that credentials only when needed.
What's your opinion on all this? I'd be very surprised that there is no
solution to that problem, as I think it's a pretty common problem (what
make all && sudo make install)