|
| 1 | +import { info } from "ci-log" |
| 2 | +import { hasApk, installApkPack } from "setup-alpine" |
| 3 | +import { hasAptGet, installAptPack } from "setup-apt" |
| 4 | +import { installBrewPack } from "setup-brew" |
| 5 | +import which from "which" |
| 6 | +import { hasDnf } from "../utils/env/hasDnf.js" |
| 7 | +import { isArch } from "../utils/env/isArch.js" |
| 8 | +import { setupBin } from "../utils/setup/setupBin.js" |
| 9 | +import { setupDnfPack } from "../utils/setup/setupDnfPack.js" |
| 10 | +import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js" |
| 11 | + |
| 12 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 13 | +export async function setupTar(version: string, setupDir: string, arch: string) { |
| 14 | + const tar = await which("tar", { nothrow: true }) |
| 15 | + if (tar !== null) { |
| 16 | + info(`tar already installed at ${tar}`) |
| 17 | + return |
| 18 | + } |
| 19 | + |
| 20 | + switch (process.platform) { |
| 21 | + case "win32": { |
| 22 | + // install tar from GnuWin |
| 23 | + // https://phoenixnap.dl.sourceforge.net/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip?viasf=1 |
| 24 | + return setupBin( |
| 25 | + "tar", |
| 26 | + "1.13-1", |
| 27 | + () => { |
| 28 | + return { |
| 29 | + url: "https://phoenixnap.dl.sourceforge.net/project/gnuwin32/tar/1.13-1/tar-1.13-1-bin.zip?viasf=1", |
| 30 | + extractedFolderName: "", |
| 31 | + binRelativeDir: "bin", |
| 32 | + binFileName: "tar.exe", |
| 33 | + } |
| 34 | + }, |
| 35 | + setupDir, |
| 36 | + arch, |
| 37 | + ) |
| 38 | + } |
| 39 | + case "darwin": { |
| 40 | + // installs as gtar |
| 41 | + return installBrewPack("gnu-tar", version) |
| 42 | + } |
| 43 | + case "linux": { |
| 44 | + if (isArch()) { |
| 45 | + await setupPacmanPack("gzip") |
| 46 | + await setupPacmanPack("xz") |
| 47 | + return setupPacmanPack("tar") |
| 48 | + } else if (hasDnf()) { |
| 49 | + return setupDnfPack([{ name: "tar" }, { name: "gzip" }, { name: "xz" }]) |
| 50 | + } else if (hasAptGet()) { |
| 51 | + return installAptPack([{ name: "tar" }, { name: "gzip" }, { name: "xz-utils" }]) |
| 52 | + } else if (await hasApk()) { |
| 53 | + return installApkPack([{ name: "tar" }, { name: "gzip" }, { name: "xz" }]) |
| 54 | + } |
| 55 | + throw new Error("Unsupported linux distribution") |
| 56 | + } |
| 57 | + default: { |
| 58 | + throw new Error("Unsupported platform") |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments