"use strict";
/**
 * penguins-eggs
 * krill modules: grubcfg.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 fs_1 = tslib_1.__importDefault(require("fs"));
/**
* grubcfg
* - open /etc/default/grub
* - find GRUB_CMDLINE_LINUX_DEFAULT=
* - replace with GRUB_CMDLINE_LINUX_DEFAULT=
* 's/GRUB_CMDLINE_LINUX_DEFAULT=.*$/GRUB_CMDLINE_LINUX_DEFAULT=/g'
*/
async function grubcfg() {
    const file = `${this.installTarget}/etc/default/grub`;
    let content = '';
    const grubs = fs_1.default.readFileSync(file, 'utf-8').split('\n');
    for (let i = 0; i < grubs.length; i++) {
        if (grubs[i].includes('GRUB_CMDLINE_LINUX_DEFAULT=')) {
            if (this.partitions.installationMode === 'full-encrypted') {
                grubs[i] = `GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=${utils_1.default.uuid(this.devices.swap.name)}"`;
            }
            else {
                grubs[i] = `GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=${utils_1.default.uuid(this.devices.swap.name)}"`;
            }
        }
        content += grubs[i] + '\n';
    }
    fs_1.default.writeFileSync(file, content, 'utf-8');
}
exports.default = grubcfg;
