typescript-virtual-container 1.2.7 → 1.2.9
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/README.md +457 -42
- package/dist/SSHMimic/executor.js +3 -5
- package/dist/VirtualFileSystem/binaryPack.d.ts +49 -0
- package/dist/VirtualFileSystem/binaryPack.d.ts.map +1 -0
- package/dist/VirtualFileSystem/binaryPack.js +193 -0
- package/dist/VirtualFileSystem/index.d.ts +7 -5
- package/dist/VirtualFileSystem/index.d.ts.map +1 -1
- package/dist/VirtualFileSystem/index.js +20 -9
- package/dist/VirtualPackageManager/index.d.ts +202 -0
- package/dist/VirtualPackageManager/index.d.ts.map +1 -0
- package/dist/VirtualPackageManager/index.js +676 -0
- package/dist/VirtualShell/index.d.ts +87 -12
- package/dist/VirtualShell/index.d.ts.map +1 -1
- package/dist/VirtualShell/index.js +83 -12
- package/dist/VirtualUserManager/index.d.ts +52 -20
- package/dist/VirtualUserManager/index.d.ts.map +1 -1
- package/dist/VirtualUserManager/index.js +54 -20
- package/dist/commands/alias.d.ts +4 -0
- package/dist/commands/alias.d.ts.map +1 -0
- package/dist/commands/alias.js +58 -0
- package/dist/commands/apt.d.ts +4 -0
- package/dist/commands/apt.d.ts.map +1 -0
- package/dist/commands/apt.js +182 -0
- package/dist/commands/cat.d.ts.map +1 -1
- package/dist/commands/cat.js +27 -8
- package/dist/commands/chmod.d.ts.map +1 -1
- package/dist/commands/chmod.js +52 -3
- package/dist/commands/command-helpers.d.ts +78 -4
- package/dist/commands/command-helpers.d.ts.map +1 -1
- package/dist/commands/command-helpers.js +78 -4
- package/dist/commands/curl.d.ts.map +1 -1
- package/dist/commands/curl.js +81 -29
- package/dist/commands/dpkg.d.ts +4 -0
- package/dist/commands/dpkg.d.ts.map +1 -0
- package/dist/commands/dpkg.js +144 -0
- package/dist/commands/echo.d.ts.map +1 -1
- package/dist/commands/echo.js +24 -12
- package/dist/commands/free.d.ts +3 -0
- package/dist/commands/free.d.ts.map +1 -0
- package/dist/commands/free.js +38 -0
- package/dist/commands/helpers.d.ts +3 -0
- package/dist/commands/helpers.d.ts.map +1 -1
- package/dist/commands/helpers.js +3 -0
- package/dist/commands/history.d.ts +3 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +21 -0
- package/dist/commands/index.d.ts +8 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +120 -11
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +4 -3
- package/dist/commands/lsb-release.d.ts +3 -0
- package/dist/commands/lsb-release.d.ts.map +1 -0
- package/dist/commands/lsb-release.js +50 -0
- package/dist/commands/man.d.ts +3 -0
- package/dist/commands/man.d.ts.map +1 -0
- package/dist/commands/man.js +155 -0
- package/dist/commands/neofetch.d.ts.map +1 -1
- package/dist/commands/neofetch.js +5 -0
- package/dist/commands/ping.d.ts.map +1 -1
- package/dist/commands/ping.js +5 -2
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +27 -6
- package/dist/commands/sh.d.ts.map +1 -1
- package/dist/commands/sh.js +29 -11
- package/dist/commands/source.d.ts +3 -0
- package/dist/commands/source.d.ts.map +1 -0
- package/dist/commands/source.js +31 -0
- package/dist/commands/test.d.ts +3 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +92 -0
- package/dist/commands/type.d.ts +3 -0
- package/dist/commands/type.d.ts.map +1 -0
- package/dist/commands/type.js +34 -0
- package/dist/commands/uptime.d.ts +3 -0
- package/dist/commands/uptime.d.ts.map +1 -0
- package/dist/commands/uptime.js +40 -0
- package/dist/commands/wget.d.ts.map +1 -1
- package/dist/commands/wget.js +71 -100
- package/dist/commands/which.d.ts +3 -0
- package/dist/commands/which.d.ts.map +1 -0
- package/dist/commands/which.js +32 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/modules/linuxRootfs.d.ts +24 -0
- package/dist/modules/linuxRootfs.d.ts.map +1 -0
- package/dist/modules/linuxRootfs.js +297 -0
- package/dist/modules/neofetch.d.ts.map +1 -1
- package/dist/modules/neofetch.js +1 -0
- package/dist/standalone.js +4 -1
- package/package.json +2 -1
- package/src/SSHMimic/executor.ts +3 -5
- package/src/VirtualFileSystem/binaryPack.ts +219 -0
- package/src/VirtualFileSystem/index.ts +21 -11
- package/src/VirtualPackageManager/index.ts +820 -0
- package/src/VirtualShell/index.ts +104 -13
- package/src/VirtualUserManager/index.ts +55 -20
- package/src/commands/alias.ts +60 -0
- package/src/commands/apt.ts +198 -0
- package/src/commands/cat.ts +32 -8
- package/src/commands/chmod.ts +48 -3
- package/src/commands/command-helpers.ts +78 -4
- package/src/commands/curl.ts +78 -37
- package/src/commands/dpkg.ts +158 -0
- package/src/commands/echo.ts +30 -14
- package/src/commands/free.ts +40 -0
- package/src/commands/helpers.ts +8 -0
- package/src/commands/history.ts +29 -0
- package/src/commands/index.ts +116 -11
- package/src/commands/ls.ts +5 -4
- package/src/commands/lsb-release.ts +52 -0
- package/src/commands/man.ts +166 -0
- package/src/commands/neofetch.ts +5 -0
- package/src/commands/ping.ts +5 -2
- package/src/commands/ps.ts +28 -6
- package/src/commands/sh.ts +33 -11
- package/src/commands/source.ts +35 -0
- package/src/commands/test.ts +100 -0
- package/src/commands/type.ts +40 -0
- package/src/commands/uptime.ts +46 -0
- package/src/commands/wget.ts +70 -123
- package/src/commands/which.ts +34 -0
- package/src/index.ts +10 -0
- package/src/modules/linuxRootfs.ts +439 -0
- package/src/modules/neofetch.ts +1 -0
- package/src/standalone.ts +4 -1
- package/standalone.js +418 -103
- package/standalone.js.map +4 -4
- package/tests/new-features.test.ts +626 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* linuxRootfs.ts
|
|
3
|
+
*
|
|
4
|
+
* Bootstraps a realistic Linux directory hierarchy in the VFS.
|
|
5
|
+
* Called once during VirtualShell initialization. Idempotent — skips
|
|
6
|
+
* paths that already exist so FS-mode snapshots survive restarts.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as os from "node:os";
|
|
10
|
+
import type { ShellProperties } from "../VirtualShell";
|
|
11
|
+
import type VirtualFileSystem from "../VirtualFileSystem";
|
|
12
|
+
import type { VirtualUserManager } from "../VirtualUserManager";
|
|
13
|
+
|
|
14
|
+
// ─── helpers ────────────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
function ensureDir(vfs: VirtualFileSystem, path: string, mode = 0o755): void {
|
|
17
|
+
if (!vfs.exists(path)) vfs.mkdir(path, mode);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function ensureFile(
|
|
21
|
+
vfs: VirtualFileSystem,
|
|
22
|
+
path: string,
|
|
23
|
+
content: string,
|
|
24
|
+
mode = 0o644,
|
|
25
|
+
): void {
|
|
26
|
+
if (!vfs.exists(path)) vfs.writeFile(path, content, { mode });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// ─── /etc ────────────────────────────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
function bootstrapEtc(
|
|
32
|
+
vfs: VirtualFileSystem,
|
|
33
|
+
hostname: string,
|
|
34
|
+
props: ShellProperties,
|
|
35
|
+
): void {
|
|
36
|
+
ensureDir(vfs, "/etc");
|
|
37
|
+
|
|
38
|
+
// os-release — authoritative distro identity used by neofetch, lsb_release
|
|
39
|
+
ensureFile(
|
|
40
|
+
vfs,
|
|
41
|
+
"/etc/os-release",
|
|
42
|
+
`${[
|
|
43
|
+
`NAME="Fortune GNU/Linux"`,
|
|
44
|
+
`PRETTY_NAME="${props.os}"`,
|
|
45
|
+
`ID=fortune`,
|
|
46
|
+
`ID_LIKE=debian`,
|
|
47
|
+
`HOME_URL="https://github.com/itsrealfortune/typescript-virtual-container"`,
|
|
48
|
+
`VERSION_CODENAME=aurora`,
|
|
49
|
+
`VERSION_ID="1.0"`,
|
|
50
|
+
].join("\n")}\n`,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
ensureFile(vfs, "/etc/debian_version", "12.0\n");
|
|
54
|
+
ensureFile(vfs, "/etc/hostname", `${hostname}\n`);
|
|
55
|
+
ensureFile(vfs, "/etc/shells", "/bin/sh\n/bin/bash\n/usr/bin/bash\n");
|
|
56
|
+
ensureFile(
|
|
57
|
+
vfs,
|
|
58
|
+
"/etc/profile",
|
|
59
|
+
`${[
|
|
60
|
+
"export PATH=/usr/local/bin:/usr/bin:/bin",
|
|
61
|
+
"export PS1='\\u@\\h:\\w\\$ '",
|
|
62
|
+
].join("\n")}\n`,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
ensureFile(
|
|
66
|
+
vfs,
|
|
67
|
+
"/etc/issue",
|
|
68
|
+
`Fortune GNU/Linux 1.0 \\n \\l\n`,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
ensureFile(
|
|
72
|
+
vfs,
|
|
73
|
+
"/etc/motd",
|
|
74
|
+
[
|
|
75
|
+
"",
|
|
76
|
+
`Welcome to ${props.os}`,
|
|
77
|
+
`Kernel: ${props.kernel}`,
|
|
78
|
+
"",
|
|
79
|
+
].join("\n"),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// APT sources
|
|
83
|
+
ensureDir(vfs, "/etc/apt");
|
|
84
|
+
ensureDir(vfs, "/etc/apt/sources.list.d");
|
|
85
|
+
ensureFile(
|
|
86
|
+
vfs,
|
|
87
|
+
"/etc/apt/sources.list",
|
|
88
|
+
`${[
|
|
89
|
+
"# Fortune GNU/Linux package sources",
|
|
90
|
+
"deb [virtual] fortune://packages.fortune.local aurora main contrib",
|
|
91
|
+
"deb [virtual] fortune://security.fortune.local aurora-security main",
|
|
92
|
+
].join("\n")}\n`,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// network stubs
|
|
96
|
+
ensureDir(vfs, "/etc/network");
|
|
97
|
+
ensureFile(
|
|
98
|
+
vfs,
|
|
99
|
+
"/etc/network/interfaces",
|
|
100
|
+
`${[
|
|
101
|
+
"auto lo",
|
|
102
|
+
"iface lo inet loopback",
|
|
103
|
+
"",
|
|
104
|
+
"auto eth0",
|
|
105
|
+
"iface eth0 inet dhcp",
|
|
106
|
+
].join("\n")}\n`,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
ensureFile(
|
|
110
|
+
vfs,
|
|
111
|
+
"/etc/resolv.conf",
|
|
112
|
+
"nameserver 1.1.1.1\nnameserver 8.8.8.8\n",
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
ensureFile(
|
|
116
|
+
vfs,
|
|
117
|
+
"/etc/hosts",
|
|
118
|
+
`${[
|
|
119
|
+
"127.0.0.1 localhost",
|
|
120
|
+
`127.0.1.1 ${hostname}`,
|
|
121
|
+
"::1 localhost ip6-localhost ip6-loopback",
|
|
122
|
+
].join("\n")}\n`,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
ensureDir(vfs, "/etc/cron.d");
|
|
126
|
+
ensureDir(vfs, "/etc/init.d");
|
|
127
|
+
ensureDir(vfs, "/etc/systemd");
|
|
128
|
+
ensureDir(vfs, "/etc/systemd/system");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ─── /etc/passwd + /etc/group + /etc/shadow ─────────────────────────────────
|
|
132
|
+
|
|
133
|
+
export function syncEtcPasswd(
|
|
134
|
+
vfs: VirtualFileSystem,
|
|
135
|
+
users: VirtualUserManager,
|
|
136
|
+
): void {
|
|
137
|
+
const userList = users.listUsers();
|
|
138
|
+
|
|
139
|
+
const passwdLines = [
|
|
140
|
+
"root:x:0:0:root:/root:/bin/bash",
|
|
141
|
+
"daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin",
|
|
142
|
+
"www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin",
|
|
143
|
+
"nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin",
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
let uid = 1000;
|
|
147
|
+
for (const u of userList) {
|
|
148
|
+
if (u === "root") continue;
|
|
149
|
+
passwdLines.push(`${u}:x:${uid}:${uid}::/home/${u}:/bin/bash`);
|
|
150
|
+
uid++;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
vfs.writeFile("/etc/passwd", `${passwdLines.join("\n")}\n`);
|
|
154
|
+
|
|
155
|
+
const groupLines = [
|
|
156
|
+
"root:x:0:",
|
|
157
|
+
"daemon:x:1:",
|
|
158
|
+
`sudo:x:27:${userList.filter((u) => users.isSudoer(u)).join(",")}`,
|
|
159
|
+
`users:x:100:${userList.filter((u) => u !== "root").join(",")}`,
|
|
160
|
+
"nogroup:x:65534:",
|
|
161
|
+
];
|
|
162
|
+
vfs.writeFile("/etc/group", `${groupLines.join("\n")}\n`);
|
|
163
|
+
|
|
164
|
+
// shadow — fake hashes, never real
|
|
165
|
+
const shadowLines = [
|
|
166
|
+
"root:*:19000:0:99999:7:::",
|
|
167
|
+
"daemon:*:19000:0:99999:7:::",
|
|
168
|
+
];
|
|
169
|
+
for (const u of userList) {
|
|
170
|
+
if (u === "root") continue;
|
|
171
|
+
shadowLines.push(`${u}:!:19000:0:99999:7:::`);
|
|
172
|
+
}
|
|
173
|
+
vfs.writeFile("/etc/shadow", `${shadowLines.join("\n")}\n`, { mode: 0o640 });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ─── /proc ───────────────────────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
export function refreshProc(
|
|
179
|
+
vfs: VirtualFileSystem,
|
|
180
|
+
props: ShellProperties,
|
|
181
|
+
hostname: string,
|
|
182
|
+
shellStartTime: number,
|
|
183
|
+
): void {
|
|
184
|
+
ensureDir(vfs, "/proc");
|
|
185
|
+
|
|
186
|
+
const uptimeSec = Math.floor((Date.now() - shellStartTime) / 1000);
|
|
187
|
+
vfs.writeFile("/proc/uptime", `${uptimeSec}.00 ${Math.floor(uptimeSec * 0.9)}.00\n`);
|
|
188
|
+
|
|
189
|
+
const totalMemKb = Math.floor(os.totalmem() / 1024);
|
|
190
|
+
const freeMemKb = Math.floor(os.freemem() / 1024);
|
|
191
|
+
const availMemKb = Math.floor(freeMemKb * 0.95);
|
|
192
|
+
vfs.writeFile(
|
|
193
|
+
"/proc/meminfo",
|
|
194
|
+
`${[
|
|
195
|
+
`MemTotal: ${String(totalMemKb).padStart(10)} kB`,
|
|
196
|
+
`MemFree: ${String(freeMemKb).padStart(10)} kB`,
|
|
197
|
+
`MemAvailable: ${String(availMemKb).padStart(10)} kB`,
|
|
198
|
+
`Buffers: ${String(Math.floor(totalMemKb * 0.02)).padStart(10)} kB`,
|
|
199
|
+
`Cached: ${String(Math.floor(totalMemKb * 0.15)).padStart(10)} kB`,
|
|
200
|
+
`SwapTotal: ${String(Math.floor(totalMemKb * 0.5)).padStart(10)} kB`,
|
|
201
|
+
`SwapFree: ${String(Math.floor(totalMemKb * 0.5)).padStart(10)} kB`,
|
|
202
|
+
].join("\n")}\n`,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const cpus = os.cpus();
|
|
206
|
+
const cpuLines: string[] = [];
|
|
207
|
+
for (let i = 0; i < cpus.length; i++) {
|
|
208
|
+
const c = cpus[i];
|
|
209
|
+
if (!c) continue;
|
|
210
|
+
const mhz = (c.speed).toFixed(3);
|
|
211
|
+
cpuLines.push(
|
|
212
|
+
`processor\t: ${i}`,
|
|
213
|
+
`model name\t: ${c.model}`,
|
|
214
|
+
`cpu MHz\t\t: ${mhz}`,
|
|
215
|
+
`cache size\t: 8192 KB`,
|
|
216
|
+
"",
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
vfs.writeFile("/proc/cpuinfo", `${cpuLines.join("\n")}\n`);
|
|
220
|
+
|
|
221
|
+
vfs.writeFile(
|
|
222
|
+
"/proc/version",
|
|
223
|
+
`Linux version ${props.kernel} (fortune@build) (gcc version 12.2.0) #1 SMP\n`,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
vfs.writeFile("/proc/hostname", `${hostname}\n`);
|
|
227
|
+
|
|
228
|
+
// /proc/loadavg
|
|
229
|
+
const load = (Math.random() * 0.5).toFixed(2);
|
|
230
|
+
vfs.writeFile("/proc/loadavg", `${load} ${load} ${load} 1/1 1\n`);
|
|
231
|
+
|
|
232
|
+
// /proc/net stubs
|
|
233
|
+
ensureDir(vfs, "/proc/net");
|
|
234
|
+
ensureFile(
|
|
235
|
+
vfs,
|
|
236
|
+
"/proc/net/dev",
|
|
237
|
+
`${[
|
|
238
|
+
"Inter-| Receive | Transmit",
|
|
239
|
+
" face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed",
|
|
240
|
+
" lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
|
|
241
|
+
" eth0: 131072 1024 0 0 0 0 0 0 65536 512 0 0 0 0 0 0",
|
|
242
|
+
].join("\n")}\n`,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ─── /sys ─────────────────────────────────────────────────────────────────────
|
|
247
|
+
|
|
248
|
+
function bootstrapSys(vfs: VirtualFileSystem, props: ShellProperties): void {
|
|
249
|
+
ensureDir(vfs, "/sys");
|
|
250
|
+
ensureDir(vfs, "/sys/devices");
|
|
251
|
+
ensureDir(vfs, "/sys/devices/virtual");
|
|
252
|
+
ensureDir(vfs, "/sys/devices/virtual/dmi");
|
|
253
|
+
ensureDir(vfs, "/sys/devices/virtual/dmi/id");
|
|
254
|
+
|
|
255
|
+
ensureFile(vfs, "/sys/devices/virtual/dmi/id/sys_vendor", "Fortune Systems\n");
|
|
256
|
+
ensureFile(vfs, "/sys/devices/virtual/dmi/id/product_name", "VirtualContainer v1\n");
|
|
257
|
+
ensureFile(vfs, "/sys/devices/virtual/dmi/id/board_name", "fortune-board\n");
|
|
258
|
+
|
|
259
|
+
ensureDir(vfs, "/sys/class");
|
|
260
|
+
ensureDir(vfs, "/sys/class/net");
|
|
261
|
+
|
|
262
|
+
ensureDir(vfs, "/sys/kernel");
|
|
263
|
+
ensureFile(vfs, "/sys/kernel/hostname", "fortune-vm\n");
|
|
264
|
+
ensureFile(
|
|
265
|
+
vfs,
|
|
266
|
+
"/sys/kernel/osrelease",
|
|
267
|
+
`${props.kernel}\n`,
|
|
268
|
+
);
|
|
269
|
+
ensureFile(vfs, "/sys/kernel/ostype", "Linux\n");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ─── /dev ─────────────────────────────────────────────────────────────────────
|
|
273
|
+
|
|
274
|
+
function bootstrapDev(vfs: VirtualFileSystem): void {
|
|
275
|
+
ensureDir(vfs, "/dev");
|
|
276
|
+
ensureFile(vfs, "/dev/null", "", 0o666);
|
|
277
|
+
ensureFile(vfs, "/dev/zero", "", 0o666);
|
|
278
|
+
ensureFile(vfs, "/dev/random", "", 0o444);
|
|
279
|
+
ensureFile(vfs, "/dev/urandom", "", 0o444);
|
|
280
|
+
ensureDir(vfs, "/dev/pts");
|
|
281
|
+
ensureDir(vfs, "/dev/shm");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ─── /usr ─────────────────────────────────────────────────────────────────────
|
|
285
|
+
|
|
286
|
+
function bootstrapUsr(vfs: VirtualFileSystem): void {
|
|
287
|
+
ensureDir(vfs, "/usr");
|
|
288
|
+
ensureDir(vfs, "/usr/bin");
|
|
289
|
+
ensureDir(vfs, "/usr/sbin");
|
|
290
|
+
ensureDir(vfs, "/usr/local");
|
|
291
|
+
ensureDir(vfs, "/usr/local/bin");
|
|
292
|
+
ensureDir(vfs, "/usr/local/lib");
|
|
293
|
+
ensureDir(vfs, "/usr/local/share");
|
|
294
|
+
ensureDir(vfs, "/usr/share");
|
|
295
|
+
ensureDir(vfs, "/usr/share/doc");
|
|
296
|
+
ensureDir(vfs, "/usr/share/man");
|
|
297
|
+
ensureDir(vfs, "/usr/share/man/man1");
|
|
298
|
+
ensureDir(vfs, "/usr/lib");
|
|
299
|
+
|
|
300
|
+
// Stub binaries so `which` can find built-in commands
|
|
301
|
+
const builtins = [
|
|
302
|
+
"sh", "bash", "ls", "cat", "echo", "grep", "find", "sort",
|
|
303
|
+
"head", "tail", "cut", "tr", "sed", "awk", "wc", "tee",
|
|
304
|
+
"tar", "gzip", "gunzip", "touch", "mkdir", "rm", "mv", "cp",
|
|
305
|
+
"chmod", "ln", "pwd", "env", "date", "sleep", "id", "whoami",
|
|
306
|
+
"hostname", "uname", "ps", "kill", "df", "du", "curl", "wget",
|
|
307
|
+
"nano", "diff", "uniq", "xargs", "base64",
|
|
308
|
+
];
|
|
309
|
+
for (const bin of builtins) {
|
|
310
|
+
ensureFile(vfs, `/usr/bin/${bin}`, `#!/bin/sh\nexec builtin ${bin} "$@"\n`, 0o755);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// lsb_release script
|
|
314
|
+
ensureFile(
|
|
315
|
+
vfs,
|
|
316
|
+
"/usr/bin/lsb_release",
|
|
317
|
+
"#!/bin/sh\nexec lsb_release \"$@\"\n",
|
|
318
|
+
0o755,
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ─── /var ─────────────────────────────────────────────────────────────────────
|
|
323
|
+
|
|
324
|
+
function bootstrapVar(vfs: VirtualFileSystem): void {
|
|
325
|
+
ensureDir(vfs, "/var");
|
|
326
|
+
ensureDir(vfs, "/var/log");
|
|
327
|
+
ensureDir(vfs, "/var/tmp");
|
|
328
|
+
ensureDir(vfs, "/var/run");
|
|
329
|
+
ensureDir(vfs, "/var/cache");
|
|
330
|
+
ensureDir(vfs, "/var/cache/apt");
|
|
331
|
+
ensureDir(vfs, "/var/cache/apt/archives");
|
|
332
|
+
ensureDir(vfs, "/var/lib");
|
|
333
|
+
ensureDir(vfs, "/var/lib/apt");
|
|
334
|
+
ensureDir(vfs, "/var/lib/apt/lists");
|
|
335
|
+
ensureDir(vfs, "/var/lib/dpkg");
|
|
336
|
+
ensureDir(vfs, "/var/lib/dpkg/info");
|
|
337
|
+
|
|
338
|
+
// dpkg status — starts empty, apt install populates it
|
|
339
|
+
ensureFile(vfs, "/var/lib/dpkg/status", "");
|
|
340
|
+
ensureFile(vfs, "/var/lib/dpkg/available", "");
|
|
341
|
+
|
|
342
|
+
// syslog stub
|
|
343
|
+
ensureFile(
|
|
344
|
+
vfs,
|
|
345
|
+
"/var/log/syslog",
|
|
346
|
+
`${new Date().toUTCString()} fortune kernel: Virtual container started\n`,
|
|
347
|
+
);
|
|
348
|
+
ensureFile(vfs, "/var/log/auth.log", "");
|
|
349
|
+
ensureFile(vfs, "/var/log/dpkg.log", "");
|
|
350
|
+
ensureFile(vfs, "/var/log/apt/history.log", "");
|
|
351
|
+
ensureFile(vfs, "/var/log/apt/term.log", "");
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ─── /bin + /sbin symlinks ────────────────────────────────────────────────────
|
|
355
|
+
|
|
356
|
+
function bootstrapBin(vfs: VirtualFileSystem): void {
|
|
357
|
+
// On modern Debian/Ubuntu /bin is a symlink to /usr/bin
|
|
358
|
+
if (!vfs.exists("/bin")) {
|
|
359
|
+
vfs.symlink("/usr/bin", "/bin");
|
|
360
|
+
}
|
|
361
|
+
if (!vfs.exists("/sbin")) {
|
|
362
|
+
vfs.symlink("/usr/sbin", "/sbin");
|
|
363
|
+
}
|
|
364
|
+
if (!vfs.exists("/lib")) {
|
|
365
|
+
ensureDir(vfs, "/lib");
|
|
366
|
+
}
|
|
367
|
+
if (!vfs.exists("/lib64")) {
|
|
368
|
+
ensureDir(vfs, "/lib64");
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ─── /tmp ─────────────────────────────────────────────────────────────────────
|
|
373
|
+
|
|
374
|
+
function bootstrapTmp(vfs: VirtualFileSystem): void {
|
|
375
|
+
ensureDir(vfs, "/tmp", 0o1777);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ─── /root ────────────────────────────────────────────────────────────────────
|
|
379
|
+
|
|
380
|
+
function bootstrapRoot(vfs: VirtualFileSystem): void {
|
|
381
|
+
ensureDir(vfs, "/root", 0o700);
|
|
382
|
+
ensureFile(
|
|
383
|
+
vfs,
|
|
384
|
+
"/root/.bashrc",
|
|
385
|
+
`${[
|
|
386
|
+
"# root .bashrc",
|
|
387
|
+
"export PS1='\\[\\033[0;31m\\]\\u@\\h\\[\\033[0m\\]:\\[\\033[0;34m\\]\\w\\[\\033[0m\\]# '",
|
|
388
|
+
"export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
389
|
+
"alias ll='ls -la'",
|
|
390
|
+
"alias la='ls -A'",
|
|
391
|
+
].join("\n")}\n`,
|
|
392
|
+
);
|
|
393
|
+
ensureFile(vfs, "/root/.profile", "[ -f ~/.bashrc ] && . ~/.bashrc\n");
|
|
394
|
+
// Fix: /home/root should map to /root for root user
|
|
395
|
+
if (!vfs.exists("/home/root")) {
|
|
396
|
+
vfs.symlink("/root", "/home/root");
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// ─── /opt + /srv + /mnt + /media ─────────────────────────────────────────────
|
|
401
|
+
|
|
402
|
+
function bootstrapMisc(vfs: VirtualFileSystem): void {
|
|
403
|
+
ensureDir(vfs, "/opt");
|
|
404
|
+
ensureDir(vfs, "/srv");
|
|
405
|
+
ensureDir(vfs, "/mnt");
|
|
406
|
+
ensureDir(vfs, "/media");
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// ─── main entry point ─────────────────────────────────────────────────────────
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Bootstraps the full Linux rootfs hierarchy in the VFS.
|
|
413
|
+
* Safe to call multiple times — idempotent.
|
|
414
|
+
*
|
|
415
|
+
* @param vfs Target virtual filesystem.
|
|
416
|
+
* @param users User manager (for /etc/passwd sync).
|
|
417
|
+
* @param hostname Virtual hostname.
|
|
418
|
+
* @param props Shell properties (kernel, os, arch).
|
|
419
|
+
* @param shellStartTime Unix ms of shell creation (for uptime).
|
|
420
|
+
*/
|
|
421
|
+
export function bootstrapLinuxRootfs(
|
|
422
|
+
vfs: VirtualFileSystem,
|
|
423
|
+
users: VirtualUserManager,
|
|
424
|
+
hostname: string,
|
|
425
|
+
props: ShellProperties,
|
|
426
|
+
shellStartTime: number,
|
|
427
|
+
): void {
|
|
428
|
+
bootstrapEtc(vfs, hostname, props);
|
|
429
|
+
bootstrapSys(vfs, props);
|
|
430
|
+
bootstrapDev(vfs);
|
|
431
|
+
bootstrapUsr(vfs);
|
|
432
|
+
bootstrapVar(vfs);
|
|
433
|
+
bootstrapBin(vfs);
|
|
434
|
+
bootstrapTmp(vfs);
|
|
435
|
+
bootstrapRoot(vfs);
|
|
436
|
+
bootstrapMisc(vfs);
|
|
437
|
+
refreshProc(vfs, props, hostname, shellStartTime);
|
|
438
|
+
syncEtcPasswd(vfs, users);
|
|
439
|
+
}
|
package/src/modules/neofetch.ts
CHANGED
|
@@ -321,6 +321,7 @@ export function buildNeofetchOutput(info: NeofetchInfo): string {
|
|
|
321
321
|
`Kernel: ${fields.kernel}`,
|
|
322
322
|
`Uptime: ${uptime}`,
|
|
323
323
|
// `Packages: ${fields.packages}`,
|
|
324
|
+
`Packages: ${fields.packages}`,
|
|
324
325
|
`Shell: ${fields.shell}`,
|
|
325
326
|
// `Shell Props: ${fields.shellProps}`,
|
|
326
327
|
`Resolution: ${fields.resolution}`,
|
package/src/standalone.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { VirtualSftpServer, VirtualShell, VirtualSshServer } from ".";
|
|
2
2
|
|
|
3
3
|
const hostname = process.env.SSH_MIMIC_HOSTNAME ?? "typescript-vm";
|
|
4
|
-
const virtualShell = new VirtualShell(hostname
|
|
4
|
+
const virtualShell = new VirtualShell(hostname, undefined, {
|
|
5
|
+
mode: "fs",
|
|
6
|
+
snapshotPath: ".vfs",
|
|
7
|
+
});
|
|
5
8
|
|
|
6
9
|
virtualShell.addCommand("demo", [], () => {
|
|
7
10
|
return {
|