From https://calibre-ebook.com/download_linux

sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin

What is the purpose of sudo -v && here, given that man sudo says

 -v, --validate

Update the user's cached credentials, authenticating the user if necessary. For the sudoers plugin, this extends the sudo timeout for another 15 minutes by default, but does not run a command. Not all security policies support cached credentials.

What is the purpose of sh /dev/stdin? (In Ubuntu 18.04, sh is dash)



What is the purpose of sudo -v && here?

I believe this minimizes user surprise if/when they are prompted by the second call to sudo for sudo sh /dev/stdin. Consider if the wget command takes some number of seconds to complete; perhaps the user switches windows or tasks and comes back later, only to find an un-bidden password prompt. What is asking for their password? Why?

With the initial sudo -v, the user is immediately prompted for their password, and the hope is that the sudo timeout will cover the time it takes for wget to complete. If the user is already inside the sudo timeout, the timeout is simply extended.

What is the purpose of sh /dev/stdin?

Here sh is being called with a parameter as the command_file that is a special file -- a link to stdin.

NAME dash — command interpreter (shell)


 dash ...
      [command_file [argument ...]]

As a result, sh reads the command_file, expecting and executing commands from it. That special stdin "file" is connected via the pipe to the output from wget, so the end result is that the contents of the URL are sent to a root-level shell.

I do not know why the Calibre project specifically chose that syntax. Alternatives include:

  • ... | sudo sh
  • ... | sudo sh -
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.