ramm 0.0.34 → 0.0.36
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/dist/ramm.js +66 -58
- package/dist/types/files.d.ts +2 -2
- package/dist/types/nft.d.ts +1 -0
- package/dist/types/ramm.d.ts +1 -1
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -175,55 +175,6 @@ var createSystemdService = async (context, serviceName, pathToServiceFile) => {
|
|
|
175
175
|
await execCommand(formatUserspace(context, `sysyemctl start ${serviceName}`));
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
-
// src/podman.ts
|
|
179
|
-
var installPodman = async () => {
|
|
180
|
-
if ((await $2`command -v podman`.nothrow().quiet()).exitCode !== 0) {
|
|
181
|
-
await installSystemPackage("podman");
|
|
182
|
-
}
|
|
183
|
-
await createNetwork();
|
|
184
|
-
};
|
|
185
|
-
var createNetwork = async () => {
|
|
186
|
-
const netwroks = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
|
|
187
|
-
const podmanNetworks = await execCommand("podman network ls");
|
|
188
|
-
if (podmanNetworks.stdout.includes("ramm")) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (netwroks.stdout.includes("podman_ramm")) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
await execCommand("podman network create --interface-name=podman_ramm ramm");
|
|
195
|
-
};
|
|
196
|
-
var getCreateCommand = async (name) => {
|
|
197
|
-
const podmanCreateCommand = await $2`podman inspect --format '{{.Config.CreateCommand}}' ${name}`.nothrow().quiet();
|
|
198
|
-
return podmanCreateCommand.text().slice(0, -1).slice(1, -1) || "";
|
|
199
|
-
};
|
|
200
|
-
var loginPodman = async (address, login, password) => {
|
|
201
|
-
return await execCommand(`echo "${password}" | podman login --username "${login}" --password-stdin ${address}`);
|
|
202
|
-
};
|
|
203
|
-
var runPodmanContainer = async (name, command) => {
|
|
204
|
-
if (await getCreateCommand(name) !== command) {
|
|
205
|
-
await $2`podman rm -f ${name}`;
|
|
206
|
-
await execCommand(command);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
console.info("Podman container is already running");
|
|
210
|
-
};
|
|
211
|
-
var runPodmanContainerService = async (name, command, context = defaultContext) => {
|
|
212
|
-
const serviceName = getSysyemdServiceName(name);
|
|
213
|
-
if (await checkSystemdService(context, serviceName)) {
|
|
214
|
-
await stopSystemdService(context, serviceName);
|
|
215
|
-
}
|
|
216
|
-
await runPodmanContainer(name, command);
|
|
217
|
-
await execCommand(`podman generate systemd --name --new ${name} > ${serviceName}`);
|
|
218
|
-
await createSystemdService(context, serviceName, serviceName);
|
|
219
|
-
};
|
|
220
|
-
var addNftPodmanRule = async () => {
|
|
221
|
-
const podmanNetworksResult = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
|
|
222
|
-
const podmanNetworks = podmanNetworksResult.stdout.trim().split(`
|
|
223
|
-
`);
|
|
224
|
-
await execCommand(`nft add set inet ramm podman_interfaces '{ type ifname; flags dynamic; elements = { ${podmanNetworks.join(", ")} }; }'`);
|
|
225
|
-
await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
|
|
226
|
-
};
|
|
227
178
|
// src/nft.ts
|
|
228
179
|
var createNftTable = ({
|
|
229
180
|
allowedIpV4,
|
|
@@ -266,14 +217,71 @@ var setupNftable = async ({
|
|
|
266
217
|
allowedIpV4,
|
|
267
218
|
allowedPorts
|
|
268
219
|
}) => {
|
|
269
|
-
await execCommand("nft
|
|
220
|
+
const listTable = await execCommand("nft list table inet ramm");
|
|
221
|
+
if (listTable.spawnResult.exitCode === 0) {
|
|
222
|
+
await execCommand("nft delete table inet ramm");
|
|
223
|
+
}
|
|
270
224
|
const nftTable = createNftTable({ allowedIpV4, allowedPorts });
|
|
271
225
|
await execCommand(`nft -f - <<EOF
|
|
272
226
|
${nftTable}
|
|
273
227
|
EOF`);
|
|
228
|
+
await safeNftTable();
|
|
229
|
+
};
|
|
230
|
+
var safeNftTable = async () => {
|
|
274
231
|
await execCommand("nft list ruleset > /etc/nftables.conf");
|
|
275
232
|
await execCommand("systemctl enable nftables");
|
|
276
233
|
};
|
|
234
|
+
|
|
235
|
+
// src/podman.ts
|
|
236
|
+
var installPodman = async () => {
|
|
237
|
+
if ((await $2`command -v podman`.nothrow().quiet()).exitCode !== 0) {
|
|
238
|
+
await installSystemPackage("podman");
|
|
239
|
+
}
|
|
240
|
+
await createNetwork();
|
|
241
|
+
};
|
|
242
|
+
var createNetwork = async () => {
|
|
243
|
+
const netwroks = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
|
|
244
|
+
const podmanNetworks = await execCommand("podman network ls");
|
|
245
|
+
if (podmanNetworks.stdout.includes("ramm")) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (netwroks.stdout.includes("podman_ramm")) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
await execCommand("podman network create --interface-name=podman_ramm ramm");
|
|
252
|
+
};
|
|
253
|
+
var getCreateCommand = async (name) => {
|
|
254
|
+
const podmanCreateCommand = await $2`podman inspect --format '{{.Config.CreateCommand}}' ${name}`.nothrow().quiet();
|
|
255
|
+
return podmanCreateCommand.text().slice(0, -1).slice(1, -1) || "";
|
|
256
|
+
};
|
|
257
|
+
var loginPodman = async (address, login, password) => {
|
|
258
|
+
return await execCommand(`echo "${password}" | podman login --username "${login}" --password-stdin ${address}`);
|
|
259
|
+
};
|
|
260
|
+
var runPodmanContainer = async (name, command) => {
|
|
261
|
+
if (await getCreateCommand(name) !== command) {
|
|
262
|
+
await $2`podman rm -f ${name}`;
|
|
263
|
+
await execCommand(command);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
console.info("Podman container is already running");
|
|
267
|
+
};
|
|
268
|
+
var runPodmanContainerService = async (name, command, context = defaultContext) => {
|
|
269
|
+
const serviceName = getSysyemdServiceName(name);
|
|
270
|
+
if (await checkSystemdService(context, serviceName)) {
|
|
271
|
+
await stopSystemdService(context, serviceName);
|
|
272
|
+
}
|
|
273
|
+
await runPodmanContainer(name, command);
|
|
274
|
+
await execCommand(`podman generate systemd --name --new ${name} > ${serviceName}`);
|
|
275
|
+
await createSystemdService(context, serviceName, serviceName);
|
|
276
|
+
};
|
|
277
|
+
var addNftPodmanRule = async () => {
|
|
278
|
+
const podmanNetworksResult = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
|
|
279
|
+
const podmanNetworks = podmanNetworksResult.stdout.trim().split(`
|
|
280
|
+
`);
|
|
281
|
+
await execCommand(`nft add set inet ramm podman_interfaces '{ type ifname; flags dynamic; elements = { ${podmanNetworks.join(", ")} }; }'`);
|
|
282
|
+
await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
|
|
283
|
+
await safeNftTable();
|
|
284
|
+
};
|
|
277
285
|
// src/files.ts
|
|
278
286
|
import { appendFile, exists } from "fs/promises";
|
|
279
287
|
var {file, write } = globalThis.Bun;
|
|
@@ -327,7 +335,7 @@ var createFileIfNeed = async (rawFilePath) => {
|
|
|
327
335
|
await execCommand(`touch ${filePath}`);
|
|
328
336
|
}
|
|
329
337
|
};
|
|
330
|
-
var
|
|
338
|
+
var writeIfNewStr = async (rawFilePath, str) => {
|
|
331
339
|
const filePath = normalizePath(rawFilePath);
|
|
332
340
|
await createFileIfNeed(filePath);
|
|
333
341
|
if (await checkStrInFile(filePath, str)) {
|
|
@@ -340,7 +348,7 @@ var writeFile = async (pathToFile, str) => {
|
|
|
340
348
|
await createFileIfNeed(normalizedPath);
|
|
341
349
|
await write(normalizedPath, str);
|
|
342
350
|
};
|
|
343
|
-
var
|
|
351
|
+
var writeFileFull = async (pathToFile, str) => {
|
|
344
352
|
const normalizedPath = normalizePath(pathToFile);
|
|
345
353
|
await createFileIfNeed(normalizedPath);
|
|
346
354
|
const fileText = await file(normalizedPath).text();
|
|
@@ -355,7 +363,7 @@ var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
|
|
|
355
363
|
const text = `Host ${address}
|
|
356
364
|
IdentityFile ${pathToKey}
|
|
357
365
|
`;
|
|
358
|
-
await
|
|
366
|
+
await writeIfNewStr(pathToHost, text);
|
|
359
367
|
};
|
|
360
368
|
var getServerFingerprint = async (context) => {
|
|
361
369
|
const { stdout } = await execCommandOverSsh('ssh-keyscan -t ed25519 localhost | grep -v "^#"', context);
|
|
@@ -364,7 +372,7 @@ var getServerFingerprint = async (context) => {
|
|
|
364
372
|
var saveSshFingerptint = async (filePath, context) => {
|
|
365
373
|
const normalizedPath = normalizePath(filePath);
|
|
366
374
|
const fingerprint = await getServerFingerprint(context);
|
|
367
|
-
await
|
|
375
|
+
await writeFileFull(filePath, normalizedPath);
|
|
368
376
|
};
|
|
369
377
|
async function createSshKey(filePath, comment) {
|
|
370
378
|
printFunction(`${createSshKey.name} ${filePath}`);
|
|
@@ -405,9 +413,9 @@ var addSshKeyToUse = async ({
|
|
|
405
413
|
}) => {
|
|
406
414
|
printFunction(`${addSshKeyToUse.name} ${filePath}`);
|
|
407
415
|
const normalizedFilePath = normalizePath(filePath);
|
|
408
|
-
await
|
|
416
|
+
await writeFileFull(normalizedFilePath, key);
|
|
409
417
|
await execCommand(`chmod 0600 ${normalizedFilePath}`);
|
|
410
|
-
await
|
|
418
|
+
await writeIfNewStr("~/.ssh/known_hosts", fingerprint);
|
|
411
419
|
await addKeyToHostConfig("~/.ssh/config", server, normalizedFilePath);
|
|
412
420
|
};
|
|
413
421
|
// src/cron.ts
|
|
@@ -469,8 +477,8 @@ var passVarsServer = async () => {
|
|
|
469
477
|
return jsonData;
|
|
470
478
|
};
|
|
471
479
|
export {
|
|
472
|
-
|
|
473
|
-
|
|
480
|
+
writeIfNewStr,
|
|
481
|
+
writeFileFull,
|
|
474
482
|
writeFile,
|
|
475
483
|
setupNftable,
|
|
476
484
|
saveSshFingerptint,
|
package/dist/types/files.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const normalizeFileContent: (str: string) => string;
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const writeIfNewStr: (rawFilePath: string, str: string) => Promise<void>;
|
|
3
3
|
export declare const writeFile: (pathToFile: string, str: string) => Promise<void>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const writeFileFull: (pathToFile: string, str: string) => Promise<void>;
|
package/dist/types/nft.d.ts
CHANGED
package/dist/types/ramm.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { restartSystemdService } from "./systemd.ts";
|
|
|
7
7
|
export { installSystemPackage } from "./packages.ts";
|
|
8
8
|
export { printBlock } from "./print.ts";
|
|
9
9
|
export { setupNftable } from "./nft.ts";
|
|
10
|
-
export {
|
|
10
|
+
export { writeIfNewStr, writeFile, writeFileFull, normalizeFileContent, } from "./files.ts";
|
|
11
11
|
export { createAndAddSshKey, getServerFingerprint, addKeyToHostConfig, addSshKeyToUse, saveSshFingerptint, } from "./ssh.ts";
|
|
12
12
|
export { normalizePath } from "./path.ts";
|
|
13
13
|
export { createCron } from "./cron.ts";
|
package/package.json
CHANGED