ramm 0.0.30 → 0.0.31

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,53 @@ 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 getServerFingerprintOverSsh = 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
+ async function createSshKey(filePath, comment) {
359
+ printFunction(`${createSshKey.name} ${filePath}`);
360
+ const normalizedPathToKey = normalizePath(filePath);
361
+ const name = normalizedPathToKey.split("/").at(-1);
362
+ const pathToKeyPub = `${normalizedPathToKey}.pub`;
363
+ const pathToDir = normalizedPathToKey.split("/").slice(0, -1).join("/");
364
+ const pathToKeyFile = file2(normalizedPathToKey);
369
365
  const pathToKeyPubFile = file2(pathToKeyPub);
370
366
  if (await pathToKeyFile.exists() && await pathToKeyPubFile.exists()) {
371
367
  return await pathToKeyPubFile.text();
372
368
  }
373
369
  await execCommand(`mkdir -p ${pathToDir}`);
374
- await execCommand(`ssh-keygen -t ed25519 -f ${pathToKey} -N "" -C "${comment || name}"`);
375
- await execCommand(`chmod 600 ${pathToKey}`);
370
+ await execCommand(`ssh-keygen -t ed25519 -f ${normalizedPathToKey} -N "" -C "${comment || name}"`);
371
+ await execCommand(`chmod 600 ${normalizedPathToKey}`);
376
372
  const pubKey = await Bun.file(pathToKeyPub).text();
377
373
  return pubKey;
378
374
  }
379
- var addSshKeyToAuthorized = async (pubKey, context) => {
380
- const { stdout: keys } = await execBySsh("cat .ssh/authorized_keys", context);
375
+ var addSshKeyToAuthorizedOverSsh = async (pubKey, context) => {
376
+ printFunction(`${addSshKeyToAuthorizedOverSsh.name} ${pubKey}`);
377
+ const { stdout: keys } = await execCommandOverSsh("cat .ssh/authorized_keys", context);
381
378
  if (keys.includes(pubKey)) {
382
379
  return;
383
380
  }
384
- await execBySsh(`echo "${pubKey}" >> .ssh/authorized_keys`, context);
381
+ await execCommandOverSsh(`echo "${pubKey}" >> .ssh/authorized_keys`, context);
385
382
  };
386
- var createAndAddSshKey = async (pathToKey, comment, context) => {
387
- const pubKey = await createSshKey(pathToKey, comment);
388
- debug(`Key is: ${pubKey}`);
389
- await addSshKeyToAuthorized(pubKey, context);
383
+ var createAndAddSshKey = async (filePath, comment, context) => {
384
+ const normalizedPath = normalizePath(filePath);
385
+ const pubKey = await createSshKey(normalizedPath, comment);
386
+ console.log(`Key is: ${pubKey}`);
387
+ await addSshKeyToAuthorizedOverSsh(pubKey, context);
390
388
  };
391
- var setupSshKey = async ({
389
+ var addSshKeyToUse = async ({
392
390
  key,
393
391
  fingerprint,
394
- pathToFile,
392
+ filePath,
395
393
  server
396
394
  }) => {
397
- await writeIfNewCompletely(pathToFile, key);
398
- await execCommand(`chmod 0600 ${pathToFile}`);
395
+ printFunction(`${addSshKeyToUse.name} ${filePath}`);
396
+ const normalizedFilePath = normalizePath(filePath);
397
+ await writeIfNewCompletely(normalizedFilePath, key);
398
+ await execCommand(`chmod 0600 ${normalizedFilePath}`);
399
399
  await writeIfNew("~/.ssh/known_hosts", fingerprint);
400
- await addKeyToHostConfig("~/.ssh/config", server, pathToFile);
400
+ await addKeyToHostConfig("~/.ssh/config", server, normalizedFilePath);
401
401
  };
402
402
  // src/cron.ts
403
403
  var createCron = async ({
@@ -440,7 +440,7 @@ var buildAndRunOverSsh = async ({
440
440
  const pathToDistFile = outputs.outputs[0]?.path;
441
441
  const relativePathToFile = pathToDistFile.slice(distDir.length + 1);
442
442
  await copyFilesBySsh(`${distDir}/`, distDir, context);
443
- await execBySsh(`bun run ${distDir}/${relativePathToFile}`, context);
443
+ await execCommandOverSsh(`bun run ${distDir}/${relativePathToFile}`, context);
444
444
  await execCommand(`rm -rf ${distDir}`);
445
445
  };
446
446
  var pathToJson = "/tmp/ramm_json";
@@ -461,7 +461,7 @@ export {
461
461
  writeIfNew,
462
462
  writeIfNewCompletely as writeFileIfNotMatch,
463
463
  writeFile,
464
- setupSshKey,
464
+ addSshKeyToUse as setupSshKey,
465
465
  setupNftable,
466
466
  runPodmanContainerService,
467
467
  runPodmanContainer,
@@ -475,10 +475,11 @@ export {
475
475
  installSystemPackage,
476
476
  installPodman,
477
477
  installBun,
478
- getServerFingerprintBySsh,
478
+ getServerFingerprintOverSsh,
479
+ execCommandRaw,
479
480
  execCommandOverSsh,
480
- execCommandMayError as execCommand,
481
- execBySsh,
481
+ execCommandMayError,
482
+ execCommand,
482
483
  createCron,
483
484
  createAndAddSshKey,
484
485
  copyFilesBySsh,
@@ -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";
@@ -8,7 +8,7 @@ export { installSystemPackage } from "./packages.ts";
8
8
  export { printBlock } from "./print.ts";
9
9
  export { setupNftable } from "./nft.ts";
10
10
  export { writeIfNew, writeFile, writeIfNewCompletely as writeFileIfNotMatch, normalizeFileContent, } from "./files.ts";
11
- export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, setupSshKey, } from "./ssh.ts";
11
+ export { createAndAddSshKey, getServerFingerprintOverSsh, addKeyToHostConfig, addSshKeyToUse as setupSshKey, } 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,10 @@
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 getServerFingerprintOverSsh: (context: Context) => Promise<string>;
4
+ export declare const createAndAddSshKey: (filePath: string, comment: string, context: Context) => Promise<void>;
5
+ export declare const addSshKeyToUse: ({ key, fingerprint, filePath, server, }: {
6
6
  key: string;
7
7
  fingerprint: string;
8
- pathToFile: string;
8
+ filePath: string;
9
9
  server: string;
10
10
  }) => 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.31",
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"