"use strict";
/**
 * penguins-eggs
 * krill modules: add-user.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 utils_2 = require("../../lib/utils");
/**
 *
 * @param this
 * @param name
 * @param password
 * @param fullName
 * @param roomNumber
 * @param workPhone
 * @param homePhone
 */
async function addUser(name = 'live', password = 'evolution', fullName = '', roomNumber = '', workPhone = '', homePhone = '') {
    // Debian
    let cmd = `chroot ${this.installTarget} adduser ${name} --home /home/${name} --shell /bin/bash --disabled-password --gecos "${fullName},${roomNumber},${workPhone},${homePhone}" ${this.toNull}`;
    if (this.distro.familyId === 'archlinux') {
        cmd = `chroot ${this.installTarget} useradd --create-home --shell /bin/bash ${name} ${this.toNull}`;
    }
    await (0, utils_2.exec)(cmd, this.echo);
    cmd = `echo ${name}:${password} | chroot ${this.installTarget} chpasswd ${this.toNull}`;
    await (0, utils_2.exec)(cmd, this.echo);
    // Debian
    cmd = `chroot ${this.installTarget} usermod -aG sudo ${name} ${this.toNull}`;
    if (this.distro.familyId === 'archlinux') {
        cmd = `chroot ${this.installTarget} usermod -aG wheel ${name}`;
    }
    try {
        await (0, utils_2.exec)(cmd, this.echo);
        // check or create group: autologin
        if (this.distro.familyId === 'archlinux') {
            await (0, utils_2.exec)(`chroot ${this.installTarget} getent group autologin || groupadd autologin`);
            await (0, utils_2.exec)(`chroot ${this.installTarget} gpasswd -a ${this.settings.config.user_opt} autologin`);
        }
    }
    catch {
        await utils_1.default.pressKeyToExit(cmd);
    }
}
exports.default = addUser;
