New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

getos

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getos - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

85

index.js

@@ -17,9 +17,9 @@ /**

*/
module.exports = function getOs(cb) {
module.exports = function getOs (cb) {
// Node builtin as first line of defense.
var osName = os.platform()
// Linux is a special case.
if(osName === "linux") return getLinuxDistro(cb)
if (osName === 'linux') return getLinuxDistro(cb)
// Else, node's builtin is acceptable.
return cb(null,{"os":osName})
return cb(null, {'os': osName})
}

@@ -30,3 +30,3 @@

*/
function getLinuxDistro(cb) {
function getLinuxDistro (cb) {
/**

@@ -37,3 +37,3 @@ * First, we check to see if this function has been called before.

*/
if(cachedDistro) return cb(null,cachedDistro)
if (cachedDistro) return cb(null, cachedDistro)

@@ -45,4 +45,4 @@ /**

*/
getReleaseFile(Object.keys(distros),function(e,file) {
if(e) return cb(e)
getReleaseFile(Object.keys(distros), function (e, file) {
if (e) return cb(e)

@@ -54,7 +54,7 @@ /**

*/
var candidates = distros[file],
os = {"os":"linux","dist":candidates[0]}
var candidates = distros[file]
var os = { 'os': 'linux', 'dist': candidates[0] }
fs.readFile(file,'utf-8',function(e,file) {
if(e) return cb(e)
fs.readFile(file, 'utf-8', function (e, file) {
if (e) return cb(e)

@@ -66,7 +66,7 @@ /**

*/
if(candidates.length===1) {
return customLogic(os,getName(os.dist),file,function(e,os) {
if(e) return cb(e)
if (candidates.length === 1) {
return customLogic(os, getName(os.dist), file, function (e, os) {
if (e) return cb(e)
cachedDistro = os
return cb(null,os)
return cb(null, os)
})

@@ -86,20 +86,19 @@ }

*/
async.each(candidates, function(candidate, done) {
var name = getName(candidate);
if(file.indexOf(name)>=0) {
async.each(candidates, function (candidate, done) {
var name = getName(candidate)
if (file.indexOf(name) >= 0) {
os.dist = candidate
return customLogic(os,name,file,function(e, augmentedOs) {
if(e) return done(e)
os = augmentedOs;
return done();
return customLogic(os, name, file, function (e, augmentedOs) {
if (e) return done(e)
os = augmentedOs
return done()
})
} else {
return done();
return done()
}
}, function(e) {
if(e) return cb(e)
}, function (e) {
if (e) return cb(e)
cachedDistro = os
return cb(null,os)
});
return cb(null, os)
})
})

@@ -109,3 +108,3 @@ })() // sneaky sneaky.

function getName(candidate) {
function getName (candidate) {
/**

@@ -122,6 +121,6 @@ * We only care about the first word. I.E. for Arch Linux it is safe

*/
while(name === 'linux') {
name = candidate.split(" ")[index++].toLowerCase()
while (name === 'linux') {
name = candidate.split(' ')[index++].toLowerCase()
}
return name;
return name
}

@@ -132,5 +131,4 @@

*/
function customLogic(os,name,file,cb) {
try{require("./logic/"+name+".js")(os,file,cb)}
catch(e) {cb(null,os)}
function customLogic (os, name, file, cb) {
try { require('./logic/' + name + '.js')(os, file, cb) } catch (e) { cb(null, os) }
}

@@ -142,12 +140,12 @@

*/
function getReleaseFile(names,cb) {
var index = 0 //Lets keep track of which file we are on.
function getReleaseFile (names, cb) {
var index = 0 // Lets keep track of which file we are on.
/**
* checkExists() is a first class function that we are using for recursion.
*/
return function checkExists() {
return function checkExists () {
/**
* Lets get the file metadata off the current file.
*/
fs.stat(names[index],function(e,stat) {
fs.stat(names[index], function (e, stat) {
/**

@@ -157,11 +155,12 @@ * Now we check if either the file didn't exist, or it is something

*/
if(e || !stat.isFile()) {
if (e || !stat.isFile()) {
index++ // If it is not a file, we will check the next one!
if(names.length <= index) // Unless we are out of files.
return cb(new Error("No unique release file found!")) // Then error.
if (names.length <= index) { // Unless we are out of files.
return cb(new Error('No unique release file found!')) // Then error.
}
return checkExists() // Re-call this function to check the next file.
}
cb(null,names[index]) // If we found a file, return it!
cb(null, names[index]) // If we found a file, return it!
})
}
}
var releaseRegex = /(.*)/
module.exports = function alpineCustomLogic(os,file,cb) {
module.exports = function alpineCustomLogic (os, file, cb) {
var release = file.match(releaseRegex)
if(release && release.length === 2) os.release = release[1]
cb(null,os)
if (release && release.length === 2) os.release = release[1]
cb(null, os)
}
var releaseRegex = /release (.*)/
module.exports = function amazonCustomLogic(os,file,cb) {
var release = file.match(releaseRegex)
if (release && release.length === 2) os.release = release[1]
cb(null,os)
};
module.exports = function amazonCustomLogic (os, file, cb) {
var release = file.match(releaseRegex)
if (release && release.length === 2) os.release = release[1]
cb(null, os)
}
var releaseRegex = /release ([^ ]+)/
var codenameRegex = /\((.*)\)/
module.exports = function centosCustomLogic(os,file,cb) {
module.exports = function centosCustomLogic (os, file, cb) {
var release = file.match(releaseRegex)
if(release && release.length === 2) os.release = release[1]
if (release && release.length === 2) os.release = release[1]
var codename = file.match(codenameRegex)
if(codename && codename.length === 2) os.codename = codename[1]
cb(null,os)
if (codename && codename.length === 2) os.codename = codename[1]
cb(null, os)
}

@@ -6,22 +6,22 @@ var exec = require('child_process').exec

module.exports = function(os,file,cb) {
//first try lsb_release
return lsbrelease(os,file,cb)
module.exports = function (os, file, cb) {
// first try lsb_release
return lsbrelease(os, file, cb)
}
function lsbrelease(os,file,cb) {
exec("lsb_release -a",function(e,stdout,stderr) {
if(e) return releasefile(os,file,cb)
function lsbrelease (os, file, cb) {
exec('lsb_release -a', function (e, stdout, stderr) {
if (e) return releasefile(os, file, cb)
var release = stdout.match(lsbRelease)
if(release && release.length === 2) os.release = release[1]
if (release && release.length === 2) os.release = release[1]
var codename = stdout.match(lsbCodename)
if(codename && release.length === 2) os.codename = codename[1]
cb(null,os)
if (codename && release.length === 2) os.codename = codename[1]
cb(null, os)
})
}
function releasefile(os,file,cb) {
function releasefile (os, file, cb) {
var release = file.match(releaseRegex)
if(release && release.length === 2) os.release = release[1]
cb(null,os)
if (release && release.length === 2) os.release = release[1]
cb(null, os)
}
var releaseRegex = /release (..)/
var codenameRegex = /\((.*)\)/
module.exports = function fedoraCustomLogic(os,file,cb) {
module.exports = function fedoraCustomLogic (os, file, cb) {
var release = file.match(releaseRegex)
if(release && release.length === 2) os.release = release[1]
if (release && release.length === 2) os.release = release[1]
var codename = file.match(codenameRegex)
if(codename && codename.length === 2) os.codename = codename[1]
cb(null,os)
if (codename && codename.length === 2) os.codename = codename[1]
cb(null, os)
}

@@ -1,1 +0,1 @@

module.exports = require('./centos')
module.exports = require('./centos')
var releaseRegex = /VERSION = (.*)\n/
module.exports = function suseCustomLogic(os,file,cb) {
module.exports = function suseCustomLogic (os, file, cb) {
var release = file.match(releaseRegex)
if(release && release.length === 2) os.release = release[1]
cb(null,os)
if (release && release.length === 2) os.release = release[1]
cb(null, os)
}
var releaseRegex = /distrib_release=(.*)/
var codenameRegex = /distrib_codename=(.*)/
module.exports = function ubuntuCustomLogic(os,file,cb) {
module.exports = function ubuntuCustomLogic (os, file, cb) {
var codename = file.match(codenameRegex)
if(codename && codename.length === 2) os.codename = codename[1]
if (codename && codename.length === 2) os.codename = codename[1]
var release = file.match(releaseRegex)
if(release && release.length === 2) os.release = release[1]
cb(null,os)
if (release && release.length === 2) os.release = release[1]
cb(null, os)
}
{
"name": "getos",
"version": "3.0.0",
"version": "3.0.1",
"description": "Get the OS/Distribution name of the environment you are working on",

@@ -8,3 +8,5 @@ "main": "index.js",

"test": "node tests/mocktests.js",
"integration": "node tests/runTest.js"
"posttest": "standard",
"integration": "node tests/runTest.js",
"standard-fix": "standard --fix"
},

@@ -29,2 +31,3 @@ "repository": {

"execSync": "1.0.2",
"standard": "^10.0.2",
"tape": "4.6.3"

@@ -31,0 +34,0 @@ },

@@ -9,3 +9,5 @@ # getos

[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
Get the OS/Distribution name of the environment you are working on

@@ -34,2 +36,3 @@

{
os: [OS NAME],
dist:[DIST NAME],

@@ -41,2 +44,13 @@ codename:[CODENAME],

For example:
```js
{
os: "linux",
dist: "Ubuntu Linux",
codename: "precise",
release: "12.04"
}
```
## Disclaimer

@@ -43,0 +57,0 @@ Check `os.json` in this repo. Any distribution that *shares* a common resource file with another distrubtion is currently untested. These are the arrays of distrubitons with more than 1 member. If you are using one of these distrubtions, please submit an issue letting me know if it works. If it fails, please post the content of the file.

@@ -1,4 +0,4 @@

require("./index.js")(function(e,os) {
if(e) return console.log(e)
require('./index.js')(function (e, os) {
if (e) return console.log(e)
return console.log(JSON.stringify(os))
})

@@ -6,26 +6,18 @@ var test = require('tape')

var orig = {
platform: os.platform,
stat: fs.stat,
readFile: fs.readFile
}
var currentData
os.platform = function() {
os.platform = function () {
return currentData.platform
}
fs.stat = function(file, callback) {
process.nextTick(function() {
if (!currentData.file[file])
return callback(new Error())
callback(null, { isFile: function() { return true }})
fs.stat = function (file, callback) {
process.nextTick(function () {
if (!currentData.file[file]) { return callback(new Error()) }
callback(null, { isFile: function () { return true } })
})
}
fs.readFile = function(file, enc, callback) {
process.nextTick(function() {
if (!currentData.file[file])
return callback(new Error())
fs.readFile = function (file, enc, callback) {
process.nextTick(function () {
if (!currentData.file[file]) { return callback(new Error()) }
callback(null, currentData.file[file])

@@ -32,0 +24,0 @@ })

@@ -11,24 +11,22 @@ var color = require('cli-color')

*/
var cwd = path.join(process.cwd(),"tests")
process.stdout.write("Fetching Distributions... ")
var cwd = path.join(process.cwd(), 'tests')
process.stdout.write('Fetching Distributions... ')
var distros = fs.readdirSync(cwd)
var failed = []
process.stdout.write("["+color.green("OK!")+"]\n")
distros.forEach(function(v1) {
if(!fs.statSync(path.join(cwd,v1)).isDirectory()) return;
process.stdout.write("Fetching versions of "+capitalize(v1)+"... ")
var versions = fs.readdirSync(path.join(cwd,v1))
process.stdout.write("["+color.green("OK!")+"]\n")
versions.forEach(function(v2) {
if(!fs.statSync(path.join(cwd,v1,v2)).isDirectory()) return;
//If Dockerfile already exists, delete it.
if(fs.existsSync(path.join(process.cwd(),"Dockerfile")))
fs.unlinkSync(path.join(process.cwd(),"Dockerfile"))
//Move the dockerfile to the base of our repo
fs.linkSync(path.join(cwd,v1,v2,"Dockerfile"),path.join(process.cwd(),"Dockerfile"))
//Build the docker image using the dockerfile
process.stdout.write("Building version "+v2+" of "+capitalize(v1)+"... ")
var cmd = "docker build -t \"getos:"+v1+v2+"\" ."
process.stdout.write('[' + color.green('OK!') + ']\n')
distros.forEach(function (v1) {
if (!fs.statSync(path.join(cwd, v1)).isDirectory()) return
process.stdout.write('Fetching versions of ' + capitalize(v1) + '... ')
var versions = fs.readdirSync(path.join(cwd, v1))
process.stdout.write('[' + color.green('OK!') + ']\n')
versions.forEach(function (v2) {
if (!fs.statSync(path.join(cwd, v1, v2)).isDirectory()) return
// If Dockerfile already exists, delete it.
if (fs.existsSync(path.join(process.cwd(), 'Dockerfile'))) { fs.unlinkSync(path.join(process.cwd(), 'Dockerfile')) }
// Move the dockerfile to the base of our repo
fs.linkSync(path.join(cwd, v1, v2, 'Dockerfile'), path.join(process.cwd(), 'Dockerfile'))
// Build the docker image using the dockerfile
process.stdout.write('Building version ' + v2 + ' of ' + capitalize(v1) + '... ')
try {
var dockerResult = execSync("docker build -t \"getos:"+v1+v2+"\" .",{stdio:[]})
var dockerResult = execSync('docker build -t "getos:' + v1 + v2 + '" .', {stdio: []})
} catch (e) {

@@ -38,11 +36,11 @@ dockerResult = dockerResult || {}

}
if(dockerResult.code&&dockerResult.code!==0) {
if (dockerResult.code && dockerResult.code !== 0) {
failed.push(dockerResult)
process.stdout.write("["+color.red("FAILED!")+"]\n")
process.stdout.write('[' + color.red('FAILED!') + ']\n')
} else {
process.stdout.write("["+color.green("OK!")+"]\n")
process.stdout.write("Running container... ")
//Show output from distribution
process.stdout.write('[' + color.green('OK!') + ']\n')
process.stdout.write('Running container... ')
// Show output from distribution
try {
var nodeResult = execSync("docker run -d getos:"+v1+v2,{stdio:[]})
var nodeResult = execSync('docker run -d getos:' + v1 + v2, {stdio: []})
} catch (e) {

@@ -52,8 +50,8 @@ nodeResult = nodeResult || {}

}
if(nodeResult.code && nodeResult.code!==0) {
if (nodeResult.code && nodeResult.code !== 0) {
failed.push(nodeResult)
process.stdout.write("["+color.red("FAILED!")+"]\n")
process.stdout.write('[' + color.red('FAILED!') + ']\n')
} else {
try {
var dockerLog = execSync("sleep 2s && docker logs "+(nodeResult.stdout || nodeResult.toString()),{stdio:[]})
var dockerLog = execSync('sleep 2s && docker logs ' + (nodeResult.stdout || nodeResult.toString()), {stdio: []})
} catch (e) {

@@ -63,23 +61,23 @@ dockerLog = dockerLog || {}

}
if(dockerLog.code && dockerLog.code!==0) {
if (dockerLog.code && dockerLog.code !== 0) {
failed.push(dockerLog)
process.stdout.write("["+color.red("FAILED!")+"]\n")
process.stdout.write('[' + color.red('FAILED!') + ']\n')
} else {
process.stdout.write("["+color.green("OK!")+"]\n")
process.stdout.write("Output from version "+v2+" of "+capitalize(v1)+": \n")
process.stdout.write(dockerLog.stdout||dockerLog.toString())
process.stdout.write('[' + color.green('OK!') + ']\n')
process.stdout.write('Output from version ' + v2 + ' of ' + capitalize(v1) + ': \n')
process.stdout.write(dockerLog.stdout || dockerLog.toString())
}
}
}
//Delete the dockerfile
fs.unlinkSync(path.join(process.cwd(),"Dockerfile"))
// Delete the dockerfile
fs.unlinkSync(path.join(process.cwd(), 'Dockerfile'))
})
})
if(failed.length>0) {
fs.writeFileSync("tests.log",JSON.stringify(failed,null," "))
if (failed.length > 0) {
fs.writeFileSync('tests.log', JSON.stringify(failed, null, ' '))
}
function capitalize(str) {
return str.charAt(0).toUpperCase()+str.slice(1)
function capitalize (str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc