From bd816f062a38c9dbb90ebc6362c404d27c86a968 Mon Sep 17 00:00:00 2001 From: Hugo Josefson Date: Fri, 15 Nov 2024 09:51:39 +0100 Subject: [PATCH] fix: type error --- README.md | 11 ++++++----- src/cli.ts | 2 +- src/machine.ts | 33 ++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d997115..0f1ce0f 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,11 @@ pass show zfs_disk_passphrase | dropbear-auto-unlock root@pve-01 ## TODO -- [ ] Instead of checking first line of ssh server, spawn `ssh` and get a proper +- [x] Instead of checking first line of ssh server, spawn `ssh` and get a proper line stream. -- [ ] Check if the prompt is an unlock prompt. If so, unlock. -- [ ] Check if we can run `zfsunlock`. If so, unlock. -- [ ] If we're in the server booted, `sleep infinity`, then wait for broken +- [x] Check if the prompt is an unlock prompt. If so, unlock. +- [x] ~~Check if we can run `zfsunlock`. If so, unlock.~~ +- [x] If we're in the server booted, `sleep infinity`, then wait for broken connection indicating next boot. -- [ ] Add timeout arguments/options to `ssh` command. +- [x] Add timeout arguments/options to `ssh` command. +- [ ] Support secondary destination for same server. diff --git a/src/cli.ts b/src/cli.ts index 650d2e1..c86dbd8 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -21,7 +21,7 @@ async function main() { "-o", "ConnectTimeout=5", destination.user + "@" + destination.host, - "bash" + "bash", ], stdin: "piped", stdout: "piped", diff --git a/src/machine.ts b/src/machine.ts index 8e78b64..218397b 100644 --- a/src/machine.ts +++ b/src/machine.ts @@ -26,7 +26,6 @@ export const machine = setup({ events: {} as | { type: - | "setContext" | "contextComplete" | "cleanedUp" | "exit" @@ -130,32 +129,38 @@ export const machine = setup({ let done = false; try { while (!done) { - const result = await reader.read(); - const burst = result.value; - done = result.done; - console.log(context.destination.host + ":", {done, burst}); + const result = await reader.read(); + const burst = result.value; + done = result.done; + console.log(context.destination.host + ":", { done, burst }); if (done || !burst) { - console.log(`${context?.destination?.host}: Got no output (already done).`); + console.log( + `${context?.destination?.host}: Got no output (already done).`, + ); continue; } if (isZfsUnlockPrompt(burst)) { console.log( `${context?.destination?.host}: Got zfs unlock prompt.`, ); - self.send({type: "zfsUnlockPromptDetected"}); + self.send({ type: "zfsUnlockPromptDetected" }); break; } if (isCommandPrompt(burst)) { console.log(`${context?.destination?.host}: Got command prompt.`); - self.send({type: "commandPromptDetected"}); + self.send({ type: "commandPromptDetected" }); break; } console.log(`${context?.destination?.host}: Got other output.`); } } finally { - console.log(`${context?.destination?.host}: Releasing stdout reader lock.`); + console.log( + `${context?.destination?.host}: Releasing stdout reader lock.`, + ); reader.releaseLock(); - console.log(`${context?.destination?.host}: Released stdout reader lock.`); + console.log( + `${context?.destination?.host}: Released stdout reader lock.`, + ); } console.log(`${context?.destination?.host}: Done reading output.`); }, @@ -190,11 +195,13 @@ export const machine = setup({ }, entry: ({ context, self }) => { console.log(`${context?.destination?.host}: Checking ZFS status...`); - console.log(`${context?.destination?.host}: Lol jk. Assuming zfs is unlocked.`); + console.log( + `${context?.destination?.host}: Lol jk. Assuming zfs is unlocked.`, + ); console.log( `${context?.destination?.host}: ZFS filesystem is unlocked.`, ); - self.send({type: "zfsUnlocked"}); + self.send({ type: "zfsUnlocked" }); console.log( `${context?.destination?.host}: Done checking ZFS status.`, ); @@ -208,7 +215,7 @@ export const machine = setup({ await context.stdin.write("sleep infinity\n"); console.log(`${context?.destination?.host}: Ran sleep infinity.`); await context.sshProcess.status; - self.send({type: "serverRebootDetected"}); + self.send({ type: "serverRebootDetected" }); }, on: { serverRebootDetected: { target: "cleanup" },