admina
Version:
Detect root/admin/sudo and execute commands as it if available
43 lines (42 loc) • 1.76 kB
text/typescript
import { SyncOptions as ExecaSyncOptions, ExecaSyncReturnValue, Options as ExecaOptions, ExecaChildProcess } from "execa";
/** Detect if sudo is available */
export declare function hasSudo(): boolean;
/**
* Detect if the process has root privilege on Posix.
*
* @example
*
* ```js
* import { isRoot } from "admina"
*
* console.log(isRoot())
* //=> false
* ```
*
* @returns Whether the process is running as root.
*/
export declare function isRoot(): boolean;
/** Detect if sudo is available and the user has root privileges */
export declare function isSudo(): boolean;
/** Prepend `sudo` to the command if sudo is available */
export declare function prependSudo(command: string): string;
/** Default exec options `{ stdio: "inherit", shell: true }` */
export declare const defaultExecOptions: ExecaSyncOptions;
/**
* Execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
*
* @param program The program to spawn
* @param args The command arguments
* @param execOptions The options passed to `execa`. Defaults to `{ stdio: "inherit", shell: true }`
* @returns The execution result
*/
export declare function execRootSync(program: string, args?: string[], execOptions?: ExecaSyncOptions): ExecaSyncReturnValue<string>;
/**
* Asynchronously execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
*
* @param program The program to spawn
* @param args The command arguments
* @param execOptions The options passed to `execa`. Defaults to `{ stdio: "inherit", shell: true }`
* @returns A promise to the execution result
*/
export declare function execRoot(program: string, args?: string[], execOptions?: ExecaOptions): ExecaChildProcess<string>;