ramm 0.0.29 → 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 +37 -31
- package/dist/types/base/base.d.ts +1 -1
- package/dist/types/ramm.d.ts +2 -2
- package/dist/types/ssh.d.ts +4 -4
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -109,7 +109,7 @@ var execCommandMayError = async (command, props) => {
|
|
|
109
109
|
var execCommand = async (command, props) => {
|
|
110
110
|
const result = await execCommandMayError(command, props);
|
|
111
111
|
if (result.spawnResult.exitCode !== 0) {
|
|
112
|
-
console.error(`Error exit code:
|
|
112
|
+
console.error(`Error exit code: ${result.spawnResult.exitCode}`);
|
|
113
113
|
console.error(`Command: ${command}`);
|
|
114
114
|
throw new Error(command);
|
|
115
115
|
}
|
|
@@ -118,7 +118,7 @@ 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
|
|
121
|
+
var execCommandOverSsh = async (command, context) => {
|
|
122
122
|
const sshKeyPart = context.sshKey ? ` -i ${context.sshKey}` : "";
|
|
123
123
|
return await execCommand(`ssh${sshKeyPart} ${context.getAddress()} '${command}'`);
|
|
124
124
|
};
|
|
@@ -126,7 +126,7 @@ var execBySsh = async (command, context) => {
|
|
|
126
126
|
var installBun = async (context) => {
|
|
127
127
|
const bunPath = new URL(import.meta.resolve("./bun.sh")).pathname;
|
|
128
128
|
await copyFilesBySsh(bunPath, "./bun.sh", context);
|
|
129
|
-
await
|
|
129
|
+
await execCommandOverSsh("./bun.sh", context);
|
|
130
130
|
};
|
|
131
131
|
// src/podman.ts
|
|
132
132
|
var {$: $2 } = globalThis.Bun;
|
|
@@ -344,7 +344,6 @@ var writeIfNewCompletely = async (pathToFile, str) => {
|
|
|
344
344
|
await write(normalizedPath, str);
|
|
345
345
|
};
|
|
346
346
|
// src/ssh.ts
|
|
347
|
-
import { debug } from "console";
|
|
348
347
|
var {file: file2 } = globalThis.Bun;
|
|
349
348
|
var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
|
|
350
349
|
const text = `Host ${address}
|
|
@@ -352,48 +351,53 @@ var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
|
|
|
352
351
|
`;
|
|
353
352
|
await writeIfNew(pathToHost, text);
|
|
354
353
|
};
|
|
355
|
-
var
|
|
356
|
-
const { stdout } = await
|
|
354
|
+
var getServerFingerprintOverSsh = async (context) => {
|
|
355
|
+
const { stdout } = await execCommandOverSsh('ssh-keyscan -t ed25519 localhost | grep -v "^#"', context);
|
|
357
356
|
return stdout.replace("localhost", context.domain);
|
|
358
357
|
};
|
|
359
|
-
async function createSshKey(
|
|
360
|
-
printFunction(createSshKey.name);
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
const
|
|
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);
|
|
365
365
|
const pathToKeyPubFile = file2(pathToKeyPub);
|
|
366
366
|
if (await pathToKeyFile.exists() && await pathToKeyPubFile.exists()) {
|
|
367
367
|
return await pathToKeyPubFile.text();
|
|
368
368
|
}
|
|
369
369
|
await execCommand(`mkdir -p ${pathToDir}`);
|
|
370
|
-
await execCommand(`ssh-keygen -t ed25519 -f ${
|
|
371
|
-
await execCommand(`chmod 600 ${
|
|
370
|
+
await execCommand(`ssh-keygen -t ed25519 -f ${normalizedPathToKey} -N "" -C "${comment || name}"`);
|
|
371
|
+
await execCommand(`chmod 600 ${normalizedPathToKey}`);
|
|
372
372
|
const pubKey = await Bun.file(pathToKeyPub).text();
|
|
373
373
|
return pubKey;
|
|
374
374
|
}
|
|
375
|
-
var
|
|
376
|
-
|
|
375
|
+
var addSshKeyToAuthorizedOverSsh = async (pubKey, context) => {
|
|
376
|
+
printFunction(`${addSshKeyToAuthorizedOverSsh.name} ${pubKey}`);
|
|
377
|
+
const { stdout: keys } = await execCommandOverSsh("cat .ssh/authorized_keys", context);
|
|
377
378
|
if (keys.includes(pubKey)) {
|
|
378
379
|
return;
|
|
379
380
|
}
|
|
380
|
-
await
|
|
381
|
+
await execCommandOverSsh(`echo "${pubKey}" >> .ssh/authorized_keys`, context);
|
|
381
382
|
};
|
|
382
|
-
var createAndAddSshKey = async (
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
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);
|
|
386
388
|
};
|
|
387
|
-
var
|
|
389
|
+
var addSshKeyToUse = async ({
|
|
388
390
|
key,
|
|
389
391
|
fingerprint,
|
|
390
|
-
|
|
392
|
+
filePath,
|
|
391
393
|
server
|
|
392
394
|
}) => {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
+
printFunction(`${addSshKeyToUse.name} ${filePath}`);
|
|
396
|
+
const normalizedFilePath = normalizePath(filePath);
|
|
397
|
+
await writeIfNewCompletely(normalizedFilePath, key);
|
|
398
|
+
await execCommand(`chmod 0600 ${normalizedFilePath}`);
|
|
395
399
|
await writeIfNew("~/.ssh/known_hosts", fingerprint);
|
|
396
|
-
await addKeyToHostConfig("~/.ssh/config", server,
|
|
400
|
+
await addKeyToHostConfig("~/.ssh/config", server, normalizedFilePath);
|
|
397
401
|
};
|
|
398
402
|
// src/cron.ts
|
|
399
403
|
var createCron = async ({
|
|
@@ -436,7 +440,7 @@ var buildAndRunOverSsh = async ({
|
|
|
436
440
|
const pathToDistFile = outputs.outputs[0]?.path;
|
|
437
441
|
const relativePathToFile = pathToDistFile.slice(distDir.length + 1);
|
|
438
442
|
await copyFilesBySsh(`${distDir}/`, distDir, context);
|
|
439
|
-
await
|
|
443
|
+
await execCommandOverSsh(`bun run ${distDir}/${relativePathToFile}`, context);
|
|
440
444
|
await execCommand(`rm -rf ${distDir}`);
|
|
441
445
|
};
|
|
442
446
|
var pathToJson = "/tmp/ramm_json";
|
|
@@ -457,7 +461,7 @@ export {
|
|
|
457
461
|
writeIfNew,
|
|
458
462
|
writeIfNewCompletely as writeFileIfNotMatch,
|
|
459
463
|
writeFile,
|
|
460
|
-
setupSshKey,
|
|
464
|
+
addSshKeyToUse as setupSshKey,
|
|
461
465
|
setupNftable,
|
|
462
466
|
runPodmanContainerService,
|
|
463
467
|
runPodmanContainer,
|
|
@@ -471,9 +475,11 @@ export {
|
|
|
471
475
|
installSystemPackage,
|
|
472
476
|
installPodman,
|
|
473
477
|
installBun,
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
478
|
+
getServerFingerprintOverSsh,
|
|
479
|
+
execCommandRaw,
|
|
480
|
+
execCommandOverSsh,
|
|
481
|
+
execCommandMayError,
|
|
482
|
+
execCommand,
|
|
477
483
|
createCron,
|
|
478
484
|
createAndAddSshKey,
|
|
479
485
|
copyFilesBySsh,
|
|
@@ -27,7 +27,7 @@ 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
|
|
30
|
+
export declare const execCommandOverSsh: (command: string, context: Context) => Promise<{
|
|
31
31
|
stderr: string;
|
|
32
32
|
stdout: string;
|
|
33
33
|
spawnResult: Subprocess<"inherit", "pipe", "pipe">;
|
package/dist/types/ramm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
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,
|
|
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";
|
package/dist/types/ssh.d.ts
CHANGED
|
@@ -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
|
|
4
|
-
export declare const createAndAddSshKey: (
|
|
5
|
-
export declare const
|
|
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
|
-
|
|
8
|
+
filePath: string;
|
|
9
9
|
server: string;
|
|
10
10
|
}) => Promise<void>;
|
package/package.json
CHANGED