32 lines
986 B
TypeScript
32 lines
986 B
TypeScript
import { readFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { getMqttClient } from "./clients/mqtt/mqtt-client";
|
|
import { ConfigSchema } from "./config.schema";
|
|
import { EfiBootMgrService } from "./efibootmgr.service";
|
|
import { startListeners } from "./listener";
|
|
import { logger } from "./logger";
|
|
import { runPublishLoop } from "./publisher";
|
|
|
|
logger.info("Starting intialization...");
|
|
|
|
const configsFolder = process.env.CONFIGS_PATH || "./";
|
|
|
|
const fileContent = await readFile(join(configsFolder, "config.json"), {
|
|
encoding: "utf8",
|
|
}).catch((e) => {
|
|
throw new Error("Error while reading config!", { cause: e });
|
|
});
|
|
|
|
const json = JSON.parse(fileContent);
|
|
|
|
const config = ConfigSchema.parse(json);
|
|
|
|
const efiBootMgrService = new EfiBootMgrService();
|
|
|
|
const bootEntries = await efiBootMgrService.listBootEntries();
|
|
|
|
const mqttClient = await getMqttClient(config.mqtt);
|
|
|
|
runPublishLoop(config, mqttClient, bootEntries);
|
|
startListeners(config, mqttClient);
|