ramm 0.0.5 → 0.0.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/dist/ramm.js +41 -0
- package/dist/types/base.d.ts +5 -2
- package/dist/types/context.d.ts +3 -1
- package/dist/types/debug.d.ts +1 -0
- package/dist/types/files.d.ts +1 -0
- package/dist/types/ramm.d.ts +4 -2
- package/dist/types/ssh.d.ts +4 -0
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -216,8 +216,45 @@ var addNftPodmanRule = async () => {
|
|
|
216
216
|
await execCommand("nft add chain inet ramm forward '{ type filter hook forward priority 0 ; }'");
|
|
217
217
|
await execCommand(`nft add rule inet ramm forward iifname != @podman_interfaces jump ${localNftChainName}`);
|
|
218
218
|
};
|
|
219
|
+
// src/files.ts
|
|
220
|
+
import { appendFile } from "fs/promises";
|
|
221
|
+
var finalizeWithNewline = (str) => {
|
|
222
|
+
if (str.at(-1) !== `
|
|
223
|
+
`) {
|
|
224
|
+
return str + `
|
|
225
|
+
`;
|
|
226
|
+
}
|
|
227
|
+
return str;
|
|
228
|
+
};
|
|
229
|
+
var checkStrInFile = async (filePath, str) => {
|
|
230
|
+
const file = Bun.file(filePath);
|
|
231
|
+
if (!await file.exists()) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
const fileText = await file.text();
|
|
235
|
+
if (fileText.includes(str)) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
};
|
|
240
|
+
var writeIfNew = async (filePath, str) => {
|
|
241
|
+
if (await checkStrInFile(filePath, str)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
await appendFile(filePath, finalizeWithNewline(str));
|
|
245
|
+
};
|
|
219
246
|
// src/ssh.ts
|
|
220
247
|
import { debug } from "console";
|
|
248
|
+
var addKeyToHostConfig = async (address, pathToKey) => {
|
|
249
|
+
const text = `Host ${address}
|
|
250
|
+
IdentityFile ${pathToKey}
|
|
251
|
+
`;
|
|
252
|
+
await writeIfNew(pathToKey, text);
|
|
253
|
+
};
|
|
254
|
+
var getServerFingerprintBySsh = async (context) => {
|
|
255
|
+
const { output } = await execBySsh('ssh-keyscan -t ed25519 localhost | grep -v "^#"', context);
|
|
256
|
+
return output.replace("localhost", context.domain);
|
|
257
|
+
};
|
|
221
258
|
async function createSshKey(pathToKey, comment) {
|
|
222
259
|
const name = pathToKey.split("/").at(-1);
|
|
223
260
|
const pathToKeyPub = `${pathToKey}.pub`;
|
|
@@ -246,6 +283,7 @@ var createAndAddSshKey = async (pathToKey, comment, context) => {
|
|
|
246
283
|
await addSshKey(pubKey, context);
|
|
247
284
|
};
|
|
248
285
|
export {
|
|
286
|
+
writeIfNew,
|
|
249
287
|
setupNftable,
|
|
250
288
|
runPodmanContainerService,
|
|
251
289
|
runPodmanContainer,
|
|
@@ -253,10 +291,13 @@ export {
|
|
|
253
291
|
installSystemPackage,
|
|
254
292
|
installPodman,
|
|
255
293
|
installBun,
|
|
294
|
+
getServerFingerprintBySsh,
|
|
295
|
+
execCommand,
|
|
256
296
|
execBySsh,
|
|
257
297
|
debugBlock,
|
|
258
298
|
createAndAddSshKey,
|
|
259
299
|
copyFilesBySsh,
|
|
260
300
|
addNftPodmanRule,
|
|
301
|
+
addKeyToHostConfig,
|
|
261
302
|
Context
|
|
262
303
|
};
|
package/dist/types/base.d.ts
CHANGED
|
@@ -8,5 +8,8 @@ export declare const execCommandSilent: (command: string) => Promise<{
|
|
|
8
8
|
output: string;
|
|
9
9
|
spawnResult: import("bun").Subprocess<"ignore", "pipe", "inherit">;
|
|
10
10
|
}>;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const copyFilesBySsh: (from: string, to: string, context: Context) => Promise<void>;
|
|
12
|
+
export declare const execBySsh: (command: string, context: Context) => Promise<{
|
|
13
|
+
output: string;
|
|
14
|
+
spawnResult: import("bun").Subprocess<"inherit", "pipe", "inherit">;
|
|
15
|
+
}>;
|
package/dist/types/context.d.ts
CHANGED
|
@@ -3,11 +3,13 @@ export declare class Context {
|
|
|
3
3
|
domain: string;
|
|
4
4
|
userspace: boolean;
|
|
5
5
|
sudo: boolean;
|
|
6
|
-
|
|
6
|
+
sshKey?: string;
|
|
7
|
+
constructor({ name, address, userspace, sudo, sshKey, }: {
|
|
7
8
|
name: string;
|
|
8
9
|
address: string;
|
|
9
10
|
userspace?: boolean;
|
|
10
11
|
sudo?: boolean;
|
|
12
|
+
sshKey?: string;
|
|
11
13
|
});
|
|
12
14
|
getAddress(): string;
|
|
13
15
|
}
|
package/dist/types/debug.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const writeIfNew: (filePath: string, str: string) => Promise<void>;
|
package/dist/types/ramm.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { execBySsh, execCommand, copyFilesBySsh } from "./base.ts";
|
|
2
2
|
export { Context } from "./context.ts";
|
|
3
3
|
export { installBun } from "./init.ts";
|
|
4
4
|
export { installPodman, runPodmanContainer } from "./podman.ts";
|
|
5
5
|
export { runPodmanContainerService, addNftPodmanRule } from "./podman.ts";
|
|
6
6
|
export { restartSystemdService } from "./systemd.ts";
|
|
7
7
|
export { installSystemPackage } from "./packages.ts";
|
|
8
|
-
export {
|
|
8
|
+
export { debugBlock } from "./debug.ts";
|
|
9
9
|
export { setupNftable } from "./nft.ts";
|
|
10
|
+
export { writeIfNew } from "./files.ts";
|
|
11
|
+
export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context } from "./context.ts";
|
|
2
|
+
export declare const addKeyToHostConfig: (address: string, pathToKey: string) => Promise<void>;
|
|
3
|
+
export declare const getServerFingerprintBySsh: (context: Context) => Promise<string>;
|
|
4
|
+
export declare const createAndAddSshKey: (pathToKey: string, comment: string, context: Context) => Promise<void>;
|
package/package.json
CHANGED