Repository navigation
Expand file tree
/
Copy pathpowershell.ts
More file actions
98 lines (85 loc) · 3.18 KB
/
Copy pathpowershell.ts
File metadata and controls
98 lines (85 loc) · 3.18 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { injectFromHierarchy, injectable } from 'inversify';
import { BaseInstallService } from '../../install-tool/base-install.service.ts';
import { BasePrepareService } from '../../prepare-tool/base-prepare.service.ts';
import { semverGte } from '../../utils/index.ts';
/**
* The distro specific dependencies.
* @see {@link https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-install?tabs=dotnet10&pivots=os-linux-ubuntu-2204#dependencies-4}
*/
const distroPackages: Record<string, string[] | undefined> = {
jammy: ['libicu70', 'libssl3'],
noble: ['libicu74', 'libssl3t64'],
resolute: ['libbrotli1', 'libicu78', 'libssl3t64'],
};
@injectable()
@injectFromHierarchy()
export class PowershellPrepareService extends BasePrepareService {
override readonly name = 'powershell';
/**
* Installs the apt packages powershell needs on the current ubuntu release.
*
* @throws on an unsupported distro
*/
override async prepare(): Promise<void> {
await this.installDistroPackages(
distroPackages,
'libc6',
'libgcc-s1',
'libgssapi-krb5-2',
'libstdc++6',
'tzdata',
'zlib1g',
);
}
}
@injectable()
@injectFromHierarchy()
export class PowershellInstallService extends BaseInstallService {
override readonly name = 'powershell';
/**
* Older versions run on .NET before 6, which can't load OpenSSL 3, so any
* HTTPS call aborts; before 7.1 they don't start at all.
*/
override readonly minVersion = '7.2.0';
/** The architecture name used by the powershell release assets. */
private get ghArch(): string {
return this.envSvc.arch === 'arm64' ? 'arm64' : 'x64';
}
/**
* Downloads the powershell archive from GitHub and extracts it into the
* versioned tool path. The file and its checksum come from the
* tool-versions data, without data it is verified against the release's
* `hashes.sha256` since v7.2.0.
*/
override async install(version: string): Promise<void> {
const baseUrl = `https://github.com/PowerShell/PowerShell/releases/download/v${version}/`;
const filename = `${this.name}-${version}-linux-${this.ghArch}.tar.gz`;
// powershell only publishes a `hashes.sha256` checksum file since v7.2.0.
const file = semverGte(version, '7.2.0')
? await this.downloadChecksumListed(
version,
baseUrl,
filename,
'hashes.sha256',
)
: await this.downloadWithoutChecksum(version, `${baseUrl}${filename}`);
await this.pathSvc.ensureToolPath(this.name);
const path = await this.pathSvc.createVersionedToolPath(this.name, version);
await this.compress.extract({ file, cwd: path });
// Happened on v7.3.0
await fs.chmod(join(path, 'pwsh'), this.envSvc.umask);
}
/** Links the `pwsh` binary into the global bin folder. */
override async link(version: string): Promise<void> {
await this.shellwrapper({
name: 'pwsh',
srcDir: this.pathSvc.versionedToolPath(this.name, version),
});
}
/** Checks that `pwsh -version` runs. */
override async test(_version: string): Promise<void> {
await this._spawn('pwsh', ['-version']);
}
}