ramm 0.0.6 → 0.0.8

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 CHANGED
@@ -216,8 +216,53 @@ 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, exists } from "fs/promises";
221
+ var finalizeWithNewline = (str) => {
222
+ if (str.at(-1) !== `
223
+ `) {
224
+ return str + `
225
+ `;
226
+ }
227
+ return str;
228
+ };
229
+ var createDir = async (str) => {
230
+ const dirname = str.split("/").slice(0, -1).join("/");
231
+ const exist = await exists(dirname);
232
+ if (exist) {
233
+ return;
234
+ }
235
+ await execCommand(`mkdir -p ${dirname}`);
236
+ };
237
+ var checkStrInFile = async (filePath, str) => {
238
+ const file = Bun.file(filePath);
239
+ if (!await file.exists()) {
240
+ return false;
241
+ }
242
+ const fileText = await file.text();
243
+ if (fileText.includes(str)) {
244
+ return true;
245
+ }
246
+ return false;
247
+ };
248
+ var writeIfNew = async (filePath, str) => {
249
+ await createDir(filePath);
250
+ if (await checkStrInFile(filePath, str)) {
251
+ return;
252
+ }
253
+ if (!await Bun.file(filePath).exists()) {
254
+ await execCommand(`touch ${filePath}`);
255
+ }
256
+ await appendFile(filePath, finalizeWithNewline(str));
257
+ };
219
258
  // src/ssh.ts
220
259
  import { debug } from "console";
260
+ var addKeyToHostConfig = async (address, pathToKey) => {
261
+ const text = `Host ${address}
262
+ IdentityFile ${pathToKey}
263
+ `;
264
+ await writeIfNew(pathToKey, text);
265
+ };
221
266
  var getServerFingerprintBySsh = async (context) => {
222
267
  const { output } = await execBySsh('ssh-keyscan -t ed25519 localhost | grep -v "^#"', context);
223
268
  return output.replace("localhost", context.domain);
@@ -250,6 +295,7 @@ var createAndAddSshKey = async (pathToKey, comment, context) => {
250
295
  await addSshKey(pubKey, context);
251
296
  };
252
297
  export {
298
+ writeIfNew,
253
299
  setupNftable,
254
300
  runPodmanContainerService,
255
301
  runPodmanContainer,
@@ -264,5 +310,6 @@ export {
264
310
  createAndAddSshKey,
265
311
  copyFilesBySsh,
266
312
  addNftPodmanRule,
313
+ addKeyToHostConfig,
267
314
  Context
268
315
  };
@@ -0,0 +1 @@
1
+ export declare const writeIfNew: (filePath: string, str: string) => Promise<void>;
@@ -7,4 +7,5 @@ export { restartSystemdService } from "./systemd.ts";
7
7
  export { installSystemPackage } from "./packages.ts";
8
8
  export { debugBlock } from "./debug.ts";
9
9
  export { setupNftable } from "./nft.ts";
10
- export { createAndAddSshKey, getServerFingerprintBySsh } from "./ssh.ts";
10
+ export { writeIfNew } from "./files.ts";
11
+ export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
@@ -1,4 +1,4 @@
1
1
  import type { Context } from "./context.ts";
2
- export declare const setupHostConfig: (address: string, pathToKey: string) => void;
2
+ export declare const addKeyToHostConfig: (address: string, pathToKey: string) => Promise<void>;
3
3
  export declare const getServerFingerprintBySsh: (context: Context) => Promise<string>;
4
4
  export declare const createAndAddSshKey: (pathToKey: string, comment: string, context: Context) => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "scripts": {
6
6
  "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh && bun run types",
7
7
  "types": "tsc --project tsconfig.types.json"