0

I installed gcc 5.2 with gmp, mpfr and mpc, plus the isl and cloog optimizations, works perfectly. All prefixes are in /usr/local so that I have to sudomy make install's. I had to redo the same install on the computer of a friend, and now, I have to do it on another computer of mine... It's enough, so that I wrote a script. (And broke my "script whatever you have to do twice" rule.) My problem is that at some places of the script I have sudo make install commands, and that I don't want to run my script as admin.

How could I modify my script so that the following happens : before each sudo make install command one is asked to elevate permissions, and if one accepts, one is asked the root password, and then, sudo make install is executed, and after, the next commands are executed with "normal" permissions, until the next sudo make install, etc... ?

(I tagged make but the question is of course independant of it.)

Olórin
  • 3,367
  • 2
  • 22
  • 42
  • 1
    I probably haven't understood your question correctly, but what's wrong with having a script that does the equivalent of `configure && make && sudo make install`? – user657267 Sep 28 '15 at 23:45
  • yes, or something with sub-shells, that eliminate any environment changes once they have closed. Something like `configure && make && (sudo make install)` ... Just an idea. Good luck. – shellter Sep 29 '15 at 07:00
  • 2
    `sudo` doesn't ask you for the root password, but your own; and it only does this when you haven't `sudo`ed recently enough. So just put `sudo :` at the top of the script, so it will ask for the password right away, and all the other `sudo` commands will execute without asking anything. – reinierpost Sep 29 '15 at 12:31
  • @reinierpost This is the answer I was looking for, thx ! – Olórin Sep 30 '15 at 21:03
  • @reinierpost: Can you make your comment as an answer? I`m sure it will be helpful for futher readers. – Tsyvarev Oct 07 '15 at 10:20
  • Possible duplicate of [Bash scripts requiring sudo password](http://stackoverflow.com/questions/3976362/bash-scripts-requiring-sudo-password) – reinierpost Oct 07 '15 at 10:40

1 Answers1

1

sudo doesn't ask you for the root password, but your own; and it only does this when you haven't sudoed recently enough.

So just put sudo : at the top of the script: then it will ask for the password right away, and after it has been supplied, all the other sudo commands will execute without asking anything.

reinierpost
  • 8,425
  • 1
  • 38
  • 70
  • Out of curiosity, does this work for all bash scripts or ? How to be sure to exit from super user rights at the end of the script ? – Olórin Oct 07 '15 at 22:15
  • `sudo ` executes that one command with super user rights. So every line without `sudo` runs without those rights. That is why working with `sudo` beats working in a root shell. – reinierpost Oct 08 '15 at 08:04