ramm 0.0.34 → 0.0.35

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
@@ -175,55 +175,6 @@ var createSystemdService = async (context, serviceName, pathToServiceFile) => {
175
175
  await execCommand(formatUserspace(context, `sysyemctl start ${serviceName}`));
176
176
  };
177
177
 
178
- // src/podman.ts
179
- var installPodman = async () => {
180
- if ((await $2`command -v podman`.nothrow().quiet()).exitCode !== 0) {
181
- await installSystemPackage("podman");
182
- }
183
- await createNetwork();
184
- };
185
- var createNetwork = async () => {
186
- const netwroks = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
187
- const podmanNetworks = await execCommand("podman network ls");
188
- if (podmanNetworks.stdout.includes("ramm")) {
189
- return;
190
- }
191
- if (netwroks.stdout.includes("podman_ramm")) {
192
- return;
193
- }
194
- await execCommand("podman network create --interface-name=podman_ramm ramm");
195
- };
196
- var getCreateCommand = async (name) => {
197
- const podmanCreateCommand = await $2`podman inspect --format '{{.Config.CreateCommand}}' ${name}`.nothrow().quiet();
198
- return podmanCreateCommand.text().slice(0, -1).slice(1, -1) || "";
199
- };
200
- var loginPodman = async (address, login, password) => {
201
- return await execCommand(`echo "${password}" | podman login --username "${login}" --password-stdin ${address}`);
202
- };
203
- var runPodmanContainer = async (name, command) => {
204
- if (await getCreateCommand(name) !== command) {
205
- await $2`podman rm -f ${name}`;
206
- await execCommand(command);
207
- return;
208
- }
209
- console.info("Podman container is already running");
210
- };
211
- var runPodmanContainerService = async (name, command, context = defaultContext) => {
212
- const serviceName = getSysyemdServiceName(name);
213
- if (await checkSystemdService(context, serviceName)) {
214
- await stopSystemdService(context, serviceName);
215
- }
216
- await runPodmanContainer(name, command);
217
- await execCommand(`podman generate systemd --name --new ${name} > ${serviceName}`);
218
- await createSystemdService(context, serviceName, serviceName);
219
- };
220
- var addNftPodmanRule = async () => {
221
- const podmanNetworksResult = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
222
- const podmanNetworks = podmanNetworksResult.stdout.trim().split(`
223
- `);
224
- await execCommand(`nft add set inet ramm podman_interfaces '{ type ifname; flags dynamic; elements = { ${podmanNetworks.join(", ")} }; }'`);
225
- await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
226
- };
227
178
  // src/nft.ts
228
179
  var createNftTable = ({
229
180
  allowedIpV4,
@@ -266,14 +217,71 @@ var setupNftable = async ({
266
217
  allowedIpV4,
267
218
  allowedPorts
268
219
  }) => {
269
- await execCommand("nft flush ruleset");
220
+ const listTable = await execCommand("nft list table inet ramm");
221
+ if (listTable.spawnResult.exitCode === 0) {
222
+ await execCommand("nft delete table inet ramm");
223
+ }
270
224
  const nftTable = createNftTable({ allowedIpV4, allowedPorts });
271
225
  await execCommand(`nft -f - <<EOF
272
226
  ${nftTable}
273
227
  EOF`);
228
+ await safeNftTable();
229
+ };
230
+ var safeNftTable = async () => {
274
231
  await execCommand("nft list ruleset > /etc/nftables.conf");
275
232
  await execCommand("systemctl enable nftables");
276
233
  };
234
+
235
+ // src/podman.ts
236
+ var installPodman = async () => {
237
+ if ((await $2`command -v podman`.nothrow().quiet()).exitCode !== 0) {
238
+ await installSystemPackage("podman");
239
+ }
240
+ await createNetwork();
241
+ };
242
+ var createNetwork = async () => {
243
+ const netwroks = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
244
+ const podmanNetworks = await execCommand("podman network ls");
245
+ if (podmanNetworks.stdout.includes("ramm")) {
246
+ return;
247
+ }
248
+ if (netwroks.stdout.includes("podman_ramm")) {
249
+ return;
250
+ }
251
+ await execCommand("podman network create --interface-name=podman_ramm ramm");
252
+ };
253
+ var getCreateCommand = async (name) => {
254
+ const podmanCreateCommand = await $2`podman inspect --format '{{.Config.CreateCommand}}' ${name}`.nothrow().quiet();
255
+ return podmanCreateCommand.text().slice(0, -1).slice(1, -1) || "";
256
+ };
257
+ var loginPodman = async (address, login, password) => {
258
+ return await execCommand(`echo "${password}" | podman login --username "${login}" --password-stdin ${address}`);
259
+ };
260
+ var runPodmanContainer = async (name, command) => {
261
+ if (await getCreateCommand(name) !== command) {
262
+ await $2`podman rm -f ${name}`;
263
+ await execCommand(command);
264
+ return;
265
+ }
266
+ console.info("Podman container is already running");
267
+ };
268
+ var runPodmanContainerService = async (name, command, context = defaultContext) => {
269
+ const serviceName = getSysyemdServiceName(name);
270
+ if (await checkSystemdService(context, serviceName)) {
271
+ await stopSystemdService(context, serviceName);
272
+ }
273
+ await runPodmanContainer(name, command);
274
+ await execCommand(`podman generate systemd --name --new ${name} > ${serviceName}`);
275
+ await createSystemdService(context, serviceName, serviceName);
276
+ };
277
+ var addNftPodmanRule = async () => {
278
+ const podmanNetworksResult = await execCommand("podman network inspect $(podman network ls -q) -f '{{.NetworkInterface}}'");
279
+ const podmanNetworks = podmanNetworksResult.stdout.trim().split(`
280
+ `);
281
+ await execCommand(`nft add set inet ramm podman_interfaces '{ type ifname; flags dynamic; elements = { ${podmanNetworks.join(", ")} }; }'`);
282
+ await execCommand("nft insert rule inet ramm prerouting iifname @podman_interfaces accept");
283
+ await safeNftTable();
284
+ };
277
285
  // src/files.ts
278
286
  import { appendFile, exists } from "fs/promises";
279
287
  var {file, write } = globalThis.Bun;
@@ -3,3 +3,4 @@ export declare const setupNftable: ({ allowedIpV4, allowedPorts, }: {
3
3
  allowedIpV4: string[];
4
4
  allowedPorts: string[];
5
5
  }) => Promise<void>;
6
+ export declare const safeNftTable: () => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.34",
4
+ "version": "0.0.35",
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"