ramm 0.0.4 → 0.0.5
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 +46 -12
- package/dist/types/dist/ramm.d.ts +30 -0
- package/dist/types/src/base.d.ts +15 -0
- package/dist/types/src/context.d.ts +15 -0
- package/dist/types/src/debug.d.ts +4 -0
- package/dist/types/src/init.d.ts +2 -0
- package/dist/types/src/nft.d.ts +2 -0
- package/dist/types/src/packages.d.ts +1 -0
- package/dist/types/src/podman.d.ts +6 -0
- package/dist/types/src/ramm.d.ts +10 -0
- package/dist/types/src/ssh.d.ts +2 -0
- package/dist/types/src/systemd.d.ts +6 -0
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -12,7 +12,7 @@ var debugSilentCommand = (command) => {
|
|
|
12
12
|
var debugCommand = (command) => {
|
|
13
13
|
debugInternal("\x1B[32mCommand\x1B[0m", `\x1B[38;5;85m${command}\x1B[0m`);
|
|
14
14
|
};
|
|
15
|
-
var
|
|
15
|
+
var debugBlock = (text) => {
|
|
16
16
|
debugInternal("\x1B[34mBlock\x1B[0m", `\x1B[38;5;81m${text}\x1B[0m`);
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -22,16 +22,19 @@ class Context {
|
|
|
22
22
|
domain;
|
|
23
23
|
userspace;
|
|
24
24
|
sudo;
|
|
25
|
+
sshKey;
|
|
25
26
|
constructor({
|
|
26
27
|
name,
|
|
27
28
|
address,
|
|
28
29
|
userspace = false,
|
|
29
|
-
sudo = false
|
|
30
|
+
sudo = false,
|
|
31
|
+
sshKey
|
|
30
32
|
}) {
|
|
31
33
|
this.name = name;
|
|
32
34
|
this.domain = address;
|
|
33
35
|
this.sudo = sudo;
|
|
34
36
|
this.userspace = userspace;
|
|
37
|
+
this.sshKey = sshKey;
|
|
35
38
|
}
|
|
36
39
|
getAddress() {
|
|
37
40
|
return `${this.name}@${this.domain}`;
|
|
@@ -94,17 +97,18 @@ var execCommandSilent = async (command) => {
|
|
|
94
97
|
spawnResult: result
|
|
95
98
|
};
|
|
96
99
|
};
|
|
97
|
-
var
|
|
100
|
+
var copyFilesBySsh = async (from, to, context) => {
|
|
98
101
|
await execCommand(`rsync -avz ${from} ${context.getAddress()}:${to}`);
|
|
99
102
|
};
|
|
100
|
-
var
|
|
101
|
-
|
|
103
|
+
var execBySsh = async (command, context) => {
|
|
104
|
+
const sshKeyPart = context.sshKey ? ` -i ${context.sshKey}` : "";
|
|
105
|
+
return await execCommand(`ssh${sshKeyPart} ${context.getAddress()} '${command}'`);
|
|
102
106
|
};
|
|
103
107
|
// src/init.ts
|
|
104
108
|
var installBun = async (context) => {
|
|
105
109
|
const bunPath = new URL(import.meta.resolve("./bun.sh")).pathname;
|
|
106
|
-
await
|
|
107
|
-
await
|
|
110
|
+
await copyFilesBySsh(bunPath, "./bun.sh", context);
|
|
111
|
+
await execBySsh("./bun.sh", context);
|
|
108
112
|
};
|
|
109
113
|
// src/podman.ts
|
|
110
114
|
var {$: $2 } = globalThis.Bun;
|
|
@@ -209,8 +213,37 @@ var addNftPodmanRule = async () => {
|
|
|
209
213
|
const podmanNetworks = podmanNetworksResult.output.trim().split(`
|
|
210
214
|
`);
|
|
211
215
|
await execCommand(`nft add set inet ramm podman_interfaces '{ type ifname; flags dynamic; elements = { ${podmanNetworks.join(", ")} }; }'`);
|
|
212
|
-
await execCommand("nft add chain inet ramm forward '{ type filter hook
|
|
213
|
-
await execCommand(`nft add rule inet ramm forward iifname @podman_interfaces jump ${localNftChainName}`);
|
|
216
|
+
await execCommand("nft add chain inet ramm forward '{ type filter hook forward priority 0 ; }'");
|
|
217
|
+
await execCommand(`nft add rule inet ramm forward iifname != @podman_interfaces jump ${localNftChainName}`);
|
|
218
|
+
};
|
|
219
|
+
// src/ssh.ts
|
|
220
|
+
import { debug } from "console";
|
|
221
|
+
async function createSshKey(pathToKey, comment) {
|
|
222
|
+
const name = pathToKey.split("/").at(-1);
|
|
223
|
+
const pathToKeyPub = `${pathToKey}.pub`;
|
|
224
|
+
const pathToDir = pathToKey.split("/").slice(0, -1).join("/");
|
|
225
|
+
const pathToKeyFile = Bun.file(pathToKey);
|
|
226
|
+
const pathToKeyPubFile = Bun.file(pathToKeyPub);
|
|
227
|
+
if (await pathToKeyFile.exists() && await pathToKeyPubFile.exists()) {
|
|
228
|
+
return await pathToKeyPubFile.text();
|
|
229
|
+
}
|
|
230
|
+
await execCommand(`mkdir -p ${pathToDir}`);
|
|
231
|
+
await execCommand(`ssh-keygen -t ed25519 -f ${pathToKey} -N "" -C "${comment || name}"`);
|
|
232
|
+
await execCommand(`chmod 600 ${pathToKey}`);
|
|
233
|
+
const pubKey = await Bun.file(pathToKeyPub).text();
|
|
234
|
+
return pubKey;
|
|
235
|
+
}
|
|
236
|
+
var addSshKey = async (pubKey, context) => {
|
|
237
|
+
const { output: keys } = await execBySsh("cat .ssh/authorized_keys", context);
|
|
238
|
+
if (keys.includes(pubKey)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
await execBySsh(`echo "${pubKey}" >> .ssh/authorized_keys`, context);
|
|
242
|
+
};
|
|
243
|
+
var createAndAddSshKey = async (pathToKey, comment, context) => {
|
|
244
|
+
const pubKey = await createSshKey(pathToKey, comment);
|
|
245
|
+
debug(`Key is: ${pubKey}`);
|
|
246
|
+
await addSshKey(pubKey, context);
|
|
214
247
|
};
|
|
215
248
|
export {
|
|
216
249
|
setupNftable,
|
|
@@ -220,9 +253,10 @@ export {
|
|
|
220
253
|
installSystemPackage,
|
|
221
254
|
installPodman,
|
|
222
255
|
installBun,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
256
|
+
execBySsh,
|
|
257
|
+
debugBlock,
|
|
258
|
+
createAndAddSshKey,
|
|
259
|
+
copyFilesBySsh,
|
|
226
260
|
addNftPodmanRule,
|
|
227
261
|
Context
|
|
228
262
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function setupNftable(allowedIpSsh: any): Promise<void>;
|
|
2
|
+
export function runPodmanContainerService(name: any, command: any, context?: Context): Promise<void>;
|
|
3
|
+
export function runPodmanContainer(name: any, command: any): Promise<void>;
|
|
4
|
+
export function restartSystemdService(name: any, constext?: Context): Promise<void>;
|
|
5
|
+
export function installSystemPackage(packageName: any): Promise<void>;
|
|
6
|
+
export function installPodman(): Promise<void>;
|
|
7
|
+
export function installBun(context: any): Promise<void>;
|
|
8
|
+
export function execBySsh(command: any, context: any): Promise<{
|
|
9
|
+
output: string;
|
|
10
|
+
spawnResult: import("bun").Subprocess<"inherit", "pipe", "inherit">;
|
|
11
|
+
}>;
|
|
12
|
+
export function debugBlock(text: any): void;
|
|
13
|
+
export function createAndAddSshKey(pathToKey: any, comment: any, context: any): Promise<void>;
|
|
14
|
+
export function copyFilesBySsh(from: any, to: any, context: any): Promise<void>;
|
|
15
|
+
export function addNftPodmanRule(): Promise<void>;
|
|
16
|
+
export class Context {
|
|
17
|
+
constructor({ name, address, userspace, sudo, sshKey }: {
|
|
18
|
+
name: any;
|
|
19
|
+
address: any;
|
|
20
|
+
userspace?: boolean | undefined;
|
|
21
|
+
sudo?: boolean | undefined;
|
|
22
|
+
sshKey: any;
|
|
23
|
+
});
|
|
24
|
+
name: any;
|
|
25
|
+
domain: any;
|
|
26
|
+
userspace: boolean;
|
|
27
|
+
sudo: boolean;
|
|
28
|
+
sshKey: any;
|
|
29
|
+
getAddress(): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Context } from "./context.ts";
|
|
2
|
+
export declare const defaultContext: Context;
|
|
3
|
+
export declare const execCommand: (command: string) => Promise<{
|
|
4
|
+
output: string;
|
|
5
|
+
spawnResult: import("bun").Subprocess<"inherit", "pipe", "inherit">;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const execCommandSilent: (command: string) => Promise<{
|
|
8
|
+
output: string;
|
|
9
|
+
spawnResult: import("bun").Subprocess<"ignore", "pipe", "inherit">;
|
|
10
|
+
}>;
|
|
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
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class Context {
|
|
2
|
+
name: string;
|
|
3
|
+
domain: string;
|
|
4
|
+
userspace: boolean;
|
|
5
|
+
sudo: boolean;
|
|
6
|
+
sshKey?: string;
|
|
7
|
+
constructor({ name, address, userspace, sudo, sshKey, }: {
|
|
8
|
+
name: string;
|
|
9
|
+
address: string;
|
|
10
|
+
userspace?: boolean;
|
|
11
|
+
sudo?: boolean;
|
|
12
|
+
sshKey?: string;
|
|
13
|
+
});
|
|
14
|
+
getAddress(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const installSystemPackage: (packageName: string) => Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from "./context.ts";
|
|
2
|
+
export declare const installPodman: () => Promise<void>;
|
|
3
|
+
export declare const getCreateCommand: (name: string) => Promise<string>;
|
|
4
|
+
export declare const runPodmanContainer: (name: string, command: string) => Promise<void>;
|
|
5
|
+
export declare const runPodmanContainerService: (name: string, command: string, context?: Context) => Promise<void>;
|
|
6
|
+
export declare const addNftPodmanRule: () => Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { execBySsh, copyFilesBySsh } from "./base.ts";
|
|
2
|
+
export { Context } from "./context.ts";
|
|
3
|
+
export { installBun } from "./init.ts";
|
|
4
|
+
export { installPodman, runPodmanContainer } from "./podman.ts";
|
|
5
|
+
export { runPodmanContainerService, addNftPodmanRule } from "./podman.ts";
|
|
6
|
+
export { restartSystemdService } from "./systemd.ts";
|
|
7
|
+
export { installSystemPackage } from "./packages.ts";
|
|
8
|
+
export { debugBlock } from "./debug.ts";
|
|
9
|
+
export { setupNftable } from "./nft.ts";
|
|
10
|
+
export { createAndAddSshKey } from "./ssh.ts";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Context } from "./context.ts";
|
|
2
|
+
export declare const getSysyemdServiceName: (name: string) => string;
|
|
3
|
+
export declare const stopSystemdService: (constext: Context, name: string) => Promise<void>;
|
|
4
|
+
export declare const restartSystemdService: (name: string, constext?: Context) => Promise<void>;
|
|
5
|
+
export declare const checkSystemdService: (context: Context, serviceName: string) => Promise<boolean>;
|
|
6
|
+
export declare const createSystemdService: (context: Context, serviceName: string, pathToServiceFile: string) => Promise<void>;
|
package/package.json
CHANGED