root-tools
> Tools for working with root and sudo such as executing command as root, detecting root, etc.
## Install
```sh
npm install --save root-tools
```
## Usage
### `isSudo` (function)
Detect if sudo is available and the user has root privileges
**returns:** boolean
### `isRoot` (function)
Detect if the process has root privileges
**returns:** boolean
### `prependSudo` (function)
Prepend `sudo` to the command if sudo is available
**Parameters:**
- command (`string`)
**returns:** string
### `execRootSync` (function)
Execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
**Parameters:**
- program (`string`) - The program to spawn
- args (`string[]`) - The command arguments
- execOptions (`execa.SyncOptions`) - The options passed to `execa`. Defaults to `{ stdio: "inherit" }`
**returns:** execa.ExecaSyncReturnValue
### `execRoot` (function)
Asynchronously execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
**Parameters:**
- program (`string`) - The program to spawn
- args (`string[]`) - The command arguments
- execOptions (`execa.Options`) - The options passed to `execa`. Defaults to `{ stdio: "inherit" }`
**returns:** execa.ExecaChildProcess
## 🤝 Contributing
You can sponsor my work here:
https://github.com/sponsors/aminya
Pull requests, issues and feature requests are welcome.
See the [Contributing guide](https://github.com/aminya/setup-cpp/blob/master/CONTRIBUTING.md).