"use strict";
/**
 * penguins-eggs
 * krill modules: mount-fs.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 });
exports.umountFs = exports.mountFs = void 0;
const tslib_1 = require("tslib");
const utils_1 = require("../../lib/utils");
const fs_1 = tslib_1.__importDefault(require("fs"));
/**
   * mountFs
   */
async function mountFs() {
    if (!fs_1.default.existsSync(this.installTarget)) {
        await (0, utils_1.exec)(`mkdir ${this.installTarget} ${this.toNull}`, this.echo);
    }
    // root
    await (0, utils_1.exec)(`mount ${this.devices.root.name} ${this.installTarget}${this.devices.root.mountPoint} ${this.toNull}`, this.echo);
    await (0, utils_1.exec)(`tune2fs -c 0 -i 0 ${this.devices.root.name} ${this.toNull}`, this.echo);
    await (0, utils_1.exec)(`rm -rf ${this.installTarget}/lost+found ${this.toNull}`, this.echo);
    // boot
    if (this.devices.boot.name !== 'none') {
        await (0, utils_1.exec)(`mkdir ${this.installTarget}/boot -p ${this.toNull}`, this.echo);
        await (0, utils_1.exec)(`mount ${this.devices.boot.name} ${this.installTarget}${this.devices.boot.mountPoint} ${this.toNull}`, this.echo);
        await (0, utils_1.exec)(`tune2fs -c 0 -i 0 ${this.devices.boot.name} ${this.toNull}`, this.echo);
    }
    // data
    if (this.devices.data.name !== 'none') {
        await (0, utils_1.exec)(`mkdir ${this.installTarget}${this.devices.data.mountPoint} -p ${this.toNull}`, this.echo);
        await (0, utils_1.exec)(`mount ${this.devices.data.name} ${this.installTarget}${this.devices.data.mountPoint} ${this.toNull}`, this.echo);
        await (0, utils_1.exec)(`tune2fs -c 0 -i 0 ${this.devices.data.name} ${this.toNull}`, this.echo);
    }
    // efi
    if (this.efi && !fs_1.default.existsSync(this.installTarget + this.devices.efi.mountPoint)) {
        await (0, utils_1.exec)(`mkdir ${this.installTarget}${this.devices.efi.mountPoint} -p ${this.toNull}`, this.echo);
        await (0, utils_1.exec)(`mount ${this.devices.efi.name} ${this.installTarget}${this.devices.efi.mountPoint} ${this.toNull}`, this.echo);
    }
    return true;
}
exports.mountFs = mountFs;
/**
 * umountFs
 */
async function umountFs() {
    // efi
    if (this.efi) {
        await this.umount(this.devices.efi.name);
    }
    // data
    if (this.devices.data.name !== 'none') {
        await this.umount(this.devices.data.name);
    }
    // boot
    if (this.devices.boot.name !== 'none') {
        await this.umount(this.devices.boot.name);
    }
    // root
    await this.umount(this.devices.root.name);
    return true;
}
exports.umountFs = umountFs;
