"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Utils = void 0;
const child_process_1 = require("child_process");
const fs_1 = require("fs");
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
class Utils {
    static checkSuppressOutputSet() {
        const fileContent = (0, fs_1.readFileSync)('/proc/cmdline', 'utf8');
        if (fileContent.includes("tep_sup_out")) {
            return true;
        }
        return false;
    }
    static execCommand(cmd) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield new Promise((resolve) => {
                const child = (0, child_process_1.exec)(cmd, (err, stdout, stderr) => {
                    if (err == null) {
                        console.log(stdout);
                    }
                    else {
                        console.log(stdout);
                        console.log(stderr);
                    }
                });
                child.on("close", () => {
                    resolve();
                });
            });
        });
    }
    // TODO: USE THIS WITH CAUTION!
    static execHostCommand(cmd) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield new Promise((resolve, reject) => {
                const child = (0, child_process_1.exec)(`nsenter -t 1 -m -u -n -i bash -c "${cmd}"`, (err, stdout, stderr) => {
                    if (err == null) {
                        console.log(stdout);
                    }
                    else {
                        console.log(stdout);
                        console.log(stderr);
                    }
                });
                child.on("close", (ret) => {
                    if (ret === 0) {
                        resolve();
                    }
                    else {
                        reject(new Error(`Command failed with exit code ${ret}`));
                    }
                });
            });
        });
    }
}
exports.Utils = Utils;
_a = Utils;
Utils.suppressOutputSet = _a.checkSuppressOutputSet();
//# sourceMappingURL=utils.js.map