From e495d4d0d5a0aa44109122cc15713544d5c22cb1 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 7 Aug 2022 17:33:11 -0700 Subject: [PATCH] fix: rename execRoot to execRootSync --- packages/sudo-tools/src/index.ts | 6 +++++- src/bazel/bazel.ts | 6 +++--- src/kcov/kcov.ts | 2 +- src/nala/nala.ts | 4 ++-- src/utils/fs/userAccess.ts | 4 ++-- src/utils/setup/setupAptPack.ts | 26 +++++++++++++------------- src/utils/setup/setupDnfPack.ts | 10 +++++----- src/utils/setup/setupPacmanPack.ts | 12 ++++++------ 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/packages/sudo-tools/src/index.ts b/packages/sudo-tools/src/index.ts index c624c003..f0fd3d8d 100644 --- a/packages/sudo-tools/src/index.ts +++ b/packages/sudo-tools/src/index.ts @@ -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 { diff --git a/src/bazel/bazel.ts b/src/bazel/bazel.ts index ec58ddcc..0d018f3f 100644 --- a/src/bazel/bazel.ts +++ b/src/bazel/bazel.ts @@ -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`, ]) diff --git a/src/kcov/kcov.ts b/src/kcov/kcov.ts index 6e114c0a..a49efe45 100644 --- a/src/kcov/kcov.ts +++ b/src/kcov/kcov.ts @@ -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 } diff --git a/src/nala/nala.ts b/src/nala/nala.ts index f3355c30..bbbfb66b 100644 --- a/src/nala/nala.ts +++ b/src/nala/nala.ts @@ -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`, ]) diff --git a/src/utils/fs/userAccess.ts b/src/utils/fs/userAccess.ts index 8b1c47cc..30a1afd0 100644 --- a/src/utils/fs/userAccess.ts +++ b/src/utils/fs/userAccess.ts @@ -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" }) } } diff --git a/src/utils/setup/setupAptPack.ts b/src/utils/setup/setupAptPack.ts index bab7b891..1a09dc1c 100644 --- a/src/utils/setup/setupAptPack.ts +++ b/src/utils/setup/setupAptPack.ts @@ -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( diff --git a/src/utils/setup/setupDnfPack.ts b/src/utils/setup/setupDnfPack.ts index 9f4c86ee..8280a96c 100644 --- a/src/utils/setup/setupDnfPack.ts +++ b/src/utils/setup/setupDnfPack.ts @@ -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/" } diff --git a/src/utils/setup/setupPacmanPack.ts b/src/utils/setup/setupPacmanPack.ts index 12e9ffb3..6148d1a1 100644 --- a/src/utils/setup/setupPacmanPack.ts +++ b/src/utils/setup/setupPacmanPack.ts @@ -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/" }