From 5db981228e5aa25a1606eeaa4cd643d8844dfa9e Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Fri, 23 Dec 2022 21:41:47 +0100 Subject: [PATCH] distro info for linux --- osUtil.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 osUtil.js diff --git a/osUtil.js b/osUtil.js new file mode 100644 index 0000000..cd8307f --- /dev/null +++ b/osUtil.js @@ -0,0 +1,17 @@ +const fs = require("fs"); + +const getLinuxDistroInfo = async() => { + let os = await fs.promises.readFile('/etc/os-release', 'utf8') + let opj = {} + + os?.split('\n')?.forEach((line, index) => { + let words = line?.split('=') + let key = words[0]?.toLowerCase() + if (key === '') return + let value = words[1]?.replace(/"/g, '') + opj[key] = value + }) + return opj; +} + +module.exports = { getLinuxDistroInfo }; \ No newline at end of file