fix: use sudo if available on linux

This commit is contained in:
Amin Yahyaabadi 2021-09-16 04:08:10 -05:00
parent c6aac2897f
commit edbc293b98
1 changed files with 5 additions and 2 deletions

View File

@ -5,12 +5,15 @@ let didUpdate: boolean = false
/** A function that installs a package using apt */
export async function setupAptPack(name: string, version?: string, updateRepositories: boolean = true) {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition
const apt = process.env.CI || process.getuid?.() === 0 ? "sudo apt-get" : "apt-get"
if (!didUpdate || updateRepositories) {
await exec("apt-get", ["update"])
await exec(apt, ["update"])
didUpdate = true
}
const exit = await exec("apt-get", ["install", version !== undefined ? `${name}=${version}` : name])
const exit = await exec(apt, ["install", version !== undefined ? `${name}=${version}` : name])
if (exit !== 0) {
throw new Error(`Failed to install ${name} ${version}`)