chore: move execaSudo

This commit is contained in:
Amin Yahyaabadi 2022-01-30 17:23:09 -08:00
parent 614ed712da
commit 1410ebe4ca
4 changed files with 20 additions and 19 deletions

View File

@ -2,7 +2,7 @@ import execa from "execa"
// import { join } from "path"
// import { untildify_user as untildify } from "./utils/path/untildify"
// import { setupCmake } from "../cmake/cmake"
import { execaSudo } from "../utils/env/sudo"
import { execSudo } from "../utils/exec/sudo"
import { addBinExtension } from "../utils/extension/extension"
import { extractTarByExe } from "../utils/setup/extract"
import { setupAptPack } from "../utils/setup/setupAptPack"
@ -38,7 +38,7 @@ function getKcovPackageInfo(version: string): PackageInfo {
await setupAptPack("libcurl4-openssl-dev")
await execa("cmake", ["-S", "./", "-B", "./build"], { cwd: out })
await execa("cmake", ["--build", "./build", "--config", "Release"], { cwd: out })
await execaSudo("cmake", ["--install", "./build"], out)
await execSudo("cmake", ["--install", "./build"], out)
return out
},
}

View File

@ -1,4 +1,3 @@
import execa from "execa"
import which from "which"
let _issudo: boolean | undefined = undefined
@ -18,11 +17,3 @@ export function mightSudo(command: string) {
}
return command
}
export function execaSudo(file: string, args: string[], cwd?: string) {
if (isRoot()) {
return execa.command(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, { shell: true, cwd })
} else {
return execa(file, args)
}
}

10
src/utils/exec/sudo.ts Normal file
View File

@ -0,0 +1,10 @@
import execa from "execa"
import { isRoot } from "../env/sudo"
export function execSudo(file: string, args: string[], cwd?: string) {
if (isRoot()) {
return execa.command(`sudo ${[file, ...args].map((arg) => `'${arg}'`).join(" ")}`, { shell: true, cwd })
} else {
return execa(file, args)
}
}

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execaSudo } from "../env/sudo"
import { execSudo } from "../exec/sudo"
let didUpdate: boolean = false
let didInit: boolean = false
@ -16,7 +16,7 @@ export async function setupAptPack(
process.env.DEBIAN_FRONTEND = "noninteractive"
if (!didUpdate) {
await execaSudo(apt, ["update", "-y"])
await execSudo(apt, ["update", "-y"])
didUpdate = true
}
@ -25,7 +25,7 @@ export async function setupAptPack(
// set time - zone
// TZ = Canada / Pacific
// ln - snf / usr / share / zoneinfo / $TZ / etc / localtime && echo $TZ > /etc/timezone
await execaSudo(apt, [
await execSudo(apt, [
"install",
"--fix-broken",
"-y",
@ -40,19 +40,19 @@ export async function setupAptPack(
if (Array.isArray(repositories)) {
for (const repo of repositories) {
// eslint-disable-next-line no-await-in-loop
await execaSudo("add-apt-repository", ["--update", "-y", repo])
await execSudo("add-apt-repository", ["--update", "-y", repo])
}
await execaSudo(apt, ["update", "-y"])
await execSudo(apt, ["update", "-y"])
}
if (version !== undefined && version !== "") {
try {
await execaSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
} catch {
await execaSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
await execSudo(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
}
} else {
await execaSudo(apt, ["install", "--fix-broken", "-y", name])
await execSudo(apt, ["install", "--fix-broken", "-y", name])
}
return { binDir: "/usr/bin/" }