// Compare this checkout with the source a live Sanario site says it was built from. // node scripts/verify-source.mjs https://example.com // Equivalent without Node: curl -s https://example.com/source/SHA256SUMS | sha256sum -c import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; const site = process.argv[2]; if (!site) { console.error('usage: node scripts/verify-source.mjs '); process.exit(2); } const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..'); const res = await fetch(new URL('/source/SHA256SUMS', site)); if (!res.ok) { console.error(`could not fetch SHA256SUMS: HTTP ${res.status}`); process.exit(2); } const lines = (await res.text()).trim().split('\n'); let bad = 0; for (const line of lines) { const [hash, rel] = [line.slice(0, 64), line.slice(66)]; const abs = path.join(root, rel); if (!abs.startsWith(root + path.sep)) { console.log(`SKIP ${rel} (outside checkout)`); bad++; continue; } if (!fs.existsSync(abs)) { console.log(`MISSING ${rel}`); bad++; continue; } const local = crypto.createHash('sha256').update(fs.readFileSync(abs)).digest('hex'); if (local !== hash) { console.log(`DIFFERS ${rel}`); bad++; } } console.log(bad ? `\n${bad} of ${lines.length} files do not match.` : `\nAll ${lines.length} files match the deployed source.`); process.exit(bad ? 1 : 0);