1// Syncro-style Bootstrapper Template
2// Embed tenant/token at build time, handle full onboarding
4const https = require('https');
5const fs = require('fs');
6const path = require('path');
7const { execFile } = require('child_process');
9// These will be replaced at build time - using JSON to avoid pkg optimization issues
10const CONFIG = JSON.parse('{"tenant":"__TENANT__","token":"__TOKEN__"}');
11const TENANT = CONFIG.tenant;
12const TOKEN = CONFIG.token;
20function download(url, dest, cb) {
21 console.log('[DEBUG] Downloading from:', url);
22 const file = fs.createWriteStream(dest);
23 https.get(url, (response) => {
24 console.log('[DEBUG] HTTP status:', response.statusCode);
25 if (response.statusCode !== 200) {
26 cb(new Error('Download failed: ' + response.statusCode));
30 file.on('finish', () => {
31 console.log('[DEBUG] Download finished:', dest);
34 }).on('error', (err) => {
35 console.error('[DEBUG] Download error:', err);
36 fs.unlink(dest, () => cb(err));
45function writeBootstrapJson(tenant, token) {
46 const bootstrapPath = path.join(process.env.ProgramData || 'C:/ProgramData', 'EverydayTechAgent', 'bootstrap.json');
47 console.log('[DEBUG] Writing bootstrap.json to:', bootstrapPath);
48 fs.mkdirSync(path.dirname(bootstrapPath), { recursive: true });
49 fs.writeFileSync(bootstrapPath, JSON.stringify({ tenant, token }, null, 2));
50 console.log('[DEBUG] bootstrap.json written:', { tenant, token });
57 console.log('[DEBUG] Starting bootstrapper...');
58 // Only block if placeholders were NOT replaced
59 if (TENANT === '__TENANT__' || TOKEN === '__TOKEN__') {
60 console.error('Bootstrapper was not built correctly (placeholders still present).');
63 console.log('[DEBUG] Tenant:', TENANT);
64 console.log('[DEBUG] Token length:', TOKEN.length);
66 writeBootstrapJson(TENANT, TOKEN);
68 // Download agent installer (no tenant/token in URL - installer reads bootstrap.json)
69 const installerUrl = `https://everydaytech.au/api/download/dev-agent`;
70 const installerPath = path.join(process.env.TEMP || 'C:/Temp', 'EverydayTechAgent_Installer.exe');
71 console.log('[DEBUG] Downloading agent installer to:', installerPath);
72 download(installerUrl, installerPath, (err) => {
74 console.error('[DEBUG] Download failed:', err);
77 console.log('[DEBUG] Running agent installer with parameters...');
78 // Pass credentials as backup (installer prefers these over bootstrap.json)
79 execFile(installerPath, [`/tenant=${TENANT}`, `/token=${TOKEN}`, '/VERYSILENT'], (error, stdout, stderr) => {
81 console.error('[DEBUG] Installer failed:', error);
82 console.error('[DEBUG] stdout:', stdout);
83 console.error('[DEBUG] stderr:', stderr);
86 console.log('[DEBUG] Agent installer completed successfully.');