twokeys-server
Version:
Server for 2Keys
75 lines (71 loc) • 2.82 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
Copyright 2018 Kishan Sambhi
This file is part of 2Keys.
2Keys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2Keys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with 2Keys. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @overview OOBE entry point
*/
const fs_1 = require("fs");
const util_1 = require("util");
const yaml_1 = __importDefault(require("yaml"));
const constants_1 = require("../util/constants");
const logger_1 = __importDefault(require("../util/logger"));
const config_1 = require("../util/config");
const software_1 = __importDefault(require("./software"));
const writeFile = util_1.promisify(fs_1.writeFile);
const logger = new logger_1.default({
name: "oobe",
});
async function run_oobe(argv) {
logger.info("Starting OOBE...");
logger.debug("Checking if OOBE has already been ran...");
let config = constants_1.default_userspace_config; // So we don't risk config being undefined
try {
config = await config_1.userspace_config_loader();
}
catch (err) {
if (err.code === "ENOENT") {
// Doesn't exist
logger.info("Generating config...");
await writeFile(constants_1.DEFAULT_USERSPACE_CONFIG, yaml_1.default.stringify(constants_1.default_userspace_config));
}
else {
logger.err(`Error accesing userspace config file (${constants_1.DEFAULT_USERSPACE_CONFIG})!`);
logger.throw(err);
}
}
finally {
// Verify OOBE
if (config.oobe && !argv.force) {
// Run before
logger.info("OOBE has been run before.");
}
else {
// Run OOBE
// Step 1: Fetch Software
await software_1.default(argv);
logger.info("OOBE done!");
// DONE!
config.oobe = true;
logger.debug("Updating userspace config...");
await writeFile(constants_1.DEFAULT_USERSPACE_CONFIG, yaml_1.default.stringify(constants_1.default_userspace_config));
}
}
}
exports.default = run_oobe;
//# sourceMappingURL=index.js.map