Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Vision8 * File : server/src/cli/setup.ts9 * Module : cli10 * Repository : https://git.spboucher.ai/maclustr-vision11 * Project Website : https://camera.spboucher.ai12 * Created : 2026-11-3013 * Last Modified : 2026-11-3014 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Mise en place idempotente : dossiers, secret serveur, identité du volume, migrations.43import crypto from 'node:crypto';44import fs from 'node:fs';45import path from 'node:path';46import { ensureDirs, loadConfig } from '../config.ts';47import { openAndMigrate } from '../db.ts';48import { initVolume } from '../storage.ts';4950const cfg = loadConfig();51fs.mkdirSync(cfg.configDir, { recursive: true, mode: 0o700 });52fs.chmodSync(cfg.configDir, 0o700);53ensureDirs(cfg);54const secretFile = path.join(cfg.configDir, 'server-secret');55if (!fs.existsSync(secretFile)) {56 fs.writeFileSync(secretFile, crypto.randomBytes(48).toString('base64url') + '\n', { mode: 0o600 });57 console.log('secret serveur créé');58}59fs.chmodSync(secretFile, 0o600);60const vol = initVolume(cfg);61const db = openAndMigrate(cfg);62const v = db.prepare('SELECT COUNT(*) AS n FROM schema_migrations').get() as { n: number };63db.close();64console.log(`dossiers ok · volume ${vol.slice(0, 8)}… · ${v.n} migration(s) appliquée(s) · données : ${cfg.dataDir}`);65