feat: support installing multiple dnf packages

This commit is contained in:
Amin Yahyaabadi 2023-07-16 03:12:24 -07:00
parent dd9ff769c8
commit 41b2cf629a
20 changed files with 68 additions and 64 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -23,9 +23,9 @@ export async function setupBazel(version: string, _setupDir: string, _arch: stri
throw new Error("installing bazel on Arch linux is not supported yet")
} else if (hasDnf()) {
// https://bazel.build/install/redhat
setupDnfPack("dnf-plugins-core", undefined)
await setupDnfPack([{ name: "dnf-plugins-core" }])
execRootSync("dnf", ["copr", "enable", "vbatts/bazel"])
return setupDnfPack("bazel4", undefined)
return setupDnfPack([{ name: "bazel4" }])
} else if (isUbuntu()) {
// https://bazel.build/install/ubuntu
const keyFileName = await addAptKeyViaDownload(

View File

@ -20,7 +20,7 @@ export function setupCcache(version: string, _setupDir: string, _arch: string) {
if (isArch()) {
return setupPacmanPack("ccache", version)
} else if (hasDnf()) {
return setupDnfPack("ccache", version)
return setupDnfPack([{ name: "ccache", version }])
} else if (isUbuntu()) {
return setupAptPack([{ name: "ccache", version }])
}

View File

@ -23,7 +23,7 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
if (isArch()) {
return setupPacmanPack("cppcheck", version)
} else if (hasDnf()) {
return setupDnfPack("ccache", version)
return setupDnfPack([{ name: "ccache", version }])
} else if (isUbuntu()) {
return setupAptPack([{ name: "cppcheck", version }])
}

View File

@ -73,7 +73,7 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
if (isArch()) {
installationInfo = await setupPacmanPack("doxygen", version)
} else if (hasDnf()) {
return setupDnfPack("doxygen", version)
return setupDnfPack([{ name: "doxygen", version }])
} else if (isUbuntu()) {
installationInfo = await setupAptPack([{ name: "doxygen", version }])
} else {

View File

@ -98,9 +98,11 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
if (isArch()) {
installationInfo = await setupPacmanPack("gcc", version)
} else if (hasDnf()) {
installationInfo = setupDnfPack("gcc", version)
setupDnfPack("gcc-c++", version)
setupDnfPack("libstdc++-devel", undefined)
installationInfo = await setupDnfPack([
{ name: "gcc", version },
{ name: "gcc-c++", version },
{ name: "libstdc++-devel" },
])
} else if (isUbuntu()) {
installationInfo = await setupAptPack([
{ name: "gcc", version, repositories: ["ppa:ubuntu-toolchain-r/test"] },

View File

@ -23,7 +23,7 @@ export async function setupGraphviz(version: string, _setupDir: string, _arch: s
if (isArch()) {
return setupPacmanPack("graphviz", version)
} else if (hasDnf()) {
return setupDnfPack("graphviz", version)
return setupDnfPack([{ name: "graphviz", version }])
} else if (isUbuntu()) {
return setupAptPack([{ name: "graphviz", version }])
}

View File

@ -47,8 +47,7 @@ async function buildKcov(file: string, dest: string) {
if (isArch()) {
await Promise.all([setupPacmanPack("libdwarf"), setupPacmanPack("libcurl-openssl")])
} else if (hasDnf()) {
setupDnfPack("libdwarf-devel")
setupDnfPack("libcurl-devel")
await setupDnfPack([{ name: "libdwarf-devel" }, { name: "libcurl-devel" }])
} else if (isUbuntu()) {
await setupAptPack([{ name: "libdw-dev" }, { name: "libcurl4-openssl-dev" }])
}
@ -116,7 +115,7 @@ export async function setupKcov(versionGiven: string, setupDir: string, arch: st
if (isArch()) {
await setupPacmanPack("binutils")
} else if (hasDnf()) {
setupDnfPack("binutils")
await setupDnfPack([{ name: "binutils" }])
} else if (isUbuntu()) {
await setupAptPack([{ name: "libbinutils" }])
}

View File

@ -23,7 +23,7 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
if (isArch()) {
return setupPacmanPack("make", version)
} else if (hasDnf()) {
return setupDnfPack("make", version)
return setupDnfPack([{ name: "make", version }])
} else if (isUbuntu()) {
return setupAptPack([{ name: "make", version }])
}

View File

@ -26,12 +26,12 @@ export async function setupPowershell(version: string | undefined, _setupDir: st
if (isArch()) {
return setupPacmanPack("powershell-bin", version, "yay")
} else if (hasDnf()) {
setupDnfPack("curl")
setupDnfPack([{ name: "curl" }])
execRootSync("/bin/bash", [
"-c",
`curl https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo`,
])
return setupDnfPack("powershell", version)
return setupDnfPack([{ name: "powershell", version }])
} else if (isUbuntu()) {
await setupAptPack([{ name: "curl" }])
const ubuntuVerSplitted = (await ubuntuVersion())!

View File

@ -112,7 +112,7 @@ async function setupPythonSystem(setupDir: string, version: string) {
if (isArch()) {
installInfo = await setupPacmanPack("python", version)
} else if (hasDnf()) {
installInfo = setupDnfPack("python3", version)
installInfo = await setupDnfPack([{ name: "python3", version }])
} else if (isUbuntu()) {
installInfo = await setupAptPack([{ name: "python3", version }, { name: "python-is-python3" }])
} else {
@ -234,7 +234,7 @@ function setupPipSystem() {
if (isArch()) {
return setupPacmanPack("python-pip")
} else if (hasDnf()) {
return setupDnfPack("python3-pip")
return setupDnfPack([{ name: "python3-pip" }])
} else if (isUbuntu()) {
return setupAptPack([{ name: "python3-pip" }])
}

View File

@ -20,8 +20,10 @@ export function setupSevenZip(version: string, _setupDir: string, _arch: string)
if (isArch()) {
return setupPacmanPack("p7zip", version)
} else if (hasDnf()) {
setupDnfPack("p7zip", version)
return setupDnfPack("p7zip-plugins", version)
return setupDnfPack([
{ name: "p7zip", version },
{ name: "p7zip-plugins", version },
])
} else if (isUbuntu()) {
return setupAptPack([{ name: "p7zip-full", version }])
}

View File

@ -107,9 +107,7 @@ export async function setupBin(
if (isArch()) {
await Promise.all([setupPacmanPack("unzip"), setupPacmanPack("tar"), setupPacmanPack("xz")])
} else if (hasDnf()) {
setupDnfPack("unzip")
setupDnfPack("tar")
setupDnfPack("xz")
await setupDnfPack([{ name: "unzip" }, { name: "tar" }, { name: "xz" }])
} else if (isUbuntu()) {
await setupAptPack([{ name: "unzip" }, { name: "tar" }, { name: "xz-utils" }])
}

View File

@ -1,31 +1,35 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execRootSync } from "admina"
import { info, warning } from "ci-log"
import { execa } from "execa"
// let didUpdate: boolean = false
export type DnfPackage = {
name: string
version?: string
}
/** A function that installs a package using dnf */
export function setupDnfPack(name: string, version?: string): InstallationInfo {
info(`Installing ${name} ${version ?? ""} via dnf`)
const dnf = "dnf"
// if (!didUpdate) {
// execRootSync(dnf, ["-y", "check-update"])
// didUpdate = true
// }
if (version !== undefined && version !== "") {
try {
execRootSync(dnf, ["-y", "install", `${name}-${version}`])
} catch (err) {
warning(`${(err as Error).toString()}\nInstalling the default version available via dnf`)
execRootSync(dnf, ["-y", "install", name])
}
} else {
execRootSync(dnf, ["-y", "install", name])
export async function setupDnfPack(packages: DnfPackage[]): Promise<InstallationInfo> {
for (const { name, version } of packages) {
info(`Installing ${name} ${version ?? ""} via dnf`)
}
const dnfArgs = await Promise.all(packages.map((pack) => getDnfArg(pack.name, pack.version)))
execRootSync("dnf", ["-y", "install", ...dnfArgs])
return { binDir: "/usr/bin/" }
}
async function getDnfArg(name: string, version: string | undefined) {
if (version !== undefined && version !== "") {
// check if name-version is available
const { stdout } = await execa("dnf", ["search", `${name}-${version}`, "--exact", "--quiet"])
if (stdout.trim() !== "") {
return `${name}-${version}`
} else {
warning(`Failed to install ${name} ${version} via dnf, trying without version`)
}
}
return name
}

View File

@ -30,12 +30,14 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
setupPacmanPack("pkg-config"),
])
} else if (hasDnf()) {
setupDnfPack("curl")
setupDnfPack("zip")
setupDnfPack("unzip")
setupDnfPack("tar")
setupDnfPack("git")
setupDnfPack("pkg-config")
await setupDnfPack([
{ name: "curl" },
{ name: "zip" },
{ name: "unzip" },
{ name: "tar" },
{ name: "git" },
{ name: "pkg-config" },
])
} else if (isUbuntu()) {
await setupAptPack([
{ name: "curl" },