mirror of https://github.com/aminya/setup-cpp
feat: use admina instead of root-tools
https://github.com/aminya/admina
This commit is contained in:
parent
8e3dedf952
commit
357e710629
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -55,6 +55,7 @@
|
|||
"@actions/io": "^1.1.2",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@npmcli/ci-detect": "github:aminya/ci-detect#37fe40075bebec96794ba0a7c4a6d5c70cbea00d",
|
||||
"admina": "^0.1.0",
|
||||
"ci-log": "workspace:1.0.0",
|
||||
"escape-path-with-spaces": "github:aminya/escape-path-with-spaces#d9f81ee649203ddc55783a2f96ada59df06118e3",
|
||||
"exec-powershell": "workspace:1.0.0",
|
||||
|
@ -64,7 +65,6 @@
|
|||
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
|
||||
"numerous": "1.0.3",
|
||||
"patha": "^0.4.0",
|
||||
"root-tools": "workspace:1.0.0",
|
||||
"semver": "7.3.7",
|
||||
"setup-python": "github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d",
|
||||
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
<h1 align="center">root-tools</h1>
|
||||
<p>
|
||||
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
|
||||
<a href="#" target="_blank">
|
||||
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
> Tools for working with root and sudo such as executing command as root, detecting root, etc.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install --save root-tools
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
<!-- INSERT GENERATED DOCS START -->
|
||||
|
||||
### `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<string>
|
||||
|
||||
### `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<string>
|
||||
|
||||
<!-- INSERT GENERATED DOCS END -->
|
||||
|
||||
## 🤝 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).
|
|
@ -1,41 +0,0 @@
|
|||
{
|
||||
"name": "root-tools",
|
||||
"version": "1.0.0",
|
||||
"description": "Tools for working with root and sudo such as executing command as root, detecting root, etc.",
|
||||
"homepage": "https://github.com/aminya/setup-cpp",
|
||||
"license": "Apache-2.0",
|
||||
"author": "Amin Yahyaabadi",
|
||||
"main": "./dist/index.js",
|
||||
"source": "./src/index.ts",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"execa": "^5.1.1",
|
||||
"which": "^2.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/which": "^2.0.1"
|
||||
},
|
||||
"keywords": [
|
||||
"sudo",
|
||||
"root",
|
||||
"is-root",
|
||||
"is-sudo",
|
||||
"exec-sudo",
|
||||
"exec-root",
|
||||
"isroot",
|
||||
"issudo",
|
||||
"exec",
|
||||
"execa",
|
||||
"spawn",
|
||||
"system",
|
||||
"unix",
|
||||
"linux",
|
||||
"github-actions",
|
||||
"github",
|
||||
"actions",
|
||||
"gitlab",
|
||||
"ci"
|
||||
]
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
import which from "which"
|
||||
import execa from "execa"
|
||||
|
||||
/** Detect if sudo is available and the user has root privileges */
|
||||
export function isSudo(): boolean {
|
||||
return (Boolean(process.env.CI) || isRoot()) && which.sync("sudo", { nothrow: true }) !== null
|
||||
}
|
||||
|
||||
/** Detect if the process has root privileges */
|
||||
export function isRoot(): boolean {
|
||||
return process.getuid?.() === 0
|
||||
}
|
||||
|
||||
/** Prepend `sudo` to the command if sudo is available */
|
||||
export function prependSudo(command: string) {
|
||||
if (isSudo()) {
|
||||
return `sudo ${command}`
|
||||
}
|
||||
return command
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 function execRootSync(
|
||||
program: string,
|
||||
args: string[] = [],
|
||||
execOptions: execa.SyncOptions = { stdio: "inherit", shell: true }
|
||||
): execa.ExecaSyncReturnValue<string> {
|
||||
if (isSudo()) {
|
||||
return execa.commandSync(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
|
||||
} else {
|
||||
return execa.sync(program, args, execOptions)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 function execRoot(
|
||||
program: string,
|
||||
args: string[] = [],
|
||||
execOptions: execa.Options = { stdio: "inherit", shell: true }
|
||||
): execa.ExecaChildProcess<string> {
|
||||
if (isSudo()) {
|
||||
return execa.command(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
|
||||
} else {
|
||||
return execa(program, args, execOptions)
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": ["./src"]
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"root-tools": "workspace:*",
|
||||
"admina": "0.1.0",
|
||||
"untildify": "^4.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { join } from "path"
|
||||
import untildify from "untildify"
|
||||
import { isSudo } from "root-tools"
|
||||
import { isSudo } from "admina"
|
||||
|
||||
export function untildifyUser(path: string) {
|
||||
if (isSudo() && typeof process.env.SUDO_USER === "string") {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"root-tools": "workspace:*"
|
||||
"admina": "0.1.0"
|
||||
},
|
||||
"keywords": [
|
||||
"chown",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { isSudo, execRootSync } from "root-tools"
|
||||
import { isSudo, execRootSync } from "admina"
|
||||
|
||||
/**
|
||||
* Give the user access to the given path and its sub-directories. It changes the owner to the SUDO_USER. This allows
|
||||
|
|
|
@ -23,6 +23,7 @@ importers:
|
|||
'@types/node': ^18.7.9
|
||||
'@types/semver': ^7.3.12
|
||||
'@types/which': ^2.0.1
|
||||
admina: ^0.1.0
|
||||
caxa: ^2.1.0
|
||||
ci-log: workspace:1.0.0
|
||||
cross-env: 7.0.3
|
||||
|
@ -47,7 +48,6 @@ importers:
|
|||
prettier: 2.7.1
|
||||
prettier-config-atomic: ^3.0.10
|
||||
readme-md-generator: ^1.0.0
|
||||
root-tools: workspace:1.0.0
|
||||
semver: 7.3.7
|
||||
setup-python: github:actions/setup-python#c474c82340438924daab9282d07300bfe7e3692d
|
||||
shx: 0.3.4
|
||||
|
@ -66,6 +66,7 @@ importers:
|
|||
'@actions/io': 1.1.2
|
||||
'@actions/tool-cache': 2.0.1
|
||||
'@npmcli/ci-detect': github.com/aminya/ci-detect/37fe40075bebec96794ba0a7c4a6d5c70cbea00d
|
||||
admina: 0.1.0
|
||||
ci-log: link:packages/ci-log
|
||||
escape-path-with-spaces: github.com/aminya/escape-path-with-spaces/d9f81ee649203ddc55783a2f96ada59df06118e3
|
||||
exec-powershell: link:packages/exec-powershell
|
||||
|
@ -75,7 +76,6 @@ importers:
|
|||
msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1
|
||||
numerous: 1.0.3
|
||||
patha: 0.4.0
|
||||
root-tools: link:packages/root-tools
|
||||
semver: 7.3.7
|
||||
setup-python: github.com/actions/setup-python/c474c82340438924daab9282d07300bfe7e3692d
|
||||
time-delta: github.com/aminya/time-delta/69d91a41cef28e569be9a2991129f5f7d1f0d00e
|
||||
|
@ -130,30 +130,19 @@ importers:
|
|||
devDependencies:
|
||||
'@types/which': 2.0.1
|
||||
|
||||
packages/root-tools:
|
||||
specifiers:
|
||||
'@types/which': ^2.0.1
|
||||
execa: ^5.1.1
|
||||
which: ^2.0.2
|
||||
dependencies:
|
||||
execa: 5.1.1
|
||||
which: 2.0.2
|
||||
devDependencies:
|
||||
'@types/which': 2.0.1
|
||||
|
||||
packages/untildify-user:
|
||||
specifiers:
|
||||
root-tools: workspace:*
|
||||
admina: 0.1.0
|
||||
untildify: ^4.0.0
|
||||
dependencies:
|
||||
root-tools: link:../root-tools
|
||||
admina: 0.1.0
|
||||
untildify: 4.0.0
|
||||
|
||||
packages/user-access:
|
||||
specifiers:
|
||||
root-tools: workspace:*
|
||||
admina: 0.1.0
|
||||
dependencies:
|
||||
root-tools: link:../root-tools
|
||||
admina: 0.1.0
|
||||
|
||||
packages:
|
||||
|
||||
|
@ -746,8 +735,8 @@ packages:
|
|||
'@cspell/dict-docker': 1.1.1
|
||||
'@cspell/dict-dotnet': 2.0.1
|
||||
'@cspell/dict-elixir': 2.0.1
|
||||
'@cspell/dict-en-gb': 1.1.33
|
||||
'@cspell/dict-en_us': 2.3.2
|
||||
'@cspell/dict-en-gb': 1.1.33
|
||||
'@cspell/dict-filetypes': 2.1.1
|
||||
'@cspell/dict-fonts': 2.0.1
|
||||
'@cspell/dict-fullstack': 2.0.6
|
||||
|
@ -2669,6 +2658,14 @@ packages:
|
|||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/admina/0.1.0:
|
||||
resolution: {integrity: sha512-3EfJlYMi6LeUv+diMPZWR1uhzC2/ESXzkk3BMvQl0yVsZ2kgiH7ZOWiB+Y7915w69jtDyTpliprlwOagC5hNnw==}
|
||||
dependencies:
|
||||
execa: 5.1.1
|
||||
is-admin: 4.0.0
|
||||
which: 2.0.2
|
||||
dev: false
|
||||
|
||||
/agent-base/6.0.2:
|
||||
resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==}
|
||||
engines: {node: '>= 6.0.0'}
|
||||
|
@ -3519,7 +3516,7 @@ packages:
|
|||
dev: true
|
||||
|
||||
/concat-map/0.0.1:
|
||||
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
|
||||
resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=}
|
||||
|
||||
/config-chain/1.1.13:
|
||||
resolution: {integrity: sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==}
|
||||
|
@ -5568,6 +5565,13 @@ packages:
|
|||
resolution: {integrity: sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==}
|
||||
dev: true
|
||||
|
||||
/is-admin/4.0.0:
|
||||
resolution: {integrity: sha512-ODl+ygFCyHXMauhn+0mBebcwO1tiB+b4FoBiIC97gFDcmdO3JMD+YmIhSA8+1KVZuGwfsX8ANo2yblgW5KUPTg==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
dependencies:
|
||||
execa: 5.1.1
|
||||
dev: false
|
||||
|
||||
/is-arrayish/0.2.1:
|
||||
resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==}
|
||||
dev: true
|
||||
|
|
|
@ -5,7 +5,7 @@ import { isArch } from "../utils/env/isArch"
|
|||
import { hasDnf } from "../utils/env/hasDnf"
|
||||
import { setupDnfPack } from "../utils/setup/setupDnfPack"
|
||||
import { isUbuntu } from "../utils/env/isUbuntu"
|
||||
import { execRootSync } from "root-tools"
|
||||
import { execRootSync } from "admina"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function setupBazel(version: string, _setupDir: string, _arch: string) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { dirname } from "patha"
|
||||
import which from "which"
|
||||
import { isUbuntu } from "../utils/env/isUbuntu"
|
||||
import { execRootSync } from "root-tools"
|
||||
import { execRootSync } from "admina"
|
||||
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
|
||||
|
||||
let binDir: string | undefined
|
||||
|
|
|
@ -7,7 +7,7 @@ import { isArch } from "../utils/env/isArch"
|
|||
import { hasDnf } from "../utils/env/hasDnf"
|
||||
import { setupDnfPack } from "../utils/setup/setupDnfPack"
|
||||
import { isUbuntu } from "../utils/env/isUbuntu"
|
||||
import { execRootSync } from "root-tools"
|
||||
import { execRootSync } from "admina"
|
||||
import { ubuntuVersion } from "../utils/env/ubuntu_version"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* eslint-disable require-atomic-updates */
|
||||
import { InstallationInfo } from "./setupBin"
|
||||
import { execRootSync } from "root-tools"
|
||||
import { execRootSync } from "admina"
|
||||
import { info } from "@actions/core"
|
||||
import ciDetect from "@npmcli/ci-detect"
|
||||
import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* eslint-disable require-atomic-updates */
|
||||
import { InstallationInfo } from "./setupBin"
|
||||
import { execRootSync } from "root-tools"
|
||||
import { execRootSync } from "admina"
|
||||
import { info, warning } from "ci-log"
|
||||
|
||||
// let didUpdate: boolean = false
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* eslint-disable require-atomic-updates */
|
||||
import { InstallationInfo } from "./setupBin"
|
||||
import { execRootSync } from "root-tools"
|
||||
import { execRootSync } from "admina"
|
||||
import { info } from "ci-log"
|
||||
|
||||
let didUpdate: boolean = false
|
||||
|
|
Loading…
Reference in New Issue