-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpowershell.ts
65 lines (61 loc) · 2.63 KB
/
powershell.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { execRootSync } from "admina"
import { addPath } from "envosman"
import { installAptPack } from "setup-apt"
import { rcOptions } from "../cli-options.js"
import { hasDnf } from "../utils/env/hasDnf.js"
import { isArch } from "../utils/env/isArch.js"
import { isUbuntu } from "../utils/env/isUbuntu.js"
import { ubuntuVersion } from "../utils/env/ubuntu_version.js"
import { setupBrewPack } from "../utils/setup/setupBrewPack.js"
import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupPowershell(version: string | undefined, _setupDir: string, _arch: string) {
switch (process.platform) {
case "win32": {
await setupChocoPack("powershell-core", version)
const binDir = "C:/Program Files/PowerShell/7"
await addPath(binDir, rcOptions)
return { binDir }
}
case "darwin": {
return setupBrewPack("powershell", version, { cask: true, overwrite: false })
}
case "linux": {
if (isArch()) {
return setupPacmanPack("powershell-bin", version, "yay")
} else if (hasDnf()) {
await 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([{ name: "powershell", version }])
} else if (isUbuntu()) {
await installAptPack([{ name: "curl" }])
const ubuntuVerSplitted = (await ubuntuVersion())!
const ubuntuVersionString = `${ubuntuVerSplitted[0]}.0${ubuntuVerSplitted[1]}`
execRootSync("curl", [
"-LJO",
`https://packages.microsoft.com/config/ubuntu/${ubuntuVersionString}/packages-microsoft-prod.deb`,
])
execRootSync("dpkg", ["-i", "packages-microsoft-prod.deb"])
// TODO Debian
// const keyFileName = await addAptKeyViaDownload(
// "microsoft.asc",
// "https://packages.microsoft.com/keys/microsoft.asc"
// )
// execRootSync("/bin/bash", [
// "-c",
// `echo "deb [arch=amd64 signed-by=${keyFileName}] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list`,
// ])
return installAptPack([{ name: "powershell", version }], true)
}
throw new Error("Unsupported linux distribution")
}
default: {
throw new Error("Unsupported platform")
}
}
}