ramm 0.0.1
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 +23 -0
- package/dist/ramm.js +80 -0
- package/dist/types/ramm.d.ts +13 -0
- package/package.json +18 -0
package/dist/bun.sh
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Проверка наличия файла /etc/os-release
|
|
4
|
+
if ! command -v unzip &> /dev/null; then
|
|
5
|
+
. /etc/os-release
|
|
6
|
+
echo "Дистрибутив: $NAME"
|
|
7
|
+
|
|
8
|
+
if [[ "$ID" == "ubuntu" ]]; then
|
|
9
|
+
sudo apt update
|
|
10
|
+
sudo apt install -y unzip
|
|
11
|
+
fi
|
|
12
|
+
fi
|
|
13
|
+
|
|
14
|
+
if ! command -v bun &> /dev/null; then
|
|
15
|
+
echo "Bun не найден. Устанавливаю..."
|
|
16
|
+
|
|
17
|
+
curl -fsSL https://bun.sh/install | bash
|
|
18
|
+
ln -s "$HOME/.bun/bin/bun" /usr/local/bin/bun
|
|
19
|
+
|
|
20
|
+
echo "Bun установлен!"
|
|
21
|
+
else
|
|
22
|
+
echo "Bun уже установлен."
|
|
23
|
+
fi
|
package/dist/ramm.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/ramm.ts
|
|
3
|
+
var {$, spawn } = globalThis.Bun;
|
|
4
|
+
var debugInternal = (func, command) => {
|
|
5
|
+
console.info(`>>>${func}<<< ${command}`);
|
|
6
|
+
};
|
|
7
|
+
var debugCommand = (command) => {
|
|
8
|
+
debugInternal("\x1B[32mCommand\x1B[0m", `\x1B[38;5;85m${command}\x1B[0m`);
|
|
9
|
+
};
|
|
10
|
+
var debug = (text) => {
|
|
11
|
+
debugInternal("\x1B[34mBlock\x1B[0m", `\x1B[38;5;81m${text}\x1B[0m`);
|
|
12
|
+
};
|
|
13
|
+
var execCommand = async (command) => {
|
|
14
|
+
debugCommand(command);
|
|
15
|
+
const result = await spawn(["bash", "-c", command], {
|
|
16
|
+
stdin: "inherit",
|
|
17
|
+
stdout: "inherit",
|
|
18
|
+
stderr: "inherit"
|
|
19
|
+
});
|
|
20
|
+
await result.exited;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class Context {
|
|
24
|
+
name;
|
|
25
|
+
domain;
|
|
26
|
+
constructor(name, address) {
|
|
27
|
+
this.name = name;
|
|
28
|
+
this.domain = address;
|
|
29
|
+
}
|
|
30
|
+
getAddress() {
|
|
31
|
+
return `${this.name}@${this.domain}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var copyFiles = async (context, from, to) => {
|
|
35
|
+
await execCommand(`rsync -avz ${from} ${context.getAddress()}:${to}`);
|
|
36
|
+
};
|
|
37
|
+
var exec = async (context, command) => {
|
|
38
|
+
await execCommand(`ssh ${context.getAddress()} "${command}"`);
|
|
39
|
+
};
|
|
40
|
+
var installSystemPackage = async (packageName) => {
|
|
41
|
+
const osName = await $`cat /etc/os-release | grep ^ID= | cut -d'=' -f2`.text();
|
|
42
|
+
if (osName === "ubuntu") {
|
|
43
|
+
execCommand(`apt-get install -y ${packageName}`);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var installPodman = async () => {
|
|
47
|
+
if ((await $`command -v podman`).exitCode === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await installSystemPackage("podman");
|
|
51
|
+
};
|
|
52
|
+
var runPodmanContainer = async (command, name) => {
|
|
53
|
+
const podmanCreateCommand = await $`podman inspect --format '{{.Config.CreateCommand}}' ${name}`.nothrow().quiet();
|
|
54
|
+
if (podmanCreateCommand.exitCode !== 0) {
|
|
55
|
+
await execCommand(command);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const podmanCreateCommandText = podmanCreateCommand.text().slice(0, -1);
|
|
59
|
+
if (podmanCreateCommandText !== `[${command}]`) {
|
|
60
|
+
await $`podman rm -f ${name}`;
|
|
61
|
+
execCommand(command);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
console.info("Podman container is already running");
|
|
65
|
+
};
|
|
66
|
+
var installBun = async (context) => {
|
|
67
|
+
const bunPath = import.meta.resolve("./bun.sh");
|
|
68
|
+
await copyFiles(context, bunPath, "bun.sh");
|
|
69
|
+
await exec(context, "./bun.sh");
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
runPodmanContainer,
|
|
73
|
+
installSystemPackage,
|
|
74
|
+
installPodman,
|
|
75
|
+
installBun,
|
|
76
|
+
exec,
|
|
77
|
+
debug,
|
|
78
|
+
copyFiles,
|
|
79
|
+
Context
|
|
80
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const debug: (text: string) => void;
|
|
2
|
+
export declare class Context {
|
|
3
|
+
name: string;
|
|
4
|
+
domain: string;
|
|
5
|
+
constructor(name: string, address: string);
|
|
6
|
+
getAddress(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare const copyFiles: (context: Context, from: string, to: string) => Promise<void>;
|
|
9
|
+
export declare const exec: (context: Context, command: string) => Promise<void>;
|
|
10
|
+
export declare const installSystemPackage: (packageName: string) => Promise<void>;
|
|
11
|
+
export declare const installPodman: () => Promise<void>;
|
|
12
|
+
export declare const runPodmanContainer: (command: string, name: string) => Promise<void>;
|
|
13
|
+
export declare const installBun: (context: Context) => Promise<void>;
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ramm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "bun build ./src/ramm.ts --target bun --outdir ./dist && cp ./src/bun.sh ./dist/bun.sh && bun run types",
|
|
7
|
+
"types": "tsc --project tsconfig.types.json"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/",
|
|
10
|
+
"types": "dist/types/ramm.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/*"
|
|
13
|
+
],
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/bun": "latest",
|
|
16
|
+
"typescript": "^5.8.2"
|
|
17
|
+
}
|
|
18
|
+
}
|