ramm 0.0.37 → 0.0.39
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 +87 -77
- package/dist/types/ramm.d.ts +1 -1
- package/dist/types/systemd.d.ts +1 -0
- package/package.json +1 -1
package/dist/ramm.js
CHANGED
|
@@ -140,6 +140,82 @@ var installSystemPackage = async (packageName) => {
|
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
// src/files.ts
|
|
144
|
+
import { appendFile, exists } from "fs/promises";
|
|
145
|
+
var {file, write } = globalThis.Bun;
|
|
146
|
+
|
|
147
|
+
// src/path.ts
|
|
148
|
+
import { homedir } from "os";
|
|
149
|
+
import { join } from "path";
|
|
150
|
+
function normalizePath(rawFilePath) {
|
|
151
|
+
let finalFilePath = rawFilePath.trim();
|
|
152
|
+
if (finalFilePath.startsWith("~/")) {
|
|
153
|
+
finalFilePath = join(homedir(), finalFilePath.slice(2));
|
|
154
|
+
}
|
|
155
|
+
return finalFilePath;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/files.ts
|
|
159
|
+
var normalizeFileContent = (str) => {
|
|
160
|
+
if (str === "") {
|
|
161
|
+
return str;
|
|
162
|
+
}
|
|
163
|
+
if (str.at(-1) !== `
|
|
164
|
+
`) {
|
|
165
|
+
return str + `
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
168
|
+
return str;
|
|
169
|
+
};
|
|
170
|
+
var createDir = async (str) => {
|
|
171
|
+
const dirname = str.split("/").slice(0, -1).join("/");
|
|
172
|
+
const exist = await exists(dirname);
|
|
173
|
+
if (exist) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
await execCommand(`mkdir -p ${dirname}`);
|
|
177
|
+
};
|
|
178
|
+
var checkStrInFile = async (filePath, str) => {
|
|
179
|
+
const file2 = Bun.file(filePath);
|
|
180
|
+
if (!await file2.exists()) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const fileText = await file2.text();
|
|
184
|
+
if (fileText.includes(str)) {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
};
|
|
189
|
+
var createFileIfNeed = async (rawFilePath) => {
|
|
190
|
+
const filePath = normalizePath(rawFilePath);
|
|
191
|
+
await createDir(filePath);
|
|
192
|
+
if (!await file(filePath).exists()) {
|
|
193
|
+
await execCommand(`touch ${filePath}`);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var writeIfNewStr = async (rawFilePath, str) => {
|
|
197
|
+
const filePath = normalizePath(rawFilePath);
|
|
198
|
+
await createFileIfNeed(filePath);
|
|
199
|
+
if (await checkStrInFile(filePath, str)) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
await appendFile(filePath, normalizeFileContent(str));
|
|
203
|
+
};
|
|
204
|
+
var writeFile = async (pathToFile, str) => {
|
|
205
|
+
const normalizedPath = normalizePath(pathToFile);
|
|
206
|
+
await createFileIfNeed(normalizedPath);
|
|
207
|
+
await write(normalizedPath, str);
|
|
208
|
+
};
|
|
209
|
+
var writeFileFull = async (pathToFile, str) => {
|
|
210
|
+
const normalizedPath = normalizePath(pathToFile);
|
|
211
|
+
await createFileIfNeed(normalizedPath);
|
|
212
|
+
const fileText = await file(normalizedPath).text();
|
|
213
|
+
if (fileText === str) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
await write(normalizedPath, str);
|
|
217
|
+
};
|
|
218
|
+
|
|
143
219
|
// src/systemd.ts
|
|
144
220
|
var systemctlWordLangth = "systemctl ".length;
|
|
145
221
|
var formatUserspace = (context, command) => {
|
|
@@ -166,6 +242,14 @@ var checkSystemdService = async (context, serviceName) => {
|
|
|
166
242
|
const { spawnResult } = await execCommandMayError(formatUserspace(context, `systemctl is-active ${serviceName}`));
|
|
167
243
|
return spawnResult.exitCode === 0;
|
|
168
244
|
};
|
|
245
|
+
var createSystemdServiceByContent = async (context, serviceName, content) => {
|
|
246
|
+
printFunction(`createSystemdServiceByContent ${serviceName}`);
|
|
247
|
+
const pathToSeviceTarget = getSystemdPathToService(context, serviceName);
|
|
248
|
+
await writeFileFull(pathToSeviceTarget, content);
|
|
249
|
+
await execCommand(formatUserspace(context, "systemctl daemon-reload"));
|
|
250
|
+
await execCommand(formatUserspace(context, `systemctl enable ${serviceName}`));
|
|
251
|
+
await execCommand(formatUserspace(context, `sysyemctl start ${serviceName}`));
|
|
252
|
+
};
|
|
169
253
|
var createSystemdService = async (context, serviceName, pathToServiceFile) => {
|
|
170
254
|
printFunction(`createSystemdService ${serviceName}`);
|
|
171
255
|
const pathToSeviceTarget = getSystemdPathToService(context, serviceName);
|
|
@@ -178,7 +262,7 @@ var createSystemdService = async (context, serviceName, pathToServiceFile) => {
|
|
|
178
262
|
// src/nft.ts
|
|
179
263
|
var createNftTable = ({
|
|
180
264
|
allowedIpV4,
|
|
181
|
-
allowedPorts
|
|
265
|
+
allowedPorts = []
|
|
182
266
|
}) => {
|
|
183
267
|
const nftTable = `table inet ramm {
|
|
184
268
|
set allowed_ipv4 {
|
|
@@ -217,7 +301,7 @@ var setupNftable = async ({
|
|
|
217
301
|
allowedIpV4,
|
|
218
302
|
allowedPorts
|
|
219
303
|
}) => {
|
|
220
|
-
const listTable = await
|
|
304
|
+
const listTable = await execCommandMayError("nft list table inet ramm");
|
|
221
305
|
if (listTable.spawnResult.exitCode === 0) {
|
|
222
306
|
await execCommand("nft delete table inet ramm");
|
|
223
307
|
}
|
|
@@ -282,81 +366,6 @@ var addNftPodmanRule = async () => {
|
|
|
282
366
|
await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
|
|
283
367
|
await safeNftTable();
|
|
284
368
|
};
|
|
285
|
-
// src/files.ts
|
|
286
|
-
import { appendFile, exists } from "fs/promises";
|
|
287
|
-
var {file, write } = globalThis.Bun;
|
|
288
|
-
|
|
289
|
-
// src/path.ts
|
|
290
|
-
import { homedir } from "os";
|
|
291
|
-
import { join } from "path";
|
|
292
|
-
function normalizePath(rawFilePath) {
|
|
293
|
-
let finalFilePath = rawFilePath.trim();
|
|
294
|
-
if (finalFilePath.startsWith("~/")) {
|
|
295
|
-
finalFilePath = join(homedir(), finalFilePath.slice(2));
|
|
296
|
-
}
|
|
297
|
-
return finalFilePath;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// src/files.ts
|
|
301
|
-
var normalizeFileContent = (str) => {
|
|
302
|
-
if (str === "") {
|
|
303
|
-
return str;
|
|
304
|
-
}
|
|
305
|
-
if (str.at(-1) !== `
|
|
306
|
-
`) {
|
|
307
|
-
return str + `
|
|
308
|
-
`;
|
|
309
|
-
}
|
|
310
|
-
return str;
|
|
311
|
-
};
|
|
312
|
-
var createDir = async (str) => {
|
|
313
|
-
const dirname = str.split("/").slice(0, -1).join("/");
|
|
314
|
-
const exist = await exists(dirname);
|
|
315
|
-
if (exist) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
await execCommand(`mkdir -p ${dirname}`);
|
|
319
|
-
};
|
|
320
|
-
var checkStrInFile = async (filePath, str) => {
|
|
321
|
-
const file2 = Bun.file(filePath);
|
|
322
|
-
if (!await file2.exists()) {
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
const fileText = await file2.text();
|
|
326
|
-
if (fileText.includes(str)) {
|
|
327
|
-
return true;
|
|
328
|
-
}
|
|
329
|
-
return false;
|
|
330
|
-
};
|
|
331
|
-
var createFileIfNeed = async (rawFilePath) => {
|
|
332
|
-
const filePath = normalizePath(rawFilePath);
|
|
333
|
-
await createDir(filePath);
|
|
334
|
-
if (!await file(filePath).exists()) {
|
|
335
|
-
await execCommand(`touch ${filePath}`);
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
var writeIfNewStr = async (rawFilePath, str) => {
|
|
339
|
-
const filePath = normalizePath(rawFilePath);
|
|
340
|
-
await createFileIfNeed(filePath);
|
|
341
|
-
if (await checkStrInFile(filePath, str)) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
await appendFile(filePath, normalizeFileContent(str));
|
|
345
|
-
};
|
|
346
|
-
var writeFile = async (pathToFile, str) => {
|
|
347
|
-
const normalizedPath = normalizePath(pathToFile);
|
|
348
|
-
await createFileIfNeed(normalizedPath);
|
|
349
|
-
await write(normalizedPath, str);
|
|
350
|
-
};
|
|
351
|
-
var writeFileFull = async (pathToFile, str) => {
|
|
352
|
-
const normalizedPath = normalizePath(pathToFile);
|
|
353
|
-
await createFileIfNeed(normalizedPath);
|
|
354
|
-
const fileText = await file(normalizedPath).text();
|
|
355
|
-
if (fileText === str) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
await write(normalizedPath, str);
|
|
359
|
-
};
|
|
360
369
|
// src/ssh.ts
|
|
361
370
|
var {file: file2 } = globalThis.Bun;
|
|
362
371
|
var addKeyToHostConfig = async (pathToHost, address, pathToKey) => {
|
|
@@ -499,6 +508,7 @@ export {
|
|
|
499
508
|
execCommandOverSsh,
|
|
500
509
|
execCommandMayError,
|
|
501
510
|
execCommand,
|
|
511
|
+
createSystemdServiceByContent,
|
|
502
512
|
createCron,
|
|
503
513
|
createAndAddSshKey,
|
|
504
514
|
copyFilesBySsh,
|
package/dist/types/ramm.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { Context } from "./context.ts";
|
|
|
3
3
|
export { installBun } from "./init.ts";
|
|
4
4
|
export { installPodman, runPodmanContainer, loginPodman } from "./podman.ts";
|
|
5
5
|
export { runPodmanContainerService, addNftPodmanRule } from "./podman.ts";
|
|
6
|
-
export { restartSystemdService } from "./systemd.ts";
|
|
6
|
+
export { restartSystemdService, createSystemdServiceByContent, } from "./systemd.ts";
|
|
7
7
|
export { installSystemPackage } from "./packages.ts";
|
|
8
8
|
export { printBlock } from "./print.ts";
|
|
9
9
|
export { setupNftable } from "./nft.ts";
|
package/dist/types/systemd.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare const getSysyemdServiceName: (name: string) => string;
|
|
|
3
3
|
export declare const stopSystemdService: (constext: Context, name: string) => Promise<void>;
|
|
4
4
|
export declare const restartSystemdService: (name: string, constext?: Context) => Promise<void>;
|
|
5
5
|
export declare const checkSystemdService: (context: Context, serviceName: string) => Promise<boolean>;
|
|
6
|
+
export declare const createSystemdServiceByContent: (context: Context, serviceName: string, content: string) => Promise<void>;
|
|
6
7
|
export declare const createSystemdService: (context: Context, serviceName: string, pathToServiceFile: string) => Promise<void>;
|
package/package.json
CHANGED