@linxin666/dsh-win-bash 0.0.0-stage → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/PROVENANCE.md +215 -0
- package/README.i18n.yaml +6 -0
- package/README.md +257 -2
- package/README.zh.md +217 -0
- package/cordis.patch.yml +13 -0
- package/lib/index.js +2697 -0
- package/lib/types/background.d.ts +169 -0
- package/lib/types/config.d.ts +130 -0
- package/lib/types/gate.d.ts +179 -0
- package/lib/types/index.d.ts +104 -0
- package/lib/types/protocol.d.ts +90 -0
- package/lib/types/pwsh-replacement.d.ts +140 -0
- package/lib/types/runtime.d.ts +115 -0
- package/lib/types/shell.d.ts +184 -0
- package/lib/types/tool.d.ts +108 -0
- package/package.json +58 -3
- package/runtime/win32-x64/checksums.sha256 +91 -0
- package/runtime/win32-x64/etc/bash.bashrc +69 -0
- package/runtime/win32-x64/etc/fstab +6 -0
- package/runtime/win32-x64/etc/msystem +27 -0
- package/runtime/win32-x64/etc/msystem.d/CLANG64 +7 -0
- package/runtime/win32-x64/etc/msystem.d/CLANGARM64 +7 -0
- package/runtime/win32-x64/etc/msystem.d/MINGW32 +7 -0
- package/runtime/win32-x64/etc/msystem.d/MINGW64 +7 -0
- package/runtime/win32-x64/etc/msystem.d/MSYS +4 -0
- package/runtime/win32-x64/etc/msystem.d/UCRT64 +7 -0
- package/runtime/win32-x64/etc/nsswitch.conf +12 -0
- package/runtime/win32-x64/etc/package-versions.txt +67 -0
- package/runtime/win32-x64/etc/profile +146 -0
- package/runtime/win32-x64/etc/profile.d/bash_profile.sh +11 -0
- package/runtime/win32-x64/etc/profile.d/lang.sh +19 -0
- package/runtime/win32-x64/licenses/GPL-2.0.txt +338 -0
- package/runtime/win32-x64/licenses/GPL-3.0.txt +674 -0
- package/runtime/win32-x64/licenses/LGPL-2.1.txt +501 -0
- package/runtime/win32-x64/licenses/LGPL-3.0.txt +165 -0
- package/runtime/win32-x64/licenses/expat-COPYING.txt +21 -0
- package/runtime/win32-x64/licenses/gcc-libs-RUNTIME.LIBRARY.EXCEPTION.txt +73 -0
- package/runtime/win32-x64/licenses/gettext-runtime-COPYING.LIB.txt +501 -0
- package/runtime/win32-x64/licenses/gettext-runtime-COPYING.txt +13 -0
- package/runtime/win32-x64/licenses/git-for-windows-LICENSE.txt +360 -0
- package/runtime/win32-x64/licenses/heimdal-LICENSE.txt +33 -0
- package/runtime/win32-x64/licenses/libcbor-LICENSE.md +21 -0
- package/runtime/win32-x64/licenses/libffi-LICENSE.txt +21 -0
- package/runtime/win32-x64/licenses/libfido2-LICENSE.txt +26 -0
- package/runtime/win32-x64/licenses/libiconv-COPYING.LIB.txt +501 -0
- package/runtime/win32-x64/licenses/libiconv-COPYING.txt +674 -0
- package/runtime/win32-x64/licenses/libopenssl-LICENSE.txt +177 -0
- package/runtime/win32-x64/licenses/libpcre-LICENCE.txt +93 -0
- package/runtime/win32-x64/licenses/libsqlite-LICENSE +25 -0
- package/runtime/win32-x64/licenses/ncurses-LICENSE +29 -0
- package/runtime/win32-x64/licenses/openssh-LICENCE.txt +412 -0
- package/runtime/win32-x64/licenses/zlib-LICENSE +22 -0
- package/runtime/win32-x64/usr/bin/awk.exe +0 -0
- package/runtime/win32-x64/usr/bin/b2sum.exe +0 -0
- package/runtime/win32-x64/usr/bin/basename.exe +0 -0
- package/runtime/win32-x64/usr/bin/basenc.exe +0 -0
- package/runtime/win32-x64/usr/bin/bash.exe +0 -0
- package/runtime/win32-x64/usr/bin/cat.exe +0 -0
- package/runtime/win32-x64/usr/bin/cmp.exe +0 -0
- package/runtime/win32-x64/usr/bin/comm.exe +0 -0
- package/runtime/win32-x64/usr/bin/cp.exe +0 -0
- package/runtime/win32-x64/usr/bin/cut.exe +0 -0
- package/runtime/win32-x64/usr/bin/dash.exe +0 -0
- package/runtime/win32-x64/usr/bin/date.exe +0 -0
- package/runtime/win32-x64/usr/bin/diff.exe +0 -0
- package/runtime/win32-x64/usr/bin/diff3.exe +0 -0
- package/runtime/win32-x64/usr/bin/dirname.exe +0 -0
- package/runtime/win32-x64/usr/bin/echo.exe +0 -0
- package/runtime/win32-x64/usr/bin/env.exe +0 -0
- package/runtime/win32-x64/usr/bin/expr.exe +0 -0
- package/runtime/win32-x64/usr/bin/false.exe +0 -0
- package/runtime/win32-x64/usr/bin/find.exe +0 -0
- package/runtime/win32-x64/usr/bin/grep.exe +0 -0
- package/runtime/win32-x64/usr/bin/head.exe +0 -0
- package/runtime/win32-x64/usr/bin/ls.exe +0 -0
- package/runtime/win32-x64/usr/bin/mkdir.exe +0 -0
- package/runtime/win32-x64/usr/bin/mktemp.exe +0 -0
- package/runtime/win32-x64/usr/bin/msys-2.0.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-gcc_s-seh-1.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-gmp-10.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-iconv-2.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-intl-8.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-mpfr-6.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-ncursesw6.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-pcre-1.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-readline8.dll +0 -0
- package/runtime/win32-x64/usr/bin/mv.exe +0 -0
- package/runtime/win32-x64/usr/bin/pathchk.exe +0 -0
- package/runtime/win32-x64/usr/bin/printf.exe +0 -0
- package/runtime/win32-x64/usr/bin/pwd.exe +0 -0
- package/runtime/win32-x64/usr/bin/readlink.exe +0 -0
- package/runtime/win32-x64/usr/bin/rm.exe +0 -0
- package/runtime/win32-x64/usr/bin/rmdir.exe +0 -0
- package/runtime/win32-x64/usr/bin/sdiff.exe +0 -0
- package/runtime/win32-x64/usr/bin/sed.exe +0 -0
- package/runtime/win32-x64/usr/bin/seq.exe +0 -0
- package/runtime/win32-x64/usr/bin/sh.exe +0 -0
- package/runtime/win32-x64/usr/bin/sleep.exe +0 -0
- package/runtime/win32-x64/usr/bin/sort.exe +0 -0
- package/runtime/win32-x64/usr/bin/tail.exe +0 -0
- package/runtime/win32-x64/usr/bin/test.exe +0 -0
- package/runtime/win32-x64/usr/bin/touch.exe +0 -0
- package/runtime/win32-x64/usr/bin/tr.exe +0 -0
- package/runtime/win32-x64/usr/bin/true.exe +0 -0
- package/runtime/win32-x64/usr/bin/uname.exe +0 -0
- package/runtime/win32-x64/usr/bin/uniq.exe +0 -0
- package/runtime/win32-x64/usr/bin/wc.exe +0 -0
- package/runtime/win32-x64/usr/bin/xargs.exe +0 -0
- package/src/background.ts +270 -0
- package/src/config.ts +209 -0
- package/src/gate.ts +308 -0
- package/src/index.ts +277 -0
- package/src/protocol.ts +130 -0
- package/src/pwsh-replacement.ts +435 -0
- package/src/runtime.ts +240 -0
- package/src/shell.ts +630 -0
- package/src/tool.ts +417 -0
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload resolution and load-time integrity verification for the vendored
|
|
3
|
+
* bash runtime.
|
|
4
|
+
*
|
|
5
|
+
* The package ships its own Git for Windows MinGit extraction under
|
|
6
|
+
* runtime/win32-x64/: the tool must NEVER fall back to a bash found on PATH
|
|
7
|
+
* (a host Git for Windows install, WSL, or a stray MSYS), because the whole
|
|
8
|
+
* point of vendoring is a shell whose version and bytes are pinned. Two
|
|
9
|
+
* invariants implement that:
|
|
10
|
+
*
|
|
11
|
+
* 1. the binary is addressed by absolute path inside the package, and
|
|
12
|
+
* 2. every vendored byte is checked against the SHA256 manifest generated at
|
|
13
|
+
* packaging time before the tool is mounted at all.
|
|
14
|
+
*
|
|
15
|
+
* A mismatch refuses the mount with a specific message. The alternative —
|
|
16
|
+
* mounting and hoping — would let a tampered or half-installed payload run
|
|
17
|
+
* model-authored commands, which is the one outcome the manifest exists to
|
|
18
|
+
* prevent.
|
|
19
|
+
* @module @linxin666/dsh-win-bash/runtime
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { createHash } from 'node:crypto'
|
|
23
|
+
import { readFileSync, statSync } from 'node:fs'
|
|
24
|
+
import { dirname, join, resolve } from 'node:path'
|
|
25
|
+
import { fileURLToPath } from 'node:url'
|
|
26
|
+
|
|
27
|
+
/** Directory holding the shipped payload, relative to the package root. */
|
|
28
|
+
export const RUNTIME_DIR = 'runtime/win32-x64'
|
|
29
|
+
|
|
30
|
+
/** Manifest file name inside {@link RUNTIME_DIR}. */
|
|
31
|
+
export const CHECKSUM_FILE = 'checksums.sha256'
|
|
32
|
+
|
|
33
|
+
/** The one platform this payload supports. */
|
|
34
|
+
export const RUNTIME_PLATFORM = 'win32'
|
|
35
|
+
|
|
36
|
+
/** The one architecture this payload supports. */
|
|
37
|
+
export const RUNTIME_ARCH = 'x64'
|
|
38
|
+
|
|
39
|
+
/** Absolute package root (the directory holding package.json). */
|
|
40
|
+
export const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
41
|
+
|
|
42
|
+
/** Absolute payload root. */
|
|
43
|
+
export function runtimeRoot(packageRoot: string = PACKAGE_ROOT): string {
|
|
44
|
+
return join(packageRoot, RUNTIME_DIR)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Absolute path of the vendored shell. */
|
|
48
|
+
export function bashPath(packageRoot: string = PACKAGE_ROOT): string {
|
|
49
|
+
return join(runtimeRoot(packageRoot), 'usr', 'bin', 'bash.exe')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Absolute path of the vendored POSIX-shell alias of the same binary. */
|
|
53
|
+
export function shPath(packageRoot: string = PACKAGE_ROOT): string {
|
|
54
|
+
return join(runtimeRoot(packageRoot), 'usr', 'bin', 'sh.exe')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Absolute path of the vendored payload's usr/bin directory. */
|
|
58
|
+
export function binDir(packageRoot: string = PACKAGE_ROOT): string {
|
|
59
|
+
return join(runtimeRoot(packageRoot), 'usr', 'bin')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** One manifest row: a payload-relative path and its digest. */
|
|
63
|
+
export interface ChecksumEntry {
|
|
64
|
+
/** Payload-relative path, using forward slashes. */
|
|
65
|
+
readonly path: string
|
|
66
|
+
/** Lowercase hex SHA256 of the file's bytes. */
|
|
67
|
+
readonly sha256: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Parse a sha256sum-style manifest: '<64 hex> <path>' per line. Blank lines
|
|
72
|
+
* and '#' comments are skipped, so the file stays a valid 'sha256sum -c'
|
|
73
|
+
* input while carrying a human-readable header.
|
|
74
|
+
* @param text - the manifest's contents.
|
|
75
|
+
* @returns parsed entries in file order.
|
|
76
|
+
* @throws when a non-comment line does not match the two-column shape.
|
|
77
|
+
*/
|
|
78
|
+
export function parseChecksums(text: string): ChecksumEntry[] {
|
|
79
|
+
const entries: ChecksumEntry[] = []
|
|
80
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
81
|
+
const line = raw.trim()
|
|
82
|
+
if (line === '' || line.startsWith('#')) continue
|
|
83
|
+
const match = /^([0-9a-f]{64})\s+(\S.*)$/.exec(line)
|
|
84
|
+
if (match === null) throw new Error('malformed checksum line: ' + line)
|
|
85
|
+
entries.push({ sha256: match[1], path: match[2] })
|
|
86
|
+
}
|
|
87
|
+
return entries
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** One payload file whose bytes did not match the manifest. */
|
|
91
|
+
export interface ChecksumMismatch {
|
|
92
|
+
/** Payload-relative path. */
|
|
93
|
+
readonly path: string
|
|
94
|
+
/** What the manifest records. */
|
|
95
|
+
readonly expected: string
|
|
96
|
+
/** What is on disk, or 'missing' when the file is absent. */
|
|
97
|
+
readonly actual: string
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Outcome of a full payload verification pass. */
|
|
101
|
+
export interface ChecksumReport {
|
|
102
|
+
/** Registered payload files that hashed correctly. */
|
|
103
|
+
readonly verified: number
|
|
104
|
+
/** Every file whose bytes or presence disagreed with the manifest. */
|
|
105
|
+
readonly mismatches: readonly ChecksumMismatch[]
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** SHA256 of a buffer or string, lowercase hex. */
|
|
109
|
+
export function sha256(bytes: Buffer | string): string {
|
|
110
|
+
return createHash('sha256').update(bytes).digest('hex')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Verify every registered payload file against the shipped manifest.
|
|
115
|
+
*
|
|
116
|
+
* Reads and hashes the whole payload (about 16 MiB after the curated
|
|
117
|
+
* extraction), which is why callers do it once at mount time rather than per
|
|
118
|
+
* command.
|
|
119
|
+
* @param packageRoot - package root holding runtime/win32-x64.
|
|
120
|
+
* @returns the count of verified files and every mismatch found.
|
|
121
|
+
* @throws when the manifest itself is unreadable or malformed.
|
|
122
|
+
*/
|
|
123
|
+
export function verifyPayload(packageRoot: string = PACKAGE_ROOT): ChecksumReport {
|
|
124
|
+
const root = runtimeRoot(packageRoot)
|
|
125
|
+
const manifest = parseChecksums(readFileSync(join(root, CHECKSUM_FILE), 'utf8'))
|
|
126
|
+
const mismatches: ChecksumMismatch[] = []
|
|
127
|
+
let verified = 0
|
|
128
|
+
for (const entry of manifest) {
|
|
129
|
+
const file = join(root, ...entry.path.split('/'))
|
|
130
|
+
let actual: string
|
|
131
|
+
try {
|
|
132
|
+
// A directory named like a manifest row must read as a mismatch, not
|
|
133
|
+
// crash the mount: statSync rejects directories before any read.
|
|
134
|
+
if (!statSync(file).isFile()) throw new Error('not a regular file')
|
|
135
|
+
actual = sha256(readFileSync(file))
|
|
136
|
+
} catch {
|
|
137
|
+
actual = 'missing'
|
|
138
|
+
}
|
|
139
|
+
if (actual === entry.sha256) verified += 1
|
|
140
|
+
else mismatches.push({ path: entry.path, expected: entry.sha256, actual })
|
|
141
|
+
}
|
|
142
|
+
return { verified, mismatches }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Why this deployment cannot serve the vendored shell. */
|
|
146
|
+
export interface RuntimeRejection {
|
|
147
|
+
/** Machine-readable reason. */
|
|
148
|
+
readonly code:
|
|
149
|
+
| 'unsupported-platform'
|
|
150
|
+
| 'unsupported-arch'
|
|
151
|
+
| 'missing-binary'
|
|
152
|
+
| 'checksum-mismatch'
|
|
153
|
+
| 'manifest-unreadable'
|
|
154
|
+
/** One-sentence, operator-facing explanation. */
|
|
155
|
+
readonly message: string
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Successful payload resolution. */
|
|
159
|
+
export interface RuntimeReady {
|
|
160
|
+
/** Absolute path of the vendored bash.exe. */
|
|
161
|
+
readonly bash: string
|
|
162
|
+
/** Absolute path of the payload's usr/bin. */
|
|
163
|
+
readonly bin: string
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Whether the running host can serve this payload at all. */
|
|
167
|
+
export interface HostPlatform {
|
|
168
|
+
/** process.platform. */
|
|
169
|
+
readonly platform: string
|
|
170
|
+
/** process.arch. */
|
|
171
|
+
readonly arch: string
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Resolve the vendored shell for one host, or refuse the mount.
|
|
176
|
+
*
|
|
177
|
+
* The order is deliberate: platform, then architecture, then presence, then
|
|
178
|
+
* integrity. A checksum failure names the first mismatching path so an
|
|
179
|
+
* operator can act on it, and no path here ever consults PATH.
|
|
180
|
+
* @param host - the running host's platform facts.
|
|
181
|
+
* @param packageRoot - package root holding the payload.
|
|
182
|
+
* @returns the resolved shell paths, or the rejection reason.
|
|
183
|
+
*/
|
|
184
|
+
export function resolveRuntime(
|
|
185
|
+
host: HostPlatform,
|
|
186
|
+
packageRoot: string = PACKAGE_ROOT,
|
|
187
|
+
): RuntimeReady | RuntimeRejection {
|
|
188
|
+
if (host.platform !== RUNTIME_PLATFORM) {
|
|
189
|
+
return {
|
|
190
|
+
code: 'unsupported-platform',
|
|
191
|
+
message:
|
|
192
|
+
'win_bash requires Windows: the vendored payload is a Git for Windows MinGit build for '
|
|
193
|
+
+ RUNTIME_PLATFORM
|
|
194
|
+
+ ' and there is no PATH fallback.',
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (host.arch !== RUNTIME_ARCH) {
|
|
198
|
+
return {
|
|
199
|
+
code: 'unsupported-arch',
|
|
200
|
+
message: 'win_bash currently ships only the ' + RUNTIME_ARCH + ' payload; this host is ' + host.arch + '.',
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const bash = bashPath(packageRoot)
|
|
204
|
+
try {
|
|
205
|
+
if (!statSync(bash).isFile()) throw new Error('not a file')
|
|
206
|
+
} catch {
|
|
207
|
+
return {
|
|
208
|
+
code: 'missing-binary',
|
|
209
|
+
message: 'the vendored payload is incomplete: ' + bash + ' is missing.',
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
let report: ChecksumReport
|
|
213
|
+
try {
|
|
214
|
+
report = verifyPayload(packageRoot)
|
|
215
|
+
} catch (error) {
|
|
216
|
+
return {
|
|
217
|
+
code: 'manifest-unreadable',
|
|
218
|
+
message:
|
|
219
|
+
'the payload checksum manifest could not be read: '
|
|
220
|
+
+ (error instanceof Error ? error.message : String(error)),
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (report.mismatches.length > 0) {
|
|
224
|
+
const first = report.mismatches[0]
|
|
225
|
+
return {
|
|
226
|
+
code: 'checksum-mismatch',
|
|
227
|
+
message:
|
|
228
|
+
'the vendored payload failed its SHA256 manifest: '
|
|
229
|
+
+ report.mismatches.length.toString()
|
|
230
|
+
+ ' file(s) differ, first '
|
|
231
|
+
+ first.path
|
|
232
|
+
+ ' (expected '
|
|
233
|
+
+ first.expected.slice(0, 12)
|
|
234
|
+
+ ', found '
|
|
235
|
+
+ first.actual.slice(0, 12)
|
|
236
|
+
+ '). Reinstall the package; win_bash will not run an unverified payload.',
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { bash, bin: binDir(packageRoot) }
|
|
240
|
+
}
|