From d6704be6dae2b4884b3ff11964ecdb984bcbb4c0 Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Fri, 29 Jul 2022 00:34:13 +0200 Subject: [PATCH] optimized checkPlatformExact --- src/Util.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Util.js b/src/Util.js index 54a2fe6..855f9f1 100644 --- a/src/Util.js +++ b/src/Util.js @@ -1,4 +1,4 @@ -const {exec} = require("child_process"); +const {exec, execSync} = require("child_process"); const {promisify} = require("util"); const promisifiedExec = promisify(exec); const process = require("process"); @@ -56,19 +56,26 @@ module.exports.getDistroInfo = async function () { return current; }; -module.exports.checkPlatformExact = async function () { - let distroInfo = await this.getDistroInfo(); - if (!distroInfo?.distributorID || !distroInfo?.distributorVersion) { - throw new Error("Missing distro platform information."); - }; +module.exports.checkPlatformExact = function () { + // let distroInfo = await this.getDistroInfo(); + // if (!distroInfo?.distributorID || !distroInfo?.distributorVersion) { + // throw new Error("Missing distro platform information."); + // }; - // https://en.wikipedia.org/wiki/Uncomplicated_Firewall - let platform = distroInfo.distributorID; - if (String(platform).toLowerCase() !== "ubuntu") { - throw new Error("node-ufw only supported on Ubuntu."); - }; + // // https://en.wikipedia.org/wiki/Uncomplicated_Firewall + // let platform = distroInfo.distributorID; + // if (String(platform).toLowerCase() !== "ubuntu") { + // throw new Error("node-ufw only supported on Ubuntu."); + // }; + + // return true; - return true; + try { + return execSync("cat /etc/*release | grep -E ^NAME")?.toString("utf-8").split('=').pop().replace(/(")/gi, "").toLowerCase() == "ubuntu" ? true : false; + } catch (e) { + console.error(e); + return false; + }; }; module.exports.checkAppropriatePort = function(port) {