Skip to content

Commit

Permalink
fix: type error
Browse files Browse the repository at this point in the history
  • Loading branch information
hugojosefson committed Nov 15, 2024
1 parent d01ff96 commit bd816f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function main() {
"-o",
"ConnectTimeout=5",
destination.user + "@" + destination.host,
"bash"
"bash",
],
stdin: "piped",
stdout: "piped",
Expand Down
33 changes: 20 additions & 13 deletions src/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const machine = setup({
events: {} as
| {
type:
| "setContext"
| "contextComplete"
| "cleanedUp"
| "exit"
Expand Down Expand Up @@ -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.`);
},
Expand Down Expand Up @@ -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.`,
);
Expand All @@ -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" },
Expand Down

0 comments on commit bd816f0

Please sign in to comment.