oss-railway 0.0.0-stage → 0.2.0

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/README.md CHANGED
@@ -1,3 +1,12 @@
1
- # Temporary Holding Version
1
+ # oss-railway
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Install OSS Railway, a self-hosted PaaS, on a Linux server.
4
+
5
+ > **Work in progress.** Still being built and not yet tested on many real servers. Don't use it for anything critical yet. Source, docs and status: https://github.com/KumarRoushan9234/OSS-Railway
6
+
7
+ ```sh
8
+ npx oss-railway setup root@203.0.113.10 [-p 22] [-i ~/.ssh/id_ed25519] # over SSH
9
+ sudo npx oss-railway install # on the server
10
+ ```
11
+
12
+ Then open the printed URL and enter the setup code.
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { spawn } = require('node:child_process');
5
+ const fs = require('node:fs');
6
+ const os = require('node:os');
7
+ const path = require('node:path');
8
+
9
+ const INSTALL_URL =
10
+ process.env.OSSR_INSTALL_URL ||
11
+ 'https://raw.githubusercontent.com/KumarRoushan9234/OSS-Railway/main/install.sh';
12
+ const DRY_RUN = process.env.OSSR_DRY_RUN === '1';
13
+
14
+ const USAGE = `Usage:
15
+ oss-railway setup <user@host> [-p port] [-i identityFile] install on a server over SSH
16
+ oss-railway install install on this Linux server (as root)
17
+ oss-railway help show this help`;
18
+
19
+ // user: letters, digits, dot, dash, underscore (not leading dash).
20
+ // host: IPv4 or hostname labels of letters, digits, dash (not leading dash).
21
+ const TARGET_RE =
22
+ /^([A-Za-z0-9_][A-Za-z0-9._-]{0,31})@((?:\d{1,3}\.){3}\d{1,3}|[A-Za-z0-9](?:[A-Za-z0-9-]{0,62})(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,62}))*)$/;
23
+
24
+ function fail(msg) {
25
+ console.error(`oss-railway: ${msg}`);
26
+ process.exit(2);
27
+ }
28
+
29
+ function run(cmd, args) {
30
+ if (DRY_RUN) {
31
+ console.log([cmd, ...args].map(quote).join(' '));
32
+ process.exit(0);
33
+ }
34
+ const child = spawn(cmd, args, { stdio: 'inherit' });
35
+ child.on('error', (err) => fail(`could not run ${cmd}: ${err.message}`));
36
+ child.on('exit', (code, signal) => process.exit(signal ? 1 : code ?? 1));
37
+ }
38
+
39
+ // Display-only quoting for dry-run output.
40
+ function quote(s) {
41
+ return /^[A-Za-z0-9_@%+=:,./-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`;
42
+ }
43
+
44
+ function shQuote(s) {
45
+ return `'${s.replace(/'/g, `'\\''`)}'`;
46
+ }
47
+
48
+ function setup(argv) {
49
+ let target;
50
+ let port;
51
+ let identity;
52
+ for (let i = 0; i < argv.length; i++) {
53
+ const a = argv[i];
54
+ if (a === '-p' || a === '-i') {
55
+ const v = argv[++i];
56
+ if (v === undefined) fail(`${a} needs a value`);
57
+ if (a === '-p') {
58
+ if (!/^\d{1,5}$/.test(v) || +v < 1 || +v > 65535) fail(`invalid port: ${v}`);
59
+ port = v;
60
+ } else {
61
+ if (v.startsWith('-')) fail(`invalid identity file: ${v}`);
62
+ identity = v;
63
+ }
64
+ } else if (target === undefined && TARGET_RE.test(a)) {
65
+ const ip = a.split('@')[1];
66
+ if (/^[\d.]+$/.test(ip) && ip.split('.').some((n) => +n > 255)) fail(`invalid host: ${a}`);
67
+ target = a;
68
+ } else {
69
+ fail(`invalid argument: ${a}\n${USAGE}`);
70
+ }
71
+ }
72
+ if (!target) fail(`missing <user@host>\n${USAGE}`);
73
+
74
+ const user = target.split('@')[0];
75
+ const sh = user === 'root' ? 'sh' : 'sudo sh';
76
+ const remote = `curl -fsSL ${shQuote(INSTALL_URL)} | ${sh}`;
77
+
78
+ const args = [];
79
+ if (port) args.push('-p', port);
80
+ if (identity) args.push('-i', identity);
81
+ args.push('--', target, remote);
82
+ run('ssh', args);
83
+ }
84
+
85
+ async function install() {
86
+ const isRoot = typeof process.getuid === 'function' && process.getuid() === 0;
87
+ if (process.platform !== 'linux' || !isRoot) {
88
+ console.log('Run this as root on the Linux server, or from your machine:');
89
+ console.log(' npx oss-railway setup root@<server-ip>');
90
+ process.exit(0);
91
+ }
92
+ if (DRY_RUN) return run('sh', ['<downloaded install.sh>']);
93
+
94
+ const res = await fetch(INSTALL_URL);
95
+ if (!res.ok) fail(`download failed: HTTP ${res.status} ${INSTALL_URL}`);
96
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ossr-'));
97
+ const file = path.join(dir, 'install.sh');
98
+ fs.writeFileSync(file, Buffer.from(await res.arrayBuffer()), { mode: 0o700 });
99
+ process.on('exit', () => fs.rmSync(dir, { recursive: true, force: true }));
100
+ run('sh', [file]);
101
+ }
102
+
103
+ const [cmd, ...rest] = process.argv.slice(2);
104
+ switch (cmd) {
105
+ case 'setup':
106
+ setup(rest);
107
+ break;
108
+ case 'install':
109
+ install().catch((err) => fail(err.message));
110
+ break;
111
+ case undefined:
112
+ case 'help':
113
+ case '-h':
114
+ case '--help':
115
+ console.log(USAGE);
116
+ break;
117
+ default:
118
+ console.error(USAGE);
119
+ process.exit(2);
120
+ }
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "oss-railway",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Install OSS Railway, a self-hosted PaaS, on any Linux server",
5
+ "license": "Apache-2.0",
6
+ "bin": {
7
+ "oss-railway": "bin/oss-railway.js"
8
+ },
9
+ "files": [
10
+ "bin"
11
+ ],
12
+ "engines": {
13
+ "node": ">=18"
14
+ },
15
+ "homepage": "https://kumarroushan9234.github.io/OSS-Railway/",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/KumarRoushan9234/OSS-Railway.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/KumarRoushan9234/OSS-Railway/issues"
22
+ },
23
+ "keywords": [
24
+ "paas",
25
+ "self-hosted",
26
+ "docker",
27
+ "caddy",
28
+ "deploy",
29
+ "railway",
30
+ "vps"
31
+ ]
32
+ }