"use strict";
/**
 * penguins-eggs
 * krill modules: del-live.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 = require("../../lib/utils");
const utils_2 = tslib_1.__importDefault(require("../../classes/utils"));
/**
   * delUser
   * va corretto con users.conf di calamares
*/
async function delLiveUser() {
    if (utils_2.default.isLive()) {
        const user = this.settings.config.user_opt;
        let userExists = false;
        try {
            const cmd = `#!/bin/sh\ngetent passwd "${user}"  > /dev/null`;
            await (0, utils_1.exec)(cmd, utils_2.default.setEcho(this.verbose));
            userExists = true;
        }
        catch (error) {
            console.log(error);
        }
        finally {
            if (userExists) {
                // debian family
                let cmd = `chroot ${this.installTarget} deluser --remove-home ${user} ${this.toNull}`;
                if (this.distro.familyId === 'archlinux') {
                    cmd = `chroot ${this.installTarget} sudo userdel -r ${user} ${this.toNull}`;
                }
                await (0, utils_1.exec)(cmd, this.echo);
            }
        }
    }
}
exports.default = delLiveUser;
