mirror of https://github.com/aminya/setup-cpp
fix: add execaSudo
This commit is contained in:
parent
15b1b24116
commit
51da3adc7b
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,5 @@
|
||||||
|
import execa from "execa"
|
||||||
|
|
||||||
let _issudo: boolean | undefined = undefined
|
let _issudo: boolean | undefined = undefined
|
||||||
|
|
||||||
export function isRoot(): boolean {
|
export function isRoot(): boolean {
|
||||||
|
@ -15,3 +17,11 @@ export function mightSudo(command: string) {
|
||||||
}
|
}
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function execaSudo(file: string, args: string[]) {
|
||||||
|
if (isRoot()) {
|
||||||
|
return execa("sudo", [file, ...args])
|
||||||
|
} else {
|
||||||
|
return execa(file, args)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
/* eslint-disable require-atomic-updates */
|
/* eslint-disable require-atomic-updates */
|
||||||
import execa from "execa"
|
|
||||||
import { InstallationInfo } from "./setupBin"
|
import { InstallationInfo } from "./setupBin"
|
||||||
// import { mightSudo } from "./sudo"
|
import { execaSudo } from "../env/sudo"
|
||||||
|
|
||||||
let didUpdate: boolean = false
|
let didUpdate: boolean = false
|
||||||
|
|
||||||
|
@ -14,22 +13,22 @@ export async function setupAptPack(
|
||||||
const apt = "apt-get" // mightSudo
|
const apt = "apt-get" // mightSudo
|
||||||
|
|
||||||
if (typeof repository === "string") {
|
if (typeof repository === "string") {
|
||||||
await execa("add-apt-repository", ["--update", "-y", repository])
|
await execaSudo("add-apt-repository", ["--update", "-y", repository])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!didUpdate || repository === true) {
|
if (!didUpdate || repository === true) {
|
||||||
await execa(apt, ["update", "-y"])
|
await execaSudo(apt, ["update", "-y"])
|
||||||
didUpdate = true
|
didUpdate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version !== undefined && version !== "") {
|
if (version !== undefined && version !== "") {
|
||||||
try {
|
try {
|
||||||
await execa(apt, ["install", "-y", `${name}=${version}`])
|
await execaSudo(apt, ["install", "-y", `${name}=${version}`])
|
||||||
} catch {
|
} catch {
|
||||||
await execa(apt, ["install", "-y", `${name}-${version}`])
|
await execaSudo(apt, ["install", "-y", `${name}-${version}`])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await execa(apt, ["install", "-y", name])
|
await execaSudo(apt, ["install", "-y", name])
|
||||||
}
|
}
|
||||||
|
|
||||||
return { binDir: "/usr/bin/" }
|
return { binDir: "/usr/bin/" }
|
||||||
|
|
Loading…
Reference in New Issue