'use strict'; const { spawnSync } = require('node:child_process'); const { loadDeployConfig } = require('./deploy-lib.cjs'); function main() { const config = loadDeployConfig('production'); const args = [ '-vv' ]; args.push('-p', String(config.port)); args.push('-i', config.privateKeyPath); for (const option of config.sshOptions) { args.push('-o', option); } args.push(`${config.username}@${config.host}`); args.push('echo AUTH_CHECK_OK'); const result = spawnSync('ssh', args, { encoding: 'utf8', stdio: 'pipe', shell: false, }); const text = `${result.stdout || ''}\n${result.stderr || ''}`; const summary = { keyOffered: /Offering public key:/i.test(text) || /Will attempt key:/i.test(text), keyAccepted: /Authenticated to .* using "publickey"/i.test(text) || /AUTH_CHECK_OK/i.test(text), authFailed: /Permission denied|Authentication failed/i.test(text), hostKeyFailed: /Host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED/i.test(text), networkFailed: /Connection timed out|No route to host|Connection refused|Could not resolve hostname|Operation timed out/i.test(text), }; console.log(JSON.stringify(summary, null, 2)); if (summary.keyAccepted) { process.exit(0); } process.exit(1); } main();