import { $ } from "bun";
import fs from "node:fs";
import execute from "../(utils)/execute";

export default async function setupSSH() {
    console.log("Generating SSH keys ...");

    const KEY_NAME = "dsql";
    const OUTPUT_DIR = "/ssh";
    const PASSPHRASE = "";

    execute(`mkdir -p "${OUTPUT_DIR}"`);

    const KEY_PATH = `${OUTPUT_DIR}/${KEY_NAME}`;

    if (!fs.existsSync(KEY_PATH)) {
        console.log("Generating SSH keypair...");
        execute(
            `ssh-keygen -t rsa -b 4096 -f "${KEY_PATH}" -N "${PASSPHRASE}" -q`
        );
    }

    console.log("SSH keys Setup Complete!");
}
