@campfire-net/campfire-mcp 0.1.2 → 0.1.3
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/index.js +31 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -38,25 +38,50 @@ function getBinaryPath() {
|
|
|
38
38
|
const cachedBin = path.join(cacheDir, platform === 'win32' ? 'cf-mcp.exe' : 'cf-mcp');
|
|
39
39
|
if (fs.existsSync(cachedBin)) return cachedBin;
|
|
40
40
|
|
|
41
|
-
// Download from GitHub Releases
|
|
41
|
+
// Download from GitHub Releases with checksum verification
|
|
42
|
+
const crypto = require('crypto');
|
|
42
43
|
const goArch = arch === 'x64' ? 'amd64' : arch;
|
|
43
44
|
const goPlatform = platform;
|
|
44
45
|
const ext = platform === 'win32' ? 'zip' : 'tar.gz';
|
|
45
|
-
const
|
|
46
|
+
const archiveName = `cf_${goPlatform}_${goArch}.${ext}`;
|
|
47
|
+
const baseUrl = 'https://github.com/campfire-net/campfire/releases/latest/download';
|
|
48
|
+
const archiveUrl = `${baseUrl}/${archiveName}`;
|
|
49
|
+
const checksumsUrl = `${baseUrl}/checksums.txt`;
|
|
50
|
+
const archivePath = path.join(cacheDir, archiveName);
|
|
46
51
|
|
|
47
|
-
process.stderr.write(`campfire-mcp: downloading
|
|
52
|
+
process.stderr.write(`campfire-mcp: downloading ${archiveName}\n`);
|
|
48
53
|
fs.mkdirSync(cacheDir, { recursive: true });
|
|
49
54
|
|
|
50
55
|
try {
|
|
56
|
+
// Download archive and checksums
|
|
57
|
+
execSync(`curl -sL "${archiveUrl}" -o "${archivePath}"`, { stdio: 'pipe' });
|
|
58
|
+
const checksums = execSync(`curl -sL "${checksumsUrl}"`, { encoding: 'utf8' });
|
|
59
|
+
|
|
60
|
+
// Verify SHA256
|
|
61
|
+
const archiveData = fs.readFileSync(archivePath);
|
|
62
|
+
const actualHash = crypto.createHash('sha256').update(archiveData).digest('hex');
|
|
63
|
+
const expectedLine = checksums.split('\n').find(l => l.includes(archiveName));
|
|
64
|
+
if (!expectedLine) {
|
|
65
|
+
throw new Error(`checksum not found for ${archiveName}`);
|
|
66
|
+
}
|
|
67
|
+
const expectedHash = expectedLine.trim().split(/\s+/)[0];
|
|
68
|
+
if (actualHash !== expectedHash) {
|
|
69
|
+
fs.unlinkSync(archivePath);
|
|
70
|
+
throw new Error(`checksum mismatch: expected ${expectedHash}, got ${actualHash}`);
|
|
71
|
+
}
|
|
72
|
+
process.stderr.write(`campfire-mcp: checksum verified\n`);
|
|
73
|
+
|
|
74
|
+
// Extract
|
|
51
75
|
if (platform === 'win32') {
|
|
52
|
-
execSync(`
|
|
76
|
+
execSync(`cd "${cacheDir}" && tar -xf "${archivePath}" --strip-components=1 --include='*/cf-mcp.exe'`, { stdio: 'pipe' });
|
|
53
77
|
} else {
|
|
54
|
-
execSync(`
|
|
78
|
+
execSync(`tar xzf "${archivePath}" -C "${cacheDir}" --strip-components=1 --wildcards '*/cf-mcp'`, { stdio: 'pipe' });
|
|
55
79
|
}
|
|
80
|
+
fs.unlinkSync(archivePath);
|
|
56
81
|
fs.chmodSync(cachedBin, 0o755);
|
|
57
82
|
if (fs.existsSync(cachedBin)) return cachedBin;
|
|
58
83
|
} catch (e) {
|
|
59
|
-
throw new Error(`campfire-mcp: failed to download binary: ${e.message}\nInstall manually: curl -fsSL https://getcampfire.dev/install.sh | sh`);
|
|
84
|
+
throw new Error(`campfire-mcp: failed to download/verify binary: ${e.message}\nInstall manually: curl -fsSL https://getcampfire.dev/install.sh | sh`);
|
|
60
85
|
}
|
|
61
86
|
|
|
62
87
|
throw new Error('campfire-mcp: could not find or download binary');
|