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" }` * 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()) { if (isSudo()) {
return execa.commandSync(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions) return execa.commandSync(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
} else { } else {

View File

@ -5,7 +5,7 @@ import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf" import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack" import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu" 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 // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupBazel(version: string, _setupDir: string, _arch: string) { 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()) { } else if (hasDnf()) {
// https://bazel.build/install/redhat // https://bazel.build/install/redhat
setupDnfPack("dnf-plugins-core", undefined) setupDnfPack("dnf-plugins-core", undefined)
execRoot("dnf", ["copr", "enable", "vbatts/bazel"]) execRootSync("dnf", ["copr", "enable", "vbatts/bazel"])
return setupDnfPack("bazel4", undefined) return setupDnfPack("bazel4", undefined)
} else if (isUbuntu()) { } else if (isUbuntu()) {
// https://bazel.build/install/ubuntu // https://bazel.build/install/ubuntu
@ -32,7 +32,7 @@ export async function setupBazel(version: string, _setupDir: string, _arch: stri
"bazel-archive-keyring.gpg", "bazel-archive-keyring.gpg",
"https://bazel.build/bazel-release.pub.gpg" "https://bazel.build/bazel-release.pub.gpg"
) )
execRoot("bash", [ execRootSync("bash", [
"-c", "-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`, `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", stdio: "inherit",
}) })
await execa(cmake, ["--build", buildDir, "--config", "Release"], { cwd: out, 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 "user/local/bin" // the cmake install prefix
return out return out
} }

View File

@ -1,7 +1,7 @@
import { dirname } from "path" import { dirname } from "path"
import which from "which" import which from "which"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { execRoot } from "sudo-tools" import { execRootSync } from "sudo-tools"
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack" import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
let binDir: string | undefined let binDir: string | undefined
@ -26,7 +26,7 @@ export async function setupNala(version: string, _setupDir: string, _arch: strin
"volian-archive-scar-unstable.gpg", "volian-archive-scar-unstable.gpg",
"https://deb.volian.org/volian/scar.key" "https://deb.volian.org/volian/scar.key"
) )
execRoot("/bin/bash", [ execRootSync("/bin/bash", [
"-c", "-c",
`echo "deb [signed-by=${keyFileName}] http://deb.volian.org/volian/ scar main" | tee /etc/apt/sources.list.d/volian-archive-scar-unstable.list`, `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 { 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 /// change the owner to the SUDO_USER. This is required so the user can use the folder without sudo
export function folderUserAccess(folder: string) { export function folderUserAccess(folder: string) {
@ -8,6 +8,6 @@ export function folderUserAccess(folder: string) {
isSudo() && isSudo() &&
process.env.SUDO_USER !== undefined 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 */ /* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin" import { InstallationInfo } from "./setupBin"
import { execRoot } from "sudo-tools" import { execRootSync } from "sudo-tools"
import { info } from "@actions/core" import { info } from "@actions/core"
import { isGitHubCI } from "../env/isCI" import { isGitHubCI } from "../env/isCI"
import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv" import { addEnv, cpprc_path, setupCppInProfile } from "../env/addEnv"
@ -36,19 +36,19 @@ export async function setupAptPack(
if (Array.isArray(repositories) && repositories.length !== 0) { if (Array.isArray(repositories) && repositories.length !== 0) {
for (const repo of repositories) { for (const repo of repositories) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
execRoot("add-apt-repository", ["--update", "-y", repo]) execRootSync("add-apt-repository", ["--update", "-y", repo])
} }
updateRepos(apt) updateRepos(apt)
} }
if (version !== undefined && version !== "") { if (version !== undefined && version !== "") {
try { try {
execRoot(apt, ["install", "--fix-broken", "-y", `${name}=${version}`]) execRootSync(apt, ["install", "--fix-broken", "-y", `${name}=${version}`])
} catch { } catch {
execRoot(apt, ["install", "--fix-broken", "-y", `${name}-${version}`]) execRootSync(apt, ["install", "--fix-broken", "-y", `${name}-${version}`])
} }
} else { } else {
execRoot(apt, ["install", "--fix-broken", "-y", name]) execRootSync(apt, ["install", "--fix-broken", "-y", name])
} }
return { binDir: "/usr/bin/" } return { binDir: "/usr/bin/" }
@ -65,12 +65,12 @@ function getApt() {
} }
function updateRepos(apt: string) { 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) */ /** Install apt utils and certificates (usually missing from docker containers) */
async function initApt(apt: string) { async function initApt(apt: string) {
execRoot(apt, [ execRootSync(apt, [
"install", "install",
"--fix-broken", "--fix-broken",
"-y", "-y",
@ -89,7 +89,7 @@ async function initApt(apt: string) {
} }
function initGpg() { function initGpg() {
execRoot("gpg", ["-k"]) execRootSync("gpg", ["-k"])
} }
export function addAptKeyViaServer(keys: string[], name: string, server = "keyserver.ubuntu.com") { 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)) { if (!existsSync(fileName)) {
initGpg() initGpg()
for (const key of keys) { for (const key of keys) {
execRoot("gpg", [ execRootSync("gpg", [
"--no-default-keyring", "--no-default-keyring",
"--keyring", "--keyring",
`gnupg-ring:${fileName}`, `gnupg-ring:${fileName}`,
@ -106,7 +106,7 @@ export function addAptKeyViaServer(keys: string[], name: string, server = "keyse
"--recv-keys", "--recv-keys",
key, key,
]) ])
execRoot("chmod", ["644", fileName]) execRootSync("chmod", ["644", fileName])
} }
} }
return fileName return fileName
@ -117,15 +117,15 @@ export async function addAptKeyViaDownload(name: string, url: string) {
if (!existsSync(fileName)) { if (!existsSync(fileName)) {
initGpg() initGpg()
await setupAptPack("curl", undefined) await setupAptPack("curl", undefined)
execRoot("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`]) execRootSync("bash", ["-c", `curl -s ${url} | gpg --no-default-keyring --keyring gnupg-ring:${fileName} --import`])
execRoot("chmod", ["644", fileName]) execRootSync("chmod", ["644", fileName])
} }
return fileName return fileName
} }
export function updateAptAlternatives(name: string, path: string) { export function updateAptAlternatives(name: string, path: string) {
if (isGitHubCI()) { 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 { } else {
setupCppInProfile() setupCppInProfile()
return appendFileSync( return appendFileSync(

View File

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

View File

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