diff --git a/src/efibootmgr.service.ts b/src/efibootmgr.service.ts index 3c9348a..e060060 100644 --- a/src/efibootmgr.service.ts +++ b/src/efibootmgr.service.ts @@ -8,7 +8,7 @@ export class EfiBootMgrService { await $`reboot`; } - async setNextBoot(bootNum: string) { + async setNextBoot(bootNum: number) { await $`efibootmgr -n ${bootNum}`; } diff --git a/src/listener.ts b/src/listener.ts index 8be8619..d1dc382 100644 --- a/src/listener.ts +++ b/src/listener.ts @@ -1,7 +1,9 @@ +/** biome-ignore-all lint/style/noNonNullAssertion: we are checking if boot entry is undefined */ import type { MqttClient } from "mqtt"; import type z from "zod"; import type { ConfigSchema } from "./config.schema"; import type { BootEntries } from "./efibootmgr.schema"; +import { EfiBootMgrService } from "./efibootmgr.service"; import { logger } from "./logger"; export async function startListeners( @@ -11,6 +13,8 @@ export async function startListeners( ) { await mqttClient.subscribeAsync(`efibootmgr-mqtt/${config.device.key}/+`); + const efiBootMgrService = new EfiBootMgrService(); + mqttClient.on("message", async (topic, payload) => { logger.info(topic, payload.toString()); @@ -30,7 +34,11 @@ export async function startListeners( ); } - logger.info(`Rebooting into: ${bootEntry?.label}`); + logger.info(`Rebooting into: ${bootEntry!.label}`); + + await efiBootMgrService.setNextBoot(bootEntry!.number); + + await efiBootMgrService.reboot(); return; }