@poetic-ai/poetic-install 1.42.0-rc10
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/bin/poetic-install.mjs +94 -0
- package/install.sh +3292 -0
- package/install.sh.sha256 +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { dirname, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
|
+
const packageJsonPath = resolve(packageRoot, 'package.json');
|
|
11
|
+
const installerPath = resolve(packageRoot, 'install.sh');
|
|
12
|
+
const checksumPath = resolve(packageRoot, 'install.sh.sha256');
|
|
13
|
+
|
|
14
|
+
function fail(message) {
|
|
15
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!['darwin', 'linux'].includes(process.platform)) {
|
|
20
|
+
fail(`Poetic supports macOS and Linux (detected ${process.platform}). On Windows, use WSL.`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const nodeMajor = Number.parseInt(process.versions.node.split('.')[0] ?? '', 10);
|
|
24
|
+
if (nodeMajor !== 24 && process.env.POETIC_ALLOW_UNSUPPORTED_NODE !== '1') {
|
|
25
|
+
fail(
|
|
26
|
+
`Node.js 24.x is required (found ${process.version}). Install Node 24 and rerun, or set POETIC_ALLOW_UNSUPPORTED_NODE=1 to use the installer's unsupported-runtime override.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const bashProbe = spawnSync('bash', ['--version'], { stdio: 'ignore' });
|
|
31
|
+
if (bashProbe.error || bashProbe.status !== 0) {
|
|
32
|
+
fail('bash is required to run the bundled Poetic installer.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let packageVersion;
|
|
36
|
+
let installerBytes;
|
|
37
|
+
let expectedChecksum;
|
|
38
|
+
try {
|
|
39
|
+
packageVersion = JSON.parse(readFileSync(packageJsonPath, 'utf8')).version;
|
|
40
|
+
installerBytes = readFileSync(installerPath);
|
|
41
|
+
expectedChecksum = readFileSync(checksumPath, 'utf8').trim().split(/\s+/)[0];
|
|
42
|
+
} catch (error) {
|
|
43
|
+
fail(`Could not read the bundled installer: ${error instanceof Error ? error.message : error}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof packageVersion !== 'string' || packageVersion.length === 0) {
|
|
47
|
+
fail('The bootstrap package has no valid version.');
|
|
48
|
+
}
|
|
49
|
+
if (!/^[a-f0-9]{64}$/.test(expectedChecksum ?? '')) {
|
|
50
|
+
fail('The bundled install.sh checksum is malformed.');
|
|
51
|
+
}
|
|
52
|
+
const actualChecksum = createHash('sha256').update(installerBytes).digest('hex');
|
|
53
|
+
if (actualChecksum !== expectedChecksum) {
|
|
54
|
+
fail(
|
|
55
|
+
`Bundled install.sh checksum mismatch (expected ${expectedChecksum}, got ${actualChecksum}).`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const forwardedArgs = process.argv.slice(2);
|
|
60
|
+
if (forwardedArgs[0] === '--') forwardedArgs.shift();
|
|
61
|
+
const uninstalling = forwardedArgs.includes('--uninstall');
|
|
62
|
+
const hasArgument = (name) =>
|
|
63
|
+
forwardedArgs.some((argument) => argument === name || argument.startsWith(`${name}=`));
|
|
64
|
+
const hasExplicitSource = hasArgument('--source') || hasArgument('--channel');
|
|
65
|
+
const bootstrapDefaults = [];
|
|
66
|
+
if (!hasExplicitSource) {
|
|
67
|
+
bootstrapDefaults.push('--source', 'package');
|
|
68
|
+
if (!hasArgument('--version')) bootstrapDefaults.push('--version', packageVersion);
|
|
69
|
+
}
|
|
70
|
+
const installerArgs = uninstalling ? forwardedArgs : [...bootstrapDefaults, ...forwardedArgs];
|
|
71
|
+
|
|
72
|
+
const child = spawn('bash', [installerPath, ...installerArgs], {
|
|
73
|
+
stdio: 'inherit',
|
|
74
|
+
env: { ...process.env, POETIC_BOOTSTRAP_VERSION: packageVersion },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const forwardedSignals = new Map();
|
|
78
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
79
|
+
const forward = () => child.kill(signal);
|
|
80
|
+
forwardedSignals.set(signal, forward);
|
|
81
|
+
process.on(signal, forward);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
child.on('error', (error) => fail(`Could not launch install.sh: ${error.message}`));
|
|
85
|
+
child.on('exit', (code, signal) => {
|
|
86
|
+
if (signal) {
|
|
87
|
+
for (const [forwardedSignal, handler] of forwardedSignals) {
|
|
88
|
+
process.off(forwardedSignal, handler);
|
|
89
|
+
}
|
|
90
|
+
process.kill(process.pid, signal);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
process.exit(code ?? 1);
|
|
94
|
+
});
|