ramm 0.0.48 → 0.0.51

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/bun.sh CHANGED
@@ -14,10 +14,10 @@ if ! command -v unzip &> /dev/null; then
14
14
  fi
15
15
 
16
16
  if ! command -v bun &> /dev/null; then
17
- echo "Installing..."
17
+ echo "Installing bun..."
18
18
 
19
19
  curl -fsSL https://bun.sh/install | bash
20
20
  ln -s "$HOME/.bun/bin/bun" /usr/local/bin/bun
21
21
  else
22
- echo "Already installed."
22
+ echo "Already installed bun."
23
23
  fi
package/dist/ramm.js CHANGED
@@ -81,8 +81,9 @@ var defaultContext = new Context({
81
81
  userspace: false,
82
82
  sudo: false
83
83
  });
84
- var execCommandRaw = async (command, { store = {}, signal, env, cwd, prefix = "" } = {}) => {
85
- const spawnResult = spawn(["bash", "-c", command], {
84
+ var execCommandRaw = async (command, { store = {}, signal, env, cwd, prefix = "" } = {}, ctx) => {
85
+ const finalCommand = ctx?.sudo ? `sudo ${command}` : command;
86
+ const spawnResult = spawn(["bash", "-c", finalCommand], {
86
87
  stdin: "inherit",
87
88
  stdout: "pipe",
88
89
  stderr: "pipe",
@@ -102,12 +103,12 @@ var execCommandRaw = async (command, { store = {}, signal, env, cwd, prefix = ""
102
103
  spawnResult
103
104
  };
104
105
  };
105
- var execCommandMayError = async (command, props) => {
106
+ var execCommandMayError = async (command, props, context) => {
106
107
  printCommand(command);
107
- return execCommandRaw(command, props);
108
+ return execCommandRaw(command, props, context);
108
109
  };
109
- var execCommand = async (command, props) => {
110
- const result = await execCommandMayError(command, props);
110
+ var execCommand = async (command, props, context) => {
111
+ const result = await execCommandMayError(command, props, context);
111
112
  if (result.spawnResult.exitCode !== 0) {
112
113
  console.error(`Error exit code: ${result.spawnResult.exitCode}`);
113
114
  console.error(`Command: ${command}`);
@@ -133,10 +134,19 @@ var {$: $2 } = globalThis.Bun;
133
134
 
134
135
  // src/packages.ts
135
136
  var {$ } = globalThis.Bun;
136
- var installSystemPackage = async (packageName) => {
137
+ var dnf_os = ["rocky", "fedora", "alma"];
138
+ var installSystemPackage = async (packageName, context) => {
137
139
  const osName = (await $`cat /etc/os-release | grep ^ID= | cut -d'=' -f2`.text()).trim();
140
+ const checkResult = await execCommandMayError(`which ${packageName}`, {}, context);
141
+ if (checkResult.spawnResult.exitCode !== 0) {
142
+ return;
143
+ }
138
144
  if (osName === "ubuntu") {
139
- await execCommandMayError(`apt-get install -y ${packageName}`);
145
+ await execCommand(`apt-get install -y ${packageName}`, {}, context);
146
+ } else if (dnf_os.includes(osName)) {
147
+ await execCommand(`dnf install -y ${packageName}`, {}, context);
148
+ } else {
149
+ throw new Error(`Unsupported OS: ${osName}`);
140
150
  }
141
151
  };
142
152
 
@@ -300,6 +310,7 @@ var setupNftable = async ({
300
310
  allowedIpV4,
301
311
  allowedPorts
302
312
  }) => {
313
+ await installSystemPackage("nftables");
303
314
  const listTable = await execCommandMayError("nft list table inet ramm");
304
315
  if (listTable.spawnResult.exitCode === 0) {
305
316
  await execCommand("nft delete table inet ramm");
@@ -11,17 +11,17 @@ type ExecProps = {
11
11
  prefix?: string;
12
12
  signal?: AbortSignal;
13
13
  } | void;
14
- export declare const execCommandRaw: (command: string, { store, signal, env, cwd, prefix }?: ExecProps) => Promise<{
14
+ export declare const execCommandRaw: (command: string, { store, signal, env, cwd, prefix }?: ExecProps, ctx?: Context) => Promise<{
15
15
  stderr: string;
16
16
  stdout: string;
17
17
  spawnResult: Subprocess<"inherit", "pipe", "pipe">;
18
18
  }>;
19
- export declare const execCommandMayError: (command: string, props: ExecProps) => Promise<{
19
+ export declare const execCommandMayError: (command: string, props: ExecProps, context?: Context) => Promise<{
20
20
  stderr: string;
21
21
  stdout: string;
22
22
  spawnResult: Subprocess<"inherit", "pipe", "pipe">;
23
23
  }>;
24
- export declare const execCommand: (command: string, props: ExecProps) => Promise<{
24
+ export declare const execCommand: (command: string, props: ExecProps, context?: Context) => Promise<{
25
25
  stderr: string;
26
26
  stdout: string;
27
27
  spawnResult: Subprocess<"inherit", "pipe", "pipe">;
@@ -1 +1,2 @@
1
- export declare const installSystemPackage: (packageName: string) => Promise<void>;
1
+ import type { Context } from "./context.ts";
2
+ export declare const installSystemPackage: (packageName: string, context?: Context) => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ramm",
3
3
  "type": "module",
4
- "version": "0.0.48",
4
+ "version": "0.0.51",
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"