"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
 * penguins-eggs
 * command: cuckoo.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */
const core_1 = require("@oclif/core");
const network_1 = tslib_1.__importDefault(require("../classes/network"));
const utils_1 = tslib_1.__importDefault(require("../classes/utils"));
const pxe_1 = tslib_1.__importDefault(require("../classes/pxe"));
const tftp = require('tftp');
class Cuckoo extends core_1.Command {
    async run(nest = '/home/eggs/mnt') {
        const { args, flags } = await this.parse(Cuckoo);
        utils_1.default.titles(this.id + ' ' + this.argv);
        if (utils_1.default.isRoot()) {
            const pxeRoot = nest + '/pxe';
            const pxe = new pxe_1.default();
            await pxe.fertilization();
            await pxe.build();
            const n = new network_1.default();
            /**
             * service proxy-dhcp
             */
            const dhcpOptions = {
                subnet: n.cidr,
                host: n.address,
                tftpserver: n.address,
                bios_filename: 'lpxelinux.0',
                efi32_filename: 'ipxe32.efi',
                efi64_filename: 'ipxe.efi',
            };
            pxe.dhcpStart(dhcpOptions);
            /**
             * service tftp
             */
            const tftpOptions = {
                host: n.address,
                port: 69,
                root: pxeRoot,
                denyPUT: true,
            };
            await pxe.tftpStart(tftpOptions);
            /**
             * service http
             */
            await pxe.httpStart();
        }
        else {
            utils_1.default.useRoot(this.id);
        }
    }
}
Cuckoo.flags = {
    help: core_1.Flags.help({ char: 'h' }),
};
Cuckoo.description = 'PXE start with proxy-dhcp';
Cuckoo.examples = [
    'sudo eggs cuckoo',
];
exports.default = Cuckoo;
