typescript-virtual-container 1.2.9 → 1.3.0
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/.vscode/settings.json +0 -1
- package/README.md +141 -50
- package/biome.json +7 -0
- package/dist/SSHMimic/exec.d.ts.map +1 -1
- package/dist/SSHMimic/executor.d.ts.map +1 -1
- package/dist/SSHMimic/executor.js +32 -16
- package/dist/SSHMimic/index.d.ts.map +1 -1
- package/dist/SSHMimic/index.js +20 -6
- package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -1
- package/dist/VirtualFileSystem/binaryPack.js +29 -6
- package/dist/VirtualFileSystem/index.d.ts.map +1 -1
- package/dist/VirtualFileSystem/index.js +36 -13
- package/dist/VirtualPackageManager/index.d.ts.map +1 -1
- package/dist/VirtualPackageManager/index.js +192 -43
- package/dist/VirtualShell/index.d.ts +10 -4
- package/dist/VirtualShell/index.d.ts.map +1 -1
- package/dist/VirtualShell/index.js +18 -7
- package/dist/VirtualShell/shell.d.ts.map +1 -1
- package/dist/VirtualShell/shell.js +3 -1
- package/dist/VirtualShell/shellParser.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.d.ts.map +1 -1
- package/dist/commands/adduser.d.ts +6 -0
- package/dist/commands/adduser.d.ts.map +1 -1
- package/dist/commands/adduser.js +6 -0
- package/dist/commands/alias.d.ts +5 -0
- package/dist/commands/alias.d.ts.map +1 -1
- package/dist/commands/alias.js +5 -0
- package/dist/commands/apt.d.ts +5 -0
- package/dist/commands/apt.d.ts.map +1 -1
- package/dist/commands/apt.js +32 -9
- package/dist/commands/awk.d.ts +11 -0
- package/dist/commands/awk.d.ts.map +1 -1
- package/dist/commands/awk.js +15 -2
- package/dist/commands/base64.d.ts +5 -0
- package/dist/commands/base64.d.ts.map +1 -1
- package/dist/commands/base64.js +9 -1
- package/dist/commands/cat.d.ts +5 -0
- package/dist/commands/cat.d.ts.map +1 -1
- package/dist/commands/cat.js +10 -2
- package/dist/commands/cd.d.ts +5 -0
- package/dist/commands/cd.d.ts.map +1 -1
- package/dist/commands/cd.js +5 -0
- package/dist/commands/chmod.d.ts +5 -0
- package/dist/commands/chmod.d.ts.map +1 -1
- package/dist/commands/chmod.js +5 -0
- package/dist/commands/cp.d.ts +5 -0
- package/dist/commands/cp.d.ts.map +1 -1
- package/dist/commands/cp.js +5 -0
- package/dist/commands/curl.d.ts +5 -0
- package/dist/commands/curl.d.ts.map +1 -1
- package/dist/commands/curl.js +34 -6
- package/dist/commands/cut.d.ts +5 -0
- package/dist/commands/cut.d.ts.map +1 -1
- package/dist/commands/cut.js +8 -1
- package/dist/commands/date.d.ts +5 -0
- package/dist/commands/date.d.ts.map +1 -1
- package/dist/commands/date.js +7 -1
- package/dist/commands/declare.d.ts +3 -0
- package/dist/commands/declare.d.ts.map +1 -0
- package/dist/commands/declare.js +39 -0
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +5 -0
- package/dist/commands/dpkg.d.ts +5 -0
- package/dist/commands/dpkg.d.ts.map +1 -1
- package/dist/commands/dpkg.js +24 -7
- package/dist/commands/du.d.ts.map +1 -1
- package/dist/commands/du.js +8 -2
- package/dist/commands/echo.d.ts +5 -0
- package/dist/commands/echo.d.ts.map +1 -1
- package/dist/commands/echo.js +13 -4
- package/dist/commands/env.d.ts +5 -0
- package/dist/commands/env.d.ts.map +1 -1
- package/dist/commands/env.js +11 -1
- package/dist/commands/exit.d.ts +5 -0
- package/dist/commands/exit.d.ts.map +1 -1
- package/dist/commands/exit.js +12 -2
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +3 -1
- package/dist/commands/find.d.ts +5 -0
- package/dist/commands/find.d.ts.map +1 -1
- package/dist/commands/find.js +5 -0
- package/dist/commands/free.d.ts +5 -0
- package/dist/commands/free.d.ts.map +1 -1
- package/dist/commands/free.js +5 -0
- package/dist/commands/grep.d.ts +5 -0
- package/dist/commands/grep.d.ts.map +1 -1
- package/dist/commands/grep.js +12 -2
- package/dist/commands/gzip.d.ts +5 -0
- package/dist/commands/gzip.d.ts.map +1 -1
- package/dist/commands/gzip.js +18 -2
- package/dist/commands/head.d.ts +5 -0
- package/dist/commands/head.d.ts.map +1 -1
- package/dist/commands/head.js +5 -0
- package/dist/commands/help.d.ts.map +1 -1
- package/dist/commands/help.js +98 -45
- package/dist/commands/history.d.ts +5 -0
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +5 -0
- package/dist/commands/hostname.d.ts +5 -0
- package/dist/commands/hostname.d.ts.map +1 -1
- package/dist/commands/hostname.js +5 -0
- package/dist/commands/id.d.ts.map +1 -1
- package/dist/commands/id.js +4 -1
- package/dist/commands/index.d.ts +2 -17
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -340
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +3 -1
- package/dist/commands/lsb-release.d.ts.map +1 -1
- package/dist/commands/lsb-release.js +8 -2
- package/dist/commands/nano.js +1 -1
- package/dist/commands/neofetch.js +1 -1
- package/dist/commands/node.d.ts +9 -0
- package/dist/commands/node.d.ts.map +1 -0
- package/dist/commands/node.js +316 -0
- package/dist/commands/npm.d.ts +19 -0
- package/dist/commands/npm.d.ts.map +1 -0
- package/dist/commands/npm.js +109 -0
- package/dist/commands/ping.d.ts.map +1 -1
- package/dist/commands/ping.js +3 -1
- package/dist/commands/printf.d.ts +3 -0
- package/dist/commands/printf.d.ts.map +1 -0
- package/dist/commands/printf.js +113 -0
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +4 -1
- package/dist/commands/python.d.ts +30 -0
- package/dist/commands/python.d.ts.map +1 -0
- package/dist/commands/python.js +2058 -0
- package/dist/commands/read.d.ts +3 -0
- package/dist/commands/read.d.ts.map +1 -0
- package/dist/commands/read.js +34 -0
- package/dist/commands/registry.d.ts +8 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +229 -0
- package/dist/commands/runtime.d.ts +6 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +280 -0
- package/dist/commands/sed.d.ts.map +1 -1
- package/dist/commands/sed.js +11 -3
- package/dist/commands/set.d.ts.map +1 -1
- package/dist/commands/set.js +9 -3
- package/dist/commands/sh.d.ts.map +1 -1
- package/dist/commands/sh.js +57 -36
- package/dist/commands/shift.d.ts +5 -0
- package/dist/commands/shift.d.ts.map +1 -0
- package/dist/commands/shift.js +52 -0
- package/dist/commands/sleep.d.ts.map +1 -1
- package/dist/commands/sort.d.ts.map +1 -1
- package/dist/commands/sort.js +4 -2
- package/dist/commands/source.d.ts.map +1 -1
- package/dist/commands/source.js +5 -2
- package/dist/commands/sudo.js +1 -1
- package/dist/commands/tar.d.ts.map +1 -1
- package/dist/commands/tar.js +11 -3
- package/dist/commands/tee.d.ts.map +1 -1
- package/dist/commands/tee.js +8 -6
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +46 -24
- package/dist/commands/tr.d.ts.map +1 -1
- package/dist/commands/tr.js +3 -1
- package/dist/commands/true.d.ts +4 -0
- package/dist/commands/true.d.ts.map +1 -0
- package/dist/commands/true.js +14 -0
- package/dist/commands/type.d.ts.map +1 -1
- package/dist/commands/type.js +1 -1
- package/dist/commands/uname.d.ts.map +1 -1
- package/dist/commands/uname.js +4 -1
- package/dist/commands/uniq.d.ts.map +1 -1
- package/dist/commands/uptime.d.ts.map +1 -1
- package/dist/commands/uptime.js +4 -1
- package/dist/commands/wget.d.ts.map +1 -1
- package/dist/commands/wget.js +32 -7
- package/dist/commands/which.d.ts.map +1 -1
- package/dist/commands/xargs.d.ts.map +1 -1
- package/dist/commands/xargs.js +1 -1
- package/dist/index.d.ts +15 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/modules/linuxRootfs.d.ts +18 -1
- package/dist/modules/linuxRootfs.d.ts.map +1 -1
- package/dist/modules/linuxRootfs.js +160 -17
- package/dist/standalone-wo-sftp.d.ts +2 -0
- package/dist/standalone-wo-sftp.d.ts.map +1 -0
- package/dist/standalone-wo-sftp.js +30 -0
- package/dist/utils/expand.d.ts +50 -0
- package/dist/utils/expand.d.ts.map +1 -0
- package/dist/utils/expand.js +183 -0
- package/dist/utils/vfsDiff.d.ts +90 -0
- package/dist/utils/vfsDiff.d.ts.map +1 -0
- package/dist/utils/vfsDiff.js +177 -0
- package/package.json +2 -1
- package/src/SSHMimic/exec.ts +10 -1
- package/src/SSHMimic/executor.ts +104 -18
- package/src/SSHMimic/index.ts +49 -15
- package/src/VirtualFileSystem/binaryPack.ts +35 -8
- package/src/VirtualFileSystem/index.ts +78 -28
- package/src/VirtualPackageManager/index.ts +208 -49
- package/src/VirtualShell/index.ts +35 -7
- package/src/VirtualShell/shell.ts +23 -3
- package/src/VirtualShell/shellParser.ts +134 -36
- package/src/VirtualUserManager/index.ts +7 -2
- package/src/commands/adduser.ts +6 -0
- package/src/commands/alias.ts +5 -1
- package/src/commands/apt.ts +47 -17
- package/src/commands/awk.ts +20 -6
- package/src/commands/base64.ts +13 -2
- package/src/commands/cat.ts +13 -5
- package/src/commands/cd.ts +5 -0
- package/src/commands/chmod.ts +5 -0
- package/src/commands/cp.ts +5 -0
- package/src/commands/curl.ts +56 -12
- package/src/commands/cut.ts +8 -1
- package/src/commands/date.ts +7 -1
- package/src/commands/declare.ts +44 -0
- package/src/commands/diff.ts +17 -3
- package/src/commands/dpkg.ts +33 -11
- package/src/commands/du.ts +17 -5
- package/src/commands/echo.ts +22 -9
- package/src/commands/env.ts +11 -1
- package/src/commands/exit.ts +12 -2
- package/src/commands/export.ts +3 -1
- package/src/commands/find.ts +5 -0
- package/src/commands/free.ts +9 -2
- package/src/commands/grep.ts +12 -2
- package/src/commands/gzip.ts +28 -4
- package/src/commands/head.ts +5 -0
- package/src/commands/help.ts +121 -47
- package/src/commands/history.ts +7 -2
- package/src/commands/hostname.ts +5 -0
- package/src/commands/id.ts +4 -1
- package/src/commands/index.ts +9 -360
- package/src/commands/ls.ts +5 -3
- package/src/commands/lsb-release.ts +8 -2
- package/src/commands/nano.ts +1 -1
- package/src/commands/neofetch.ts +1 -1
- package/src/commands/node.ts +341 -0
- package/src/commands/npm.ts +132 -0
- package/src/commands/ping.ts +6 -2
- package/src/commands/printf.ts +112 -0
- package/src/commands/ps.ts +21 -9
- package/src/commands/python.ts +2229 -0
- package/src/commands/read.ts +41 -0
- package/src/commands/registry.ts +244 -0
- package/src/commands/runtime.ts +353 -0
- package/src/commands/sed.ts +27 -9
- package/src/commands/set.ts +9 -3
- package/src/commands/sh.ts +159 -55
- package/src/commands/shift.ts +53 -0
- package/src/commands/sleep.ts +2 -1
- package/src/commands/sort.ts +10 -6
- package/src/commands/source.ts +15 -3
- package/src/commands/sudo.ts +1 -1
- package/src/commands/tar.ts +28 -7
- package/src/commands/tee.ts +7 -1
- package/src/commands/test.ts +61 -26
- package/src/commands/tr.ts +3 -1
- package/src/commands/true.ts +17 -0
- package/src/commands/type.ts +6 -3
- package/src/commands/uname.ts +5 -1
- package/src/commands/uniq.ts +8 -2
- package/src/commands/uptime.ts +4 -1
- package/src/commands/wget.ts +51 -12
- package/src/commands/which.ts +5 -2
- package/src/commands/xargs.ts +11 -2
- package/src/index.ts +23 -24
- package/src/modules/linuxRootfs.ts +233 -30
- package/src/standalone-wo-sftp.ts +38 -0
- package/src/utils/expand.ts +238 -0
- package/src/utils/vfsDiff.ts +275 -0
- package/standalone-wo-sftp.js +507 -0
- package/standalone-wo-sftp.js.map +7 -0
- package/standalone.js +253 -191
- package/standalone.js.map +4 -4
- package/tests/bun-test-shim.ts +9 -1
- package/tests/command-helpers.test.ts +1 -5
- package/tests/new-features.test.ts +415 -5
- package/tests/parser-executor.test.ts +27 -27
- package/tests/sftp.test.ts +122 -42
- package/tests/users.test.ts +23 -5
- package/CHANGELOG.md +0 -150
package/src/commands/test.ts
CHANGED
|
@@ -6,7 +6,11 @@ import type { ShellModule } from "../types/commands";
|
|
|
6
6
|
* string =, !=, numeric -eq -ne -lt -le -gt -ge,
|
|
7
7
|
* ! (negate), -a (and), -o (or).
|
|
8
8
|
*/
|
|
9
|
-
function evalTest(
|
|
9
|
+
function evalTest(
|
|
10
|
+
tokens: string[],
|
|
11
|
+
shell: import("../VirtualShell").VirtualShell,
|
|
12
|
+
cwd: string,
|
|
13
|
+
): boolean {
|
|
10
14
|
// When called via [ command, ] is the last arg — strip it
|
|
11
15
|
// When called via test command, no brackets present
|
|
12
16
|
if (tokens[tokens.length - 1] === "]") {
|
|
@@ -25,32 +29,53 @@ function evalTest(tokens: string[], shell: import("../VirtualShell").VirtualShel
|
|
|
25
29
|
// Boolean -a / -o (simple left-right, no precedence)
|
|
26
30
|
const andIdx = tokens.indexOf("-a");
|
|
27
31
|
if (andIdx !== -1) {
|
|
28
|
-
return
|
|
29
|
-
evalTest(tokens.slice(andIdx
|
|
32
|
+
return (
|
|
33
|
+
evalTest(tokens.slice(0, andIdx), shell, cwd) &&
|
|
34
|
+
evalTest(tokens.slice(andIdx + 1), shell, cwd)
|
|
35
|
+
);
|
|
30
36
|
}
|
|
31
37
|
const orIdx = tokens.indexOf("-o");
|
|
32
38
|
if (orIdx !== -1) {
|
|
33
|
-
return
|
|
34
|
-
evalTest(tokens.slice(orIdx
|
|
39
|
+
return (
|
|
40
|
+
evalTest(tokens.slice(0, orIdx), shell, cwd) ||
|
|
41
|
+
evalTest(tokens.slice(orIdx + 1), shell, cwd)
|
|
42
|
+
);
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
// Unary file tests
|
|
38
46
|
if (tokens.length === 2) {
|
|
39
47
|
const [flag, operand = ""] = tokens;
|
|
40
|
-
const resolvePath = (p: string) =>
|
|
48
|
+
const resolvePath = (p: string) =>
|
|
49
|
+
p.startsWith("/") ? p : `${cwd}/${p}`.replace(/\/+/g, "/");
|
|
41
50
|
const path = resolvePath(operand);
|
|
42
51
|
|
|
43
52
|
switch (flag) {
|
|
44
|
-
case "-e":
|
|
45
|
-
|
|
46
|
-
case "-
|
|
47
|
-
|
|
48
|
-
case "-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
case "-
|
|
53
|
-
|
|
53
|
+
case "-e":
|
|
54
|
+
return shell.vfs.exists(path);
|
|
55
|
+
case "-f":
|
|
56
|
+
return shell.vfs.exists(path) && shell.vfs.stat(path).type === "file";
|
|
57
|
+
case "-d":
|
|
58
|
+
return (
|
|
59
|
+
shell.vfs.exists(path) && shell.vfs.stat(path).type === "directory"
|
|
60
|
+
);
|
|
61
|
+
case "-r":
|
|
62
|
+
return shell.vfs.exists(path); // all readable in virtual env
|
|
63
|
+
case "-w":
|
|
64
|
+
return shell.vfs.exists(path);
|
|
65
|
+
case "-x":
|
|
66
|
+
return shell.vfs.exists(path) && !!(shell.vfs.stat(path).mode & 0o111);
|
|
67
|
+
case "-s":
|
|
68
|
+
return (
|
|
69
|
+
shell.vfs.exists(path) &&
|
|
70
|
+
shell.vfs.stat(path).type === "file" &&
|
|
71
|
+
(shell.vfs.stat(path) as import("../types/vfs").VfsFileNode).size > 0
|
|
72
|
+
);
|
|
73
|
+
case "-z":
|
|
74
|
+
return operand.length === 0;
|
|
75
|
+
case "-n":
|
|
76
|
+
return operand.length > 0;
|
|
77
|
+
case "-L":
|
|
78
|
+
return shell.vfs.isSymlink(path);
|
|
54
79
|
}
|
|
55
80
|
}
|
|
56
81
|
|
|
@@ -63,17 +88,27 @@ function evalTest(tokens: string[], shell: import("../VirtualShell").VirtualShel
|
|
|
63
88
|
switch (op) {
|
|
64
89
|
// String
|
|
65
90
|
case "=":
|
|
66
|
-
case "==":
|
|
67
|
-
|
|
68
|
-
case "
|
|
69
|
-
|
|
91
|
+
case "==":
|
|
92
|
+
return left === right;
|
|
93
|
+
case "!=":
|
|
94
|
+
return left !== right;
|
|
95
|
+
case "<":
|
|
96
|
+
return left < right;
|
|
97
|
+
case ">":
|
|
98
|
+
return left > right;
|
|
70
99
|
// Numeric
|
|
71
|
-
case "-eq":
|
|
72
|
-
|
|
73
|
-
case "-
|
|
74
|
-
|
|
75
|
-
case "-
|
|
76
|
-
|
|
100
|
+
case "-eq":
|
|
101
|
+
return leftN === rightN;
|
|
102
|
+
case "-ne":
|
|
103
|
+
return leftN !== rightN;
|
|
104
|
+
case "-lt":
|
|
105
|
+
return leftN < rightN;
|
|
106
|
+
case "-le":
|
|
107
|
+
return leftN <= rightN;
|
|
108
|
+
case "-gt":
|
|
109
|
+
return leftN > rightN;
|
|
110
|
+
case "-ge":
|
|
111
|
+
return leftN >= rightN;
|
|
77
112
|
}
|
|
78
113
|
}
|
|
79
114
|
|
package/src/commands/tr.ts
CHANGED
|
@@ -16,7 +16,9 @@ export const trCommand: ShellModule = {
|
|
|
16
16
|
for (const c of set1) input = input.split(c).join("");
|
|
17
17
|
} else if (set2) {
|
|
18
18
|
for (let i = 0; i < set1.length; i++) {
|
|
19
|
-
input = input
|
|
19
|
+
input = input
|
|
20
|
+
.split(set1[i]!)
|
|
21
|
+
.join(set2[i] ?? set2[set2.length - 1] ?? "");
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
return { stdout: input, exitCode: 0 };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ShellModule } from "../types/commands";
|
|
2
|
+
|
|
3
|
+
export const trueCommand: ShellModule = {
|
|
4
|
+
name: "true",
|
|
5
|
+
description: "Return success exit code",
|
|
6
|
+
category: "shell",
|
|
7
|
+
params: [],
|
|
8
|
+
run: () => ({ exitCode: 0 }),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const falseCommand: ShellModule = {
|
|
12
|
+
name: "false",
|
|
13
|
+
description: "Return failure exit code",
|
|
14
|
+
category: "shell",
|
|
15
|
+
params: [],
|
|
16
|
+
run: () => ({ exitCode: 1 }),
|
|
17
|
+
};
|
package/src/commands/type.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveModule } from ".";
|
|
2
1
|
import type { ShellModule } from "../types/commands";
|
|
2
|
+
import { resolveModule } from "./registry";
|
|
3
3
|
|
|
4
4
|
export const typeCommand: ShellModule = {
|
|
5
5
|
name: "type",
|
|
@@ -7,9 +7,12 @@ export const typeCommand: ShellModule = {
|
|
|
7
7
|
category: "shell",
|
|
8
8
|
params: ["<command...>"],
|
|
9
9
|
run: ({ args, shell, env }) => {
|
|
10
|
-
if (args.length === 0)
|
|
10
|
+
if (args.length === 0)
|
|
11
|
+
return { stderr: "type: missing argument", exitCode: 1 };
|
|
11
12
|
|
|
12
|
-
const pathDirs = (env?.vars?.PATH ?? "/usr/local/bin:/usr/bin:/bin").split(
|
|
13
|
+
const pathDirs = (env?.vars?.PATH ?? "/usr/local/bin:/usr/bin:/bin").split(
|
|
14
|
+
":",
|
|
15
|
+
);
|
|
13
16
|
const lines: string[] = [];
|
|
14
17
|
let exitCode = 0;
|
|
15
18
|
|
package/src/commands/uname.ts
CHANGED
|
@@ -12,7 +12,11 @@ export const unameCommand: ShellModule = {
|
|
|
12
12
|
const release = shell.properties?.kernel ?? "5.15.0";
|
|
13
13
|
const machine = shell.properties?.arch ?? "x86_64";
|
|
14
14
|
const hostname = shell.hostname;
|
|
15
|
-
if (all)
|
|
15
|
+
if (all)
|
|
16
|
+
return {
|
|
17
|
+
stdout: `${sysname} ${hostname} ${release} #1 SMP ${machine} GNU/Linux`,
|
|
18
|
+
exitCode: 0,
|
|
19
|
+
};
|
|
16
20
|
if (ifFlag(args, ["-r"])) return { stdout: release, exitCode: 0 };
|
|
17
21
|
if (ifFlag(args, ["-m"])) return { stdout: machine, exitCode: 0 };
|
|
18
22
|
return { stdout: sysname, exitCode: 0 };
|
package/src/commands/uniq.ts
CHANGED
|
@@ -18,8 +18,14 @@ export const uniqCommand: ShellModule = {
|
|
|
18
18
|
while (j < lines.length && lines[j] === lines[i]) j++;
|
|
19
19
|
const n = j - i;
|
|
20
20
|
const line = lines[i]!;
|
|
21
|
-
if (dupOnly && n === 1) {
|
|
22
|
-
|
|
21
|
+
if (dupOnly && n === 1) {
|
|
22
|
+
i = j;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (uniqOnly && n > 1) {
|
|
26
|
+
i = j;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
23
29
|
out.push(count ? `${String(n).padStart(4)} ${line}` : line);
|
|
24
30
|
i = j;
|
|
25
31
|
}
|
package/src/commands/uptime.ts
CHANGED
|
@@ -17,7 +17,10 @@ export const uptimeCommand: ShellModule = {
|
|
|
17
17
|
|
|
18
18
|
if (since) {
|
|
19
19
|
return {
|
|
20
|
-
stdout: new Date(shell.startTime)
|
|
20
|
+
stdout: new Date(shell.startTime)
|
|
21
|
+
.toISOString()
|
|
22
|
+
.slice(0, 19)
|
|
23
|
+
.replace("T", " "),
|
|
21
24
|
exitCode: 0,
|
|
22
25
|
};
|
|
23
26
|
}
|
package/src/commands/wget.ts
CHANGED
|
@@ -9,7 +9,16 @@ export const wgetCommand: ShellModule = {
|
|
|
9
9
|
params: ["[options] <url>"],
|
|
10
10
|
run: async ({ authUser, cwd, args, shell }) => {
|
|
11
11
|
const { flagsWithValues, positionals } = parseArgs(args, {
|
|
12
|
-
flagsWithValue: [
|
|
12
|
+
flagsWithValue: [
|
|
13
|
+
"-O",
|
|
14
|
+
"--output-document",
|
|
15
|
+
"-o",
|
|
16
|
+
"--output-file",
|
|
17
|
+
"-P",
|
|
18
|
+
"--directory-prefix",
|
|
19
|
+
"--tries",
|
|
20
|
+
"--timeout",
|
|
21
|
+
],
|
|
13
22
|
});
|
|
14
23
|
|
|
15
24
|
if (ifFlag(args, ["-h", "--help"])) {
|
|
@@ -29,18 +38,32 @@ export const wgetCommand: ShellModule = {
|
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
if (ifFlag(args, ["-V", "--version"])) {
|
|
32
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
stdout: "GNU Wget 1.21.3 (virtual) built on Fortune GNU/Linux.",
|
|
43
|
+
exitCode: 0,
|
|
44
|
+
};
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
const url = positionals[0];
|
|
36
|
-
if (!url)
|
|
48
|
+
if (!url)
|
|
49
|
+
return {
|
|
50
|
+
stderr: "wget: missing URL\nUsage: wget [OPTION]... [URL]...",
|
|
51
|
+
exitCode: 1,
|
|
52
|
+
};
|
|
37
53
|
|
|
38
|
-
const outputArg =
|
|
39
|
-
|
|
54
|
+
const outputArg =
|
|
55
|
+
flagsWithValues.get("-O") ??
|
|
56
|
+
flagsWithValues.get("--output-document") ??
|
|
57
|
+
null;
|
|
58
|
+
const dirPrefix =
|
|
59
|
+
flagsWithValues.get("-P") ??
|
|
60
|
+
flagsWithValues.get("--directory-prefix") ??
|
|
61
|
+
null;
|
|
40
62
|
const quiet = ifFlag(args, ["-q", "--quiet"]);
|
|
41
63
|
|
|
42
64
|
// Derive target filename
|
|
43
|
-
const filename =
|
|
65
|
+
const filename =
|
|
66
|
+
outputArg === "-" ? null : (outputArg ?? stripUrlFilename(url));
|
|
44
67
|
const targetPath = filename
|
|
45
68
|
? resolvePath(cwd, dirPrefix ? `${dirPrefix}/${filename}` : filename)
|
|
46
69
|
: null;
|
|
@@ -56,7 +79,9 @@ export const wgetCommand: ShellModule = {
|
|
|
56
79
|
|
|
57
80
|
let response: Response;
|
|
58
81
|
try {
|
|
59
|
-
response = await fetch(url, {
|
|
82
|
+
response = await fetch(url, {
|
|
83
|
+
headers: { "User-Agent": "Wget/1.21.3 (Fortune GNU/Linux)" },
|
|
84
|
+
});
|
|
60
85
|
} catch (err) {
|
|
61
86
|
const msg = err instanceof Error ? err.message : String(err);
|
|
62
87
|
stderrLines.push(`wget: unable to resolve host: ${msg}`);
|
|
@@ -69,22 +94,36 @@ export const wgetCommand: ShellModule = {
|
|
|
69
94
|
}
|
|
70
95
|
|
|
71
96
|
let body: string;
|
|
72
|
-
try {
|
|
97
|
+
try {
|
|
98
|
+
body = await response.text();
|
|
99
|
+
} catch {
|
|
100
|
+
return { stderr: "wget: failed to read response", exitCode: 1 };
|
|
101
|
+
}
|
|
73
102
|
|
|
74
103
|
if (!quiet) {
|
|
75
|
-
const ct =
|
|
76
|
-
|
|
104
|
+
const ct =
|
|
105
|
+
response.headers.get("content-type") ?? "application/octet-stream";
|
|
106
|
+
stderrLines.push(
|
|
107
|
+
`HTTP request sent, awaiting response... ${response.status} ${response.statusText}`,
|
|
108
|
+
);
|
|
77
109
|
stderrLines.push(`Length: ${body.length} [${ct}]`);
|
|
78
110
|
}
|
|
79
111
|
|
|
80
112
|
// Output to stdout (pipe) or file
|
|
81
113
|
if (outputArg === "-") {
|
|
82
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
stdout: body,
|
|
116
|
+
stderr: stderrLines.join("\n") || undefined,
|
|
117
|
+
exitCode: 0,
|
|
118
|
+
};
|
|
83
119
|
}
|
|
84
120
|
|
|
85
121
|
if (targetPath) {
|
|
86
122
|
shell.writeFileAsUser(authUser, targetPath, body);
|
|
87
|
-
if (!quiet)
|
|
123
|
+
if (!quiet)
|
|
124
|
+
stderrLines.push(
|
|
125
|
+
`Saving to: '${targetPath}'\n${targetPath} 100%[==================>] ${body.length} B`,
|
|
126
|
+
);
|
|
88
127
|
return { stderr: stderrLines.join("\n") || undefined, exitCode: 0 };
|
|
89
128
|
}
|
|
90
129
|
|
package/src/commands/which.ts
CHANGED
|
@@ -6,9 +6,12 @@ export const whichCommand: ShellModule = {
|
|
|
6
6
|
category: "shell",
|
|
7
7
|
params: ["<command...>"],
|
|
8
8
|
run: ({ args, shell, env }) => {
|
|
9
|
-
if (args.length === 0)
|
|
9
|
+
if (args.length === 0)
|
|
10
|
+
return { stderr: "which: missing argument", exitCode: 1 };
|
|
10
11
|
|
|
11
|
-
const pathDirs = (env?.vars?.PATH ?? "/usr/local/bin:/usr/bin:/bin").split(
|
|
12
|
+
const pathDirs = (env?.vars?.PATH ?? "/usr/local/bin:/usr/bin:/bin").split(
|
|
13
|
+
":",
|
|
14
|
+
);
|
|
12
15
|
const lines: string[] = [];
|
|
13
16
|
let anyMissing = false;
|
|
14
17
|
|
package/src/commands/xargs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ShellModule } from "../types/commands";
|
|
2
|
-
import { runCommand } from "./
|
|
2
|
+
import { runCommand } from "./runtime";
|
|
3
3
|
|
|
4
4
|
export const xargsCommand: ShellModule = {
|
|
5
5
|
name: "xargs",
|
|
@@ -12,6 +12,15 @@ export const xargsCommand: ShellModule = {
|
|
|
12
12
|
const items = (stdin ?? "").trim().split(/\s+/).filter(Boolean);
|
|
13
13
|
if (items.length === 0) return { exitCode: 0 };
|
|
14
14
|
const fullCmd = [baseCmd, ...extraArgs, ...items].join(" ");
|
|
15
|
-
return runCommand(
|
|
15
|
+
return runCommand(
|
|
16
|
+
fullCmd,
|
|
17
|
+
authUser,
|
|
18
|
+
hostname,
|
|
19
|
+
mode,
|
|
20
|
+
cwd,
|
|
21
|
+
shell,
|
|
22
|
+
undefined,
|
|
23
|
+
env,
|
|
24
|
+
);
|
|
16
25
|
},
|
|
17
26
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export { HoneyPot } from "./Honeypot/index";
|
|
2
|
+
export { SshClient } from "./SSHClient/index";
|
|
3
|
+
export { SftpMimic as VirtualSftpServer, SshMimic as VirtualSshServer } from "./SSHMimic/index";
|
|
4
|
+
export { default as VirtualFileSystem } from "./VirtualFileSystem/index";
|
|
5
|
+
export { VirtualPackageManager } from "./VirtualPackageManager/index";
|
|
6
|
+
export { VirtualShell } from "./VirtualShell/index";
|
|
7
|
+
export { VirtualUserManager } from "./VirtualUserManager/index";
|
|
8
8
|
|
|
9
9
|
export type {
|
|
10
10
|
AuditLogEntry,
|
|
11
|
-
HoneyPotStats
|
|
11
|
+
HoneyPotStats
|
|
12
12
|
} from "./Honeypot/index";
|
|
13
13
|
export type {
|
|
14
14
|
CommandContext,
|
|
@@ -18,9 +18,8 @@ export type {
|
|
|
18
18
|
NanoEditorSession,
|
|
19
19
|
ShellEnv,
|
|
20
20
|
ShellModule,
|
|
21
|
-
SudoChallenge
|
|
21
|
+
SudoChallenge
|
|
22
22
|
} from "./types/commands";
|
|
23
|
-
export type { ShellProperties } from "./VirtualShell/index";
|
|
24
23
|
export type { ExecStream, ShellStream } from "./types/streams";
|
|
25
24
|
export type {
|
|
26
25
|
RemoveOptions,
|
|
@@ -34,29 +33,29 @@ export type {
|
|
|
34
33
|
VfsSnapshotDirectoryNode,
|
|
35
34
|
VfsSnapshotFileNode,
|
|
36
35
|
VfsSnapshotNode,
|
|
37
|
-
WriteFileOptions
|
|
36
|
+
WriteFileOptions
|
|
38
37
|
} from "./types/vfs";
|
|
39
38
|
export type { VfsOptions, VfsPersistenceMode } from "./VirtualFileSystem/index";
|
|
39
|
+
export type { ShellProperties } from "./VirtualShell/index";
|
|
40
40
|
|
|
41
41
|
export type {
|
|
42
|
-
PackageDefinition,
|
|
43
|
-
PackageFile
|
|
44
|
-
InstalledPackage,
|
|
42
|
+
InstalledPackage, PackageDefinition,
|
|
43
|
+
PackageFile
|
|
45
44
|
} from "./VirtualPackageManager/index";
|
|
46
45
|
|
|
47
46
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
47
|
+
assertDiff, diffSnapshots,
|
|
48
|
+
formatDiff
|
|
49
|
+
} from "./utils/vfsDiff";
|
|
50
|
+
export type {
|
|
51
|
+
VfsDiff,
|
|
52
|
+
VfsDiffEntry,
|
|
53
|
+
VfsDiffModified
|
|
54
|
+
} from "./utils/vfsDiff";
|
|
57
55
|
|
|
58
56
|
export {
|
|
59
57
|
getArg,
|
|
60
58
|
getFlag,
|
|
61
|
-
ifFlag
|
|
59
|
+
ifFlag
|
|
62
60
|
} from "./commands/command-helpers";
|
|
61
|
+
|