ramm 0.0.14 → 0.0.16
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 +36 -4
- package/dist/types/cron.d.ts +4 -0
- package/dist/types/files.d.ts +1 -0
- package/dist/types/ramm.d.ts +2 -1
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -239,7 +239,7 @@ EOF`);
|
|
|
239
239
|
};
|
|
240
240
|
// src/files.ts
|
|
241
241
|
import { appendFile, exists } from "fs/promises";
|
|
242
|
-
var {write } = globalThis.Bun;
|
|
242
|
+
var {file, write } = globalThis.Bun;
|
|
243
243
|
|
|
244
244
|
// src/path.ts
|
|
245
245
|
import { homedir } from "os";
|
|
@@ -270,11 +270,11 @@ var createDir = async (str) => {
|
|
|
270
270
|
await execCommand(`mkdir -p ${dirname}`);
|
|
271
271
|
};
|
|
272
272
|
var checkStrInFile = async (filePath, str) => {
|
|
273
|
-
const
|
|
274
|
-
if (!await
|
|
273
|
+
const file2 = Bun.file(filePath);
|
|
274
|
+
if (!await file2.exists()) {
|
|
275
275
|
return false;
|
|
276
276
|
}
|
|
277
|
-
const fileText = await
|
|
277
|
+
const fileText = await file2.text();
|
|
278
278
|
if (fileText.includes(str)) {
|
|
279
279
|
return true;
|
|
280
280
|
}
|
|
@@ -300,6 +300,15 @@ var writeFile = async (pathToFile, str) => {
|
|
|
300
300
|
await createFileIfNeed(normalizedPath);
|
|
301
301
|
await write(normalizedPath, str);
|
|
302
302
|
};
|
|
303
|
+
var writeFileIfNotMatch = async (pathToFile, str) => {
|
|
304
|
+
const normalizedPath = normalizePath(pathToFile);
|
|
305
|
+
await createFileIfNeed(normalizedPath);
|
|
306
|
+
const fileText = await file(normalizedPath).text();
|
|
307
|
+
if (fileText === str) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
await write(normalizedPath, str);
|
|
311
|
+
};
|
|
303
312
|
// src/ssh.ts
|
|
304
313
|
import { debug } from "console";
|
|
305
314
|
var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
|
|
@@ -339,8 +348,30 @@ var createAndAddSshKey = async (pathToKey, comment, context) => {
|
|
|
339
348
|
debug(`Key is: ${pubKey}`);
|
|
340
349
|
await addSshKey(pubKey, context);
|
|
341
350
|
};
|
|
351
|
+
// src/cron.ts
|
|
352
|
+
var createCron = async ({
|
|
353
|
+
time,
|
|
354
|
+
pathToFile
|
|
355
|
+
}) => {
|
|
356
|
+
const constructedLine = `${time} ${pathToFile}`;
|
|
357
|
+
const tempFile = `/tmp/cron_${new Date().getTime().toString()}`;
|
|
358
|
+
const { output: cronConfig } = await execCommand("crontab -l");
|
|
359
|
+
let newCronConfig = cronConfig;
|
|
360
|
+
if (cronConfig.includes(constructedLine)) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (cronConfig.includes(pathToFile)) {
|
|
364
|
+
newCronConfig = cronConfig.split(`
|
|
365
|
+
`).filter((str) => !str.includes(pathToFile)).join(`
|
|
366
|
+
`);
|
|
367
|
+
}
|
|
368
|
+
await writeFile(tempFile, newCronConfig);
|
|
369
|
+
await execCommand(`crontab ${tempFile}`);
|
|
370
|
+
await execCommand(`rm ${tempFile}`);
|
|
371
|
+
};
|
|
342
372
|
export {
|
|
343
373
|
writeIfNew,
|
|
374
|
+
writeFileIfNotMatch,
|
|
344
375
|
writeFile,
|
|
345
376
|
setupNftable,
|
|
346
377
|
runPodmanContainerService,
|
|
@@ -354,6 +385,7 @@ export {
|
|
|
354
385
|
execCommand,
|
|
355
386
|
execBySsh,
|
|
356
387
|
debugBlock,
|
|
388
|
+
createCron,
|
|
357
389
|
createAndAddSshKey,
|
|
358
390
|
copyFilesBySsh,
|
|
359
391
|
addNftPodmanRule,
|
package/dist/types/files.d.ts
CHANGED
package/dist/types/ramm.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ 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 { writeIfNew, writeFile } from "./files.ts";
|
|
10
|
+
export { writeIfNew, writeFile, writeFileIfNotMatch } from "./files.ts";
|
|
11
11
|
export { createAndAddSshKey, getServerFingerprintBySsh, addKeyToHostConfig, } from "./ssh.ts";
|
|
12
12
|
export { normalizePath } from "./path.ts";
|
|
13
|
+
export { createCron } from "./cron.ts";
|
package/package.json
CHANGED