Make rustup.sh run sudo itself
There's a lot of code here that would not need to run as root if rustup.sh did the sudo invocation itself, and ~/.rustup would not need to be owned by root.
Some considerations:
- How to detect when sudo is needed
- What to do when there's no tty
- Needs to accommodate non-interactive tools
This would be great. One downside: even if the script pre-authorizes itself with sudo -v, the download might take long enough (or the timeout set short enough) that the timeout expires before it tries to use sudo to run the actual install.
An alternative approach might instead be instead to simply detect when the script is run with sudo and do most of the work in a child process that has its privileges revoked (sudo -u "#$SUDO_UID" ...), then perform the actual install in the parent once the child indicates that it's performed all of the previous steps.
I want to install rust into home folder and do not give rustup.sh root rights at all (using --prefix option) Can I do this after such change?
@PetrGlad rustup has already adopted this change, and there's a --disable-sudo flag to skip running sudo.