"use strict";
/**
 * penguins-eggs
 * class: tools.ts
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
const settings_1 = tslib_1.__importDefault(require("./settings"));
const utils_1 = tslib_1.__importDefault(require("./utils"));
/**
 * Utils: general porpourse utils
 * @remarks all the utilities
 */
class Tools {
    constructor() {
        this.tools_yaml = '/etc/penguins-eggs.d/tools.yaml';
        this.snapshot_dir = '';
        this.snapshot_name = '';
        this.config = {};
    }
    /*
     * Load configuration from /etc/penguins-eggs.yaml
     * @returns {boolean} Success
     */
    async loadSettings() {
        let foundSettings = false;
        if (node_fs_1.default.existsSync(this.tools_yaml)) {
            foundSettings = true;
            const loaded = js_yaml_1.default.load(node_fs_1.default.readFileSync(this.tools_yaml, 'utf-8'));
            this.config.remoteHost = loaded.remoteHost;
            this.config.remoteUser = loaded.remoteUser;
            this.config.remotePathDeb = loaded.remotePathDeb;
            this.config.remotePathDoc = loaded.remotePathDoc;
            this.config.remotePathIso = loaded.remotePathIso;
            this.config.localPathDeb = loaded.localPathDeb;
            this.config.localPathDoc = loaded.localPathDoc;
            this.config.localPathIso = loaded.localPathIso;
            this.config.filterDeb = loaded.filterDeb;
            /**
             * da eggs
             */
            const settings = new settings_1.default();
            settings.load();
            this.snapshot_dir = settings.config.snapshot_dir;
            let prefix = settings.config.snapshot_prefix;
            this.snapshot_name = prefix + settings.config.snapshot_basename + '_' + utils_1.default.uefiArch();
        }
        else {
            console.log(`Can't find: ${this.tools_yaml}`);
            process.exit(1);
        }
        return foundSettings;
    }
}
exports.default = Tools;
