"use strict";
/**
 * penguins-eggs
 * krill modules: network.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 * https://stackoverflow.com/questions/23876782/how-do-i-split-a-typescript-class-into-multiple-files
 */
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const utils_1 = tslib_1.__importDefault(require("../../classes/utils"));
const pacman_1 = tslib_1.__importDefault(require("../../classes/pacman"));
/**
 * networkcfg
 *
 * - debian: /etc/network/interface
 * - ubuntu: netplan
 * - arch:
 *
 * - all: /etc/resolv.conf
 */
async function networkCfg() {
    /**
     * debian: /etc/network/interfaces
     */
    if (this.distro.familyId === 'debian' && !pacman_1.default.packageIsInstalled('netplan.io')) {
        const file = this.installTarget + '/etc/network/interfaces';
        let content = '# created by eggs\n\n';
        content += 'auto lo\n';
        content += 'iface lo inet loopback\n\n';
        content += 'auto ' + this.network.iface + '\n';
        content += 'iface ' + this.network.iface + ' inet ' + this.network.addressType + '\n';
        if (this.network.addressType !== 'dhcp') {
            content += '    address ' + this.network.address + '\n';
            content += '    netmask ' + this.network.netmask + '\n';
            content += '    gateway ' + this.network.gateway + '\n';
        }
        utils_1.default.write(file, content);
        // trixie use systemd-networkd
        // const systemdCtl = new Systemctl()
        // if (await systemdCtl.isActive('systemd-networkd.service')) {
        //  await exec (`rm ${file}`)
        // }
    }
    else if (this.distro.familyId === 'debian' && pacman_1.default.packageIsInstalled('netplan.io')) {
        // ubuntu: netplan
    }
    else if (this.distro.familyId === 'arch') {
        // arch: 
    }
    /**
     * THIS IS EXCLUDED ACTUALLY
     *
    if (this.network.addressType === 'dhcp') {
      const systemdCtl = new Systemctl()
      if (await systemdCtl.isActive('resolvconf.service')) {
        await exec(`rm ${this.installTarget}/etc/resolv.conf`)
        await exec(`ln -s /run/resolvconf/resolv.conf ${this.installTarget}/etc/resolv.conf`)
      } else {
        const file = this.installTarget + '/etc/resolv.conf'
        let content = '# created by eggs\n\n'
        content += 'domain ' + this.network.domain + '\n'
        for (const element of this.network.dns) {
          content += 'nameserver ' + element + '\n'
        }
        Utils.write(file, content)
      }
    }
    */
}
exports.default = networkCfg;
