ramm 0.0.30 → 0.0.32

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
@@ -118,10 +118,6 @@ var execCommand = async (command, props) => {
118
118
  var copyFilesBySsh = async (from, to, context) => {
119
119
  await execCommand(`rsync -avz ${from} ${context.getAddress()}:${to}`);
120
120
  };
121
- var execBySsh = async (command, context) => {
122
- const sshKeyPart = context.sshKey ? ` -i ${context.sshKey}` : "";
123
- return await execCommand(`ssh${sshKeyPart} ${context.getAddress()} '${command}'`);
124
- };
125
121
  var execCommandOverSsh = async (command, context) => {
126
122
  const sshKeyPart = context.sshKey ? ` -i ${context.sshKey}` : "";
127
123
  return await execCommand(`ssh${sshKeyPart} ${context.getAddress()} '${command}'`);
@@ -130,7 +126,7 @@ var execCommandOverSsh = async (command, context) => {
130
126
  var installBun = async (context) => {
131
127
  const bunPath = new URL(import.meta.resolve("./bun.sh")).pathname;
132
128
  await copyFilesBySsh(bunPath, "./bun.sh", context);
133
- await execBySsh("./bun.sh", context);
129
+ await execCommandOverSsh("./bun.sh", context);
134
130
  };
135
131
  // src/podman.ts
136
132
  var {$: $2 } = globalThis.Bun;
@@ -348,7 +344,6 @@ var writeIfNewCompletely = async (pathToFile, str) => {
348
344
  await write(normalizedPath, str);
349
345
  };
350
346
  // src/ssh.ts
351
- import { debug } from "console";
352
347
  var {file: file2 } = globalThis.Bun;
353
348
  var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
354
349
  const text = `Host ${address}
@@ -356,48 +351,57 @@ var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
356
351
  `;
357
352
  await writeIfNew(pathToHost, text);
358
353
  };
359
- var getServerFingerprintBySsh = async (context) => {
360
- const { stdout } = await execBySsh('ssh-keyscan -t ed25519 localhost | grep -v "^#"', context);
354
+ var getServerFingerprint = async (context) => {
355
+ const { stdout } = await execCommandOverSsh('ssh-keyscan -t ed25519 localhost | grep -v "^#"', context);
361
356
  return stdout.replace("localhost", context.domain);
362
357
  };
363
- async function createSshKey(pathToKey, comment) {
364
- printFunction(createSshKey.name);
365
- const name = pathToKey.split("/").at(-1);
366
- const pathToKeyPub = `${pathToKey}.pub`;
367
- const pathToDir = pathToKey.split("/").slice(0, -1).join("/");
368
- const pathToKeyFile = file2(pathToKey);
358
+ var saveSshFingerptint = async (filePath, context) => {
359
+ const fingerprint = await getServerFingerprint(context);
360
+ await writeIfNewCompletely(filePath, fingerprint);
361
+ };
362
+ async function createSshKey(filePath, comment) {
363
+ printFunction(`${createSshKey.name} ${filePath}`);
364
+ const normalizedPathToKey = normalizePath(filePath);
365
+ const name = normalizedPathToKey.split("/").at(-1);
366
+ const pathToKeyPub = `${normalizedPathToKey}.pub`;
367
+ const pathToDir = normalizedPathToKey.split("/").slice(0, -1).join("/");
368
+ const pathToKeyFile = file2(normalizedPathToKey);
369
369
  const pathToKeyPubFile = file2(pathToKeyPub);
370
370
  if (await pathToKeyFile.exists() && await pathToKeyPubFile.exists()) {
371
371
  return await pathToKeyPubFile.text();
372
372
  }
373
373
  await execCommand(`mkdir -p ${pathToDir}`);
374
- await execCommand(`ssh-keygen -t ed25519 -f ${pathToKey} -N "" -C "${comment || name}"`);
375
- await execCommand(`chmod 600 ${pathToKey}`);
374
+ await execCommand(`ssh-keygen -t ed25519 -f ${normalizedPathToKey} -N "" -C "${comment || name}"`);
375
+ await execCommand(`chmod 600 ${normalizedPathToKey}`);
376
376
  const pubKey = await Bun.file(pathToKeyPub).text();
377
377
  return pubKey;
378
378
  }
379
- var addSshKeyToAuthorized = async (pubKey, context) => {
380
- const { stdout: keys } = await execBySsh("cat .ssh/authorized_keys", context);
379
+ var addSshKeyToAuthorizedOverSsh = async (pubKey, context) => {
380
+ printFunction(`${addSshKeyToAuthorizedOverSsh.name} ${pubKey}`);
381
+ const { stdout: keys } = await execCommandOverSsh("cat .ssh/authorized_keys", context);
381
382
  if (keys.includes(pubKey)) {
382
383
  return;
383
384
  }
384
- await execBySsh(`echo "${pubKey}" >> .ssh/authorized_keys`, context);
385
+ await execCommandOverSsh(`echo "${pubKey}" >> .ssh/authorized_keys`, context);
385
386
  };
386
- var createAndAddSshKey = async (pathToKey, comment, context) => {
387
- const pubKey = await createSshKey(pathToKey, comment);
388
- debug(`Key is: ${pubKey}`);
389
- await addSshKeyToAuthorized(pubKey, context);
387
+ var createAndAddSshKey = async (filePath, comment, context) => {
388
+ const normalizedPath = normalizePath(filePath);
389
+ const pubKey = await createSshKey(normalizedPath, comment);
390
+ console.log(`Key is: ${pubKey}`);
391
+ await addSshKeyToAuthorizedOverSsh(pubKey, context);
390
392
  };
391
- var setupSshKey = async ({
393
+ var addSshKeyToUse = async ({
392
394
  key,
393
395
  fingerprint,
394
- pathToFile,
396
+ filePath,
395
397
  server
396
398
  }) => {
397
- await writeIfNewCompletely(pathToFile, key);
398
- await execCommand(`chmod 0600 ${pathToFile}`);
399
+ printFunction(`${addSshKeyToUse.name} ${filePath}`);
400
+ const normalizedFilePath = normalizePath(filePath);
401
+ await writeIfNewCompletely(normalizedFilePath, key);
402
+ await execCommand(`chmod 0600 ${normalizedFilePath}`);
399
403
  await writeIfNew("~/.ssh/known_hosts", fingerprint);
400
- await addKeyToHostConfig("~/.ssh/config", server, pathToFile);
404
+ await addKeyToHostConfig("~/.ssh/config", server, normalizedFilePath);
401
405
  };
402
406
  // src/cron.ts
403
407
  var createCron = async ({
@@ -440,7 +444,7 @@ var buildAndRunOverSsh = async ({
440
444
  const pathToDistFile = outputs.outputs[0]?.path;
441
445
  const relativePathToFile = pathToDistFile.slice(distDir.length + 1);
442
446
  await copyFilesBySsh(`${distDir}/`, distDir, context);
443
- await execBySsh(`bun run ${distDir}/${relativePathToFile}`, context);
447
+ await execCommandOverSsh(`bun run ${distDir}/${relativePathToFile}`, context);
444
448
  await execCommand(`rm -rf ${distDir}`);
445
449
  };
446
450
  var pathToJson = "/tmp/ramm_json";
@@ -458,11 +462,11 @@ var passVarsServer = async () => {
458
462
  return jsonData;
459
463
  };
460
464
  export {
465
+ writeIfNewCompletely,
461
466
  writeIfNew,
462
- writeIfNewCompletely as writeFileIfNotMatch,
463
467
  writeFile,
464
- setupSshKey,
465
468
  setupNftable,
469
+ saveSshFingerptint,
466
470
  runPodmanContainerService,
467
471
  runPodmanContainer,
468
472
  restartSystemdService,
@@ -475,14 +479,16 @@ export {
475
479
  installSystemPackage,
476
480
  installPodman,
477
481
  installBun,
478
- getServerFingerprintBySsh,
482
+ getServerFingerprint,
483
+ execCommandRaw,
479
484
  execCommandOverSsh,
480
- execCommandMayError as execCommand,
481
- execBySsh,
485
+ execCommandMayError,
486
+ execCommand,
482
487
  createCron,
483
488
  createAndAddSshKey,
484
489
  copyFilesBySsh,
485
490
  buildAndRunOverSsh,
491
+ addSshKeyToUse,
486
492
  addNftPodmanRule,
487
493
  addKeyToHostConfig,
488
494
  Context
@@ -27,11 +27,6 @@ export declare const execCommand: (command: string, props: ExecProps) => Promise
27
27
  spawnResult: Subprocess<"inherit", "pipe", "pipe">;
28
28
  }>;
29
29
  export declare const copyFilesBySsh: (from: string, to: string, context: Context) => Promise<void>;
30
- export declare const execBySsh: (command: string, context: Context) => Promise<{
31
- stderr: string;
32
- stdout: string;
33
- spawnResult: Subprocess<"inherit", "pipe", "pipe">;
34
- }>;
35
30
  export declare const execCommandOverSsh: (command: string, context: Context) => Promise<{
36
31
  stderr: string;
37
32
  stdout: string;
@@ -1,4 +1,4 @@
1
- export { execBySsh, execCommandOverSsh, execCommandMayError as execCommand, copyFilesBySsh, } from "./base/base.ts";
1
+ export { execCommandOverSsh, execCommand, execCommandMayError, copyFilesBySsh, execCommandRaw, } from "./base/base.ts";
2
2
  export { Context } from "./context.ts";
3
3
  export { installBun } from "./init.ts";
4
4
  export { installPodman, runPodmanContainer, loginPodman } from "./podman.ts";
@@ -7,8 +7,8 @@ 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 { writeIfNew, writeFile, writeIfNewCompletely as writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
11
- export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, setupSshKey, } from "./ssh.ts";
10
+ export { writeIfNew, writeFile, writeIfNewCompletely, normalizeFileContent, } from "./files.ts";
11
+ export { createAndAddSshKey, getServerFingerprint, addKeyToHostConfig, addSshKeyToUse, saveSshFingerptint, } from "./ssh.ts";
12
12
  export { normalizePath } from "./path.ts";
13
13
  export { createCron } from "./cron.ts";
14
14
  export { buildAndRunOverSsh, passVarsClient, passVarsServer } from "./build.ts";
@@ -1,10 +1,11 @@
1
1
  import type { Context } from "./context.ts";
2
2
  export declare const addKeyToHostConfig: (pathToHost: string, 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>;
5
- export declare const setupSshKey: ({ key, fingerprint, pathToFile, server, }: {
3
+ export declare const getServerFingerprint: (context: Context) => Promise<string>;
4
+ export declare const saveSshFingerptint: (filePath: string, context: Context) => Promise<void>;
5
+ export declare const createAndAddSshKey: (filePath: string, comment: string, context: Context) => Promise<void>;
6
+ export declare const addSshKeyToUse: ({ key, fingerprint, filePath, server, }: {
6
7
  key: string;
7
8
  fingerprint: string;
8
- pathToFile: string;
9
+ filePath: string;
9
10
  server: string;
10
11
  }) => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.30",
4
+ "version": "0.0.32",
5
5
  "scripts": {
6
6
  "build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh",
7
7
  "types": "tsc --project tsconfig.types.json"