fix: rename execRoot to execRootSync

This commit is contained in:
Amin Yahyaabadi 2022-08-07 17:33:11 -07:00
parent 0d99c85e65
commit e495d4d0d5
8 changed files with 37 additions and 33 deletions

View File

@ -28,7 +28,11 @@ export function prependSudo(command: string) {
*
* Defaults to `{ stdio: "inherit" }`
*/
export function execRoot(program: string, args: string[] = [], execOptions: execa.SyncOptions = { stdio: "inherit" }) {
export function execRootSync(
program: string,
args: string[] = [],
execOptions: execa.SyncOptions = { stdio: "inherit" }
) {
if (isSudo()) {
return execa.commandSync(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
} else {

View File

@ -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 { execRoot } from "sudo-tools"
import { execRootSync } from "sudo-tools"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupBazel(version: string, _setupDir: string, _arch: string) {
@ -24,7 +24,7 @@ export async function setupBazel(version: string, _setupDir: string, _arch: stri
} else if (hasDnf()) {
// https://bazel.build/install/redhat
setupDnfPack("dnf-plugins-core", undefined)
execRoot("dnf", ["copr", "enable", "vbatts/bazel"])
execRootSync("dnf", ["copr", "enable", "vbatts/bazel"])
return setupDnfPack("bazel4", undefined)
} else if (isUbuntu()) {
// https://bazel.build/install/ubuntu
@ -32,7 +32,7 @@ export async function setupBazel(version: string, _setupDir: string, _arch: stri
"bazel-archive-keyring.gpg",
"https://bazel.build/bazel-release.pub.gpg"
)
execRoot("bash", [
execRootSync("bash", [
"-c",
`echo "deb [arch=amd64 signed-by=${keyFileName}] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list`,
])

View File

@ -61,7 +61,7 @@ async function buildKcov(file: string, dest: string) {
stdio: "inherit",
})
await execa(cmake, ["--build", buildDir, "--config", "Release"], { cwd: out, stdio: "inherit" })
// execRoot(cmake, ["--install", buildDir], out)
// execRootSync(cmake, ["--install", buildDir], out)
// return "user/local/bin" // the cmake install prefix
return out
}

View File

@ -1,7 +1,7 @@
import { dirname } from "path"
import which from "which"
import { isUbuntu } from "../utils/env/isUbuntu"
import { execRoot } from "sudo-tools"
import { execRootSync } from "sudo-tools"
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
let binDir: string | undefined
@ -26,7 +26,7 @@ export async function setupNala(version: string, _setupDir: string, _arch: strin
"volian-archive-scar-unstable.gpg",
"https://deb.volian.org/volian/scar.key"
)
execRoot("/bin/bash", [
execRootSync("/bin/bash", [
"-c",
`echo "deb [signed-by=${keyFileName}] http://deb.volian.org/volian/ scar main" | tee /etc/apt/sources.list.d/volian-archive-scar-unstable.list`,
])

View File

@ -1,5 +1,5 @@
import { isSudo } from "sudo-tools"
import { execRoot } from "sudo-tools"
import { execRootSync } from "sudo-tools"
/// change the owner to the SUDO_USER. This is required so the user can use the folder without sudo
export function folderUserAccess(folder: string) {
@ -8,6 +8,6 @@ export function folderUserAccess(folder: string) {
isSudo() &&
process.env.SUDO_USER !== undefined
) {
execRoot("chown", ["-R", process.env.SUDO_USER, folder], { cwd: folder, stdio: "inherit" })
execRootSync("chown", ["-R", process.env.SUDO_USER, folder], { cwd: folder, stdio: "inherit" })
}
}

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execRoot } from "sudo-tools"
import { execRootSync } from "sudo-tools"
import { info } from "@actions/core"
import { isGitHubCI } from "../env/isCI"
import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv"
@ -36,19 +36,19 @@ export async function setupAptPack(
if (Array.isArray(repositories) && repositories.length !== 0) {
for (const repo of repositories) {
// eslint-disable-next-line no-await-in-loop
execRoot("add-apt-repository", ["--update", "-y", repo])
execRootSync("add-apt-repository", ["--update", "-y", repo])
}
updateRepos(apt)
}
if (version !== undefined && version !== "") {
try {
execRoot(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
execRootSync(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
} catch {
execRoot(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
execRootSync(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
}
} else {
execRoot(apt, ["install", "--fix-broken", "-y", name])
execRootSync(apt, ["install", "--fix-broken", "-y", name])
}
return { binDir: "/usr/bin/" }
@ -65,12 +65,12 @@ function getApt() {
}
function updateRepos(apt: string) {
execRoot(apt, apt !== "nala" ? ["update", "-y"] : ["update"])
execRootSync(apt, apt !== "nala" ? ["update", "-y"] : ["update"])
}
/** Install apt utils and certificates (usually missing from docker containers) */
async function initApt(apt: string) {
execRoot(apt, [
execRootSync(apt, [
"install",
"--fix-broken",
"-y",
@ -89,7 +89,7 @@ async function initApt(apt: string) {
}
function initGpg() {
execRoot("gpg", ["-k"])
execRootSync("gpg", ["-k"])
}
export function addAptKeyViaServer(keys: string[], name: string, server = "keyserver.ubuntu.com") {
@ -97,7 +97,7 @@ export function addAptKeyViaServer(keys: string[], name: string, server = "keyse
if (!existsSync(fileName)) {
initGpg()
for (const key of keys) {
execRoot("gpg", [
execRootSync("gpg", [
"--no-default-keyring",
"--keyring",
`gnupg-ring:${fileName}`,
@ -106,7 +106,7 @@ export function addAptKeyViaServer(keys: string[], name: string, server = "keyse
"--recv-keys",
key,
])
execRoot("chmod", ["644", fileName])
execRootSync("chmod", ["644", fileName])
}
}
return fileName
@ -117,15 +117,15 @@ export async function addAptKeyViaDownload(name: string, url: string) {
if (!existsSync(fileName)) {
initGpg()
await setupAptPack("curl", undefined)
execRoot("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`])
execRoot("chmod", ["644", fileName])
execRootSync("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`])
execRootSync("chmod", ["644", fileName])
}
return fileName
}
export function updateAptAlternatives(name: string, path: string) {
if (isGitHubCI()) {
return execRoot("update-alternatives", ["--install", `/usr/bin/${name}`, name, path, "40"])
return execRootSync("update-alternatives", ["--install", `/usr/bin/${name}`, name, path, "40"])
} else {
setupCppInProfile()
return appendFileSync(

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execRoot } from "sudo-tools"
import { execRootSync } from "sudo-tools"
import { info, warning } from "../io/io"
// let didUpdate: boolean = false
@ -12,19 +12,19 @@ export function setupDnfPack(name: string, version?: string): InstallationInfo {
const dnf = "dnf"
// if (!didUpdate) {
// execRoot(dnf, ["-y", "check-update"])
// execRootSync(dnf, ["-y", "check-update"])
// didUpdate = true
// }
if (version !== undefined && version !== "") {
try {
execRoot(dnf, ["-y", "install", `${name}-${version}`])
execRootSync(dnf, ["-y", "install", `${name}-${version}`])
} catch (err) {
warning(`${(err as Error).toString()}\nInstalling the default version available via dnf`)
execRoot(dnf, ["-y", "install", name])
execRootSync(dnf, ["-y", "install", name])
}
} else {
execRoot(dnf, ["-y", "install", name])
execRootSync(dnf, ["-y", "install", name])
}
return { binDir: "/usr/bin/" }

View File

@ -1,6 +1,6 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execRoot } from "sudo-tools"
import { execRootSync } from "sudo-tools"
import { info } from "../io/io"
let didUpdate: boolean = false
@ -13,24 +13,24 @@ export function setupPacmanPack(name: string, version?: string, aur?: string): I
const pacman = "pacman"
if (!didUpdate) {
execRoot(pacman, ["-Syuu", "--noconfirm"])
execRootSync(pacman, ["-Syuu", "--noconfirm"])
didUpdate = true
}
if (!didInit) {
// install base-devel
execRoot(pacman, ["-Sy", "--noconfirm", "base-devel"])
execRootSync(pacman, ["-Sy", "--noconfirm", "base-devel"])
didInit = true
}
if (version !== undefined && version !== "") {
try {
execRoot(aur ?? pacman, ["-S", "--noconfirm", `${name}=${version}`])
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}=${version}`])
} catch {
execRoot(aur ?? pacman, ["-S", "--noconfirm", `${name}${version}`])
execRootSync(aur ?? pacman, ["-S", "--noconfirm", `${name}${version}`])
}
} else {
execRoot(aur ?? pacman, ["-S", "--noconfirm", name])
execRootSync(aur ?? pacman, ["-S", "--noconfirm", name])
}
return { binDir: "/usr/bin/" }