setup-cpp/packages/root-tools
Amin Yahyaabadi b38bf66f56 feat: add user-access package 2022-08-07 21:03:16 -07:00
..
src fix: fix the root-tools folder name 2022-08-07 19:27:05 -07:00
README.md feat: add user-access package 2022-08-07 21:03:16 -07:00
package.json feat: add untildify-user package 2022-08-07 20:04:59 -07:00
tsconfig.json fix: fix the root-tools folder name 2022-08-07 19:27:05 -07:00

README.md

root-tools

Version License: Apache--2.0

Tools for working with root and sudo such as executing command as root, detecting root, etc.

Install

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", shell: true }

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", shell: true }

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.