sudo-prompt/README.md

38 lines
1.6 KiB
Markdown
Raw Normal View History

2015-08-05 09:11:02 +02:00
# sudo-prompt
2015-06-08 15:24:56 +02:00
2015-06-08 15:34:07 +02:00
Run a command using sudo, prompting the user with an OS dialog if necessary. Useful for background applications or native Electron apps that need sudo.
2015-06-08 15:24:56 +02:00
2015-06-08 15:38:31 +02:00
![Sudo on Mac OS X for an app called "Ronomon"](./osx.png)
2015-06-08 15:37:08 +02:00
2015-06-08 15:29:54 +02:00
Currently supports native OS dialog prompt on Mac OS X (patches welcome for Linux) and uses process.title as the name of the app requesting permission.
2015-06-08 15:24:56 +02:00
2015-08-05 09:10:34 +02:00
sudo-prompt has no external dependencies and does not require any native bindings.
## Installation
```
npm install sudo-prompt
```
2015-06-08 15:24:56 +02:00
## Usage
2015-06-08 15:34:07 +02:00
Note: Your command should not start with the "sudo" prefix.
2015-06-08 15:24:56 +02:00
```
2015-08-05 09:10:34 +02:00
// To run a command using sudo-prompt:
2015-06-08 15:24:56 +02:00
var sudo = require('sudo-prompt');
sudo.exec('echo hello', function(error) {});
// To update the sudo timestamp for the current user:
2015-08-05 09:10:34 +02:00
// This will extend any existing sudo session for a few more minutes.
// It will prompt to create a new session if there is no existing sudo session.
2015-06-08 15:24:56 +02:00
sudo.touch(function(error) {});
// To use something other than process.title as the app name:
// Must be alphanumeric (may contain spaces).
sudo.setName('Your app name')
```
2015-08-05 09:10:34 +02:00
## Behavior
2015-08-10 08:32:13 +02:00
sudo-prompt should behave just like the `sudo` command in the shell. If your command does not work with the `sudo` command in the shell (perhaps because it uses `>` redirection to a restricted file), then it will not work with sudo-prompt. However, it is still possible to use sudo-prompt to get a privileged shell, [see this issue for more information](https://github.com/jorangreef/sudo-prompt/issues/1).
2015-08-05 09:10:34 +02:00
2015-06-08 15:24:56 +02:00
## Concurrency
2015-08-05 09:12:00 +02:00
You can call `sudo.exec` and `sudo.touch` concurrently, and sudo-prompt will batch up permission requests into a single password prompt.