Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: getos @ 3.1.0 .. 3.1.1

index.js

@@ -5,7 +5,6 @@
var distros = require('./os.json')
var fs = require('fs')
var os = require('os')
-var path = require('path')
/**
* Begin definition of globals.
@@ -21,7 +20,7 @@
// Linux is a special case.
if (osName === 'linux') return getLinuxDistro(cb)
// Else, node's builtin is acceptable.
- return cb(null, {'os': osName})
+ return cb(null, { 'os': osName })
}
/**
@@ -121,7 +120,7 @@
* Loads a custom logic module to populate additional distribution information
*/
function customLogic (os, name, file, cb) {
- var logic = path.join(__dirname, 'logic/' + name + '.js')
+ var logic = './logic/' + name + '.js'
try { require(logic)(os, file, cb) } catch (e) { cb(null, os) }
}

logic/manjaro.js

@@ -0,0 +1,10 @@
+var releaseRegex = /distrib_release=(.*)/
+var codenameRegex = /distrib_codename=(.*)/
+
+module.exports = function ubuntuCustomLogic (os, file, cb) {
+ var codename = file.match(codenameRegex)
+ 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)
+}

os.json

@@ -3,12 +3,13 @@
"/etc/redhat-release" : ["RHEL","RHAS","Red Hat Linux","Scientific Linux","ScientificSL","ScientificCERNSLC","ScientificFermiLTS","ScientificSLF","Centos"],
"/etc/redhat_version" : ["RHEL","RHAS","Red Hat Linux","Scientific Linux","ScientificSL","ScientificCERNSLC","ScientificFermiLTS","ScientificSLF"],
"/etc/SuSE-release": ["SUSE Linux"],
- "/etc/lsb-release" : ["Ubuntu Linux","Chakra","IYCC","Linux Mint","elementary OS","Arch Linux"],
+ "/etc/lsb-release" : ["Ubuntu Linux","Chakra","IYCC","Linux Mint","elementary OS","Arch Linux","Manjaro Linux"],
"/etc/debian_version" : ["Debian"],
"/etc/debian_release" : ["Debian"],
+ "/etc/arch-release" : ["Arch Linux"],
"/etc/os-release": ["Raspbian"],
+ "/etc/NIXOS": ["NixOS"],
"/etc/annvix-release" : ["Annvix"],
- "/etc/arch-release" : ["Arch Linux"],
"/etc/arklinux-release" : ["Arklinux"],
"/etc/aurox-release" : ["Aurox Linux"],
"/etc/blackcat-release" : ["BlackCat"],

package.json

@@ -1,6 +1,6 @@
{
"name": "getos",
- "version": "3.1.0",
+ "version": "3.1.1",
"description": "Get the OS/Distribution name of the environment you are working on",
"main": "index.js",
"scripts": {
@@ -25,13 +25,13 @@
},
"homepage": "https://github.com/retrohacker/getos",
"devDependencies": {
- "cli-color": "1.2.0",
+ "cli-color": "1.4.0",
"execSync": "1.0.2",
- "standard": "^10.0.2",
- "tape": "4.8.0"
+ "standard": "^12.0.1",
+ "tape": "4.9.1"
},
"dependencies": {
- "async": "2.4.0"
+ "async": "2.6.1"
},
"contributors": [
{

tests/alpine/3.3/Dockerfile

@@ -0,0 +1,11 @@
+FROM alpine:3.3
+
+MAINTAINER David Routhieau "rootio@protonmail.com"
+
+RUN apk add --update --no-cache \
+ nodejs
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node", "test.js"]

tests/debian/7.3/Dockerfile

@@ -0,0 +1,20 @@
+FROM debian:7.3
+MAINTAINER William Blankenship <william.jblankenship@gmail.com>
+
+# Setup NodeSource Official PPA
+RUN apt-get update && \
+ apt-get install -y --force-yes \
+ curl \
+ apt-transport-https \
+ lsb-release \
+ build-essential \
+ python-all
+
+RUN curl -sL https://deb.nodesource.com/setup | bash -
+RUN apt-get update
+RUN apt-get install nodejs -y --force-yes
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node","test.js"]

tests/debian/7.4/Dockerfile

@@ -0,0 +1,20 @@
+FROM debian:7.4
+MAINTAINER William Blankenship <william.jblankenship@gmail.com>
+
+# Setup NodeSource Official PPA
+RUN apt-get update && \
+ apt-get install -y --force-yes \
+ curl \
+ apt-transport-https \
+ lsb-release \
+ build-essential \
+ python-all
+
+RUN curl -sL https://deb.nodesource.com/setup | bash -
+RUN apt-get update
+RUN apt-get install nodejs -y --force-yes
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node","test.js"]

tests/debian/7.5/Dockerfile

@@ -0,0 +1,20 @@
+FROM debian:7.5
+MAINTAINER William Blankenship <william.jblankenship@gmail.com>
+
+# Setup NodeSource Official PPA
+RUN apt-get update && \
+ apt-get install -y --force-yes \
+ curl \
+ apt-transport-https \
+ lsb-release \
+ build-essential \
+ python-all
+
+RUN curl -sL https://deb.nodesource.com/setup | bash -
+RUN apt-get update
+RUN apt-get install nodejs -y --force-yes
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node","test.js"]

tests/debian/7.6/Dockerfile

@@ -0,0 +1,20 @@
+FROM debian:7.6
+MAINTAINER William Blankenship <william.jblankenship@gmail.com>
+
+# Setup NodeSource Official PPA
+RUN apt-get update && \
+ apt-get install -y --force-yes \
+ curl \
+ apt-transport-https \
+ lsb-release \
+ build-essential \
+ python-all
+
+RUN curl -sL https://deb.nodesource.com/setup | bash -
+RUN apt-get update
+RUN apt-get install nodejs -y --force-yes
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node","test.js"]

tests/fedora/20/Dockerfile

@@ -0,0 +1,9 @@
+FROM fedora:20
+MAINTAINER William Blankenship <william.jblankenship@gmail.com>
+
+RUN yum install -y nodejs npm
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node","test.js"]

tests/mockdata.json

@@ -0,0 +1,22 @@
+[
+ { "desc": "OS X", "platform": "darwin", "expected": { "os": "darwin" } }
+, { "desc": "Windows", "platform": "win32", "expected": { "os": "win32" } }
+, { "desc": "Ubuntu 14.10", "platform": "linux", "file": { "/etc/lsb-release": "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=14.10\nDISTRIB_CODENAME=utopic\nDISTRIB_DESCRIPTION=\"Ubuntu 14.10\"\n" }, "expected": { "codename": "utopic", "dist": "Ubuntu Linux", "os": "linux", "release": "14.10" } }
+, { "desc": "Ubuntu 14.04", "platform": "linux", "file": { "/etc/lsb-release": "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=14.04\nDISTRIB_CODENAME=trusty\nDISTRIB_DESCRIPTION=\"Ubuntu 14.04.2 LTS\"\n" }, "expected": { "codename": "trusty", "dist": "Ubuntu Linux", "os": "linux", "release": "14.04" } }
+, { "desc": "Ubuntu 12.04", "platform": "linux", "file": { "/etc/lsb-release": "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=12.04\nDISTRIB_CODENAME=precise\nDISTRIB_DESCRIPTION=\"Ubuntu 12.04.5 LTS\"\n" }, "expected": { "codename": "precise", "dist": "Ubuntu Linux", "os": "linux", "release": "12.04" } }
+, { "desc": "Fedora 21", "platform": "linux", "file": { "/etc/fedora-release": "Fedora release 21 (Twenty One)\n" }, "expected": { "codename": "Twenty One", "dist": "Fedora", "os": "linux", "release": "21" } }
+, { "desc": "CentOS 5.11", "platform": "linux", "file": { "/etc/redhat-release": "CentOS release 5.11 (Final)\n" }, "expected": { "codename": "final", "dist": "Centos", "os": "linux", "release": "5.11" } }
+, { "desc": "Centos 6.6", "platform": "linux", "file": { "/etc/redhat-release": "CentOS release 6.6 (Final)\n" }, "expected": { "codename": "final", "dist": "Centos", "os": "linux", "release": "6.6" } }
+, { "desc": "Centos 7.1", "platform": "linux", "file": { "/etc/redhat-release": "CentOS Linux release 7.1.1503 (Core)\n" }, "expected": { "codename": "core", "dist": "Centos", "os": "linux", "release": "7.1.1503" } }
+, { "desc": "RHEL 6.5", "platform": "linux", "file": { "/etc/redhat-release": "Red Hat Enterprise Linux Server release 6.5 (Santiago)\n" }, "expected": { "codename": "santiago", "dist": "Red Hat Linux", "os": "linux", "release": "6.5" } }
+, { "desc": "RHEL 6.6", "platform": "linux", "file": { "/etc/redhat-release": "Red Hat Enterprise Linux Server release 6.6 (Santiago)\n" }, "expected": { "codename": "santiago", "dist": "Red Hat Linux", "os": "linux", "release": "6.6" } }
+, { "desc": "RHEL 7.0", "platform": "linux", "file": { "/etc/redhat-release": "Red Hat Enterprise Linux Server release 7.0 (Maipo)\n" }, "expected": { "codename": "maipo", "dist": "Red Hat Linux", "os": "linux", "release": "7.0" } }
+, { "desc": "SUSE Linux", "platform": "linux", "file": { "/etc/SuSE-release": "SUSE Linux Enterprise Server 11 (x86_64)\nVERSION = 11\nPATCHLEVEL = 4\n" }, "expected": { "dist": "SUSE Linux", "os": "linux", "release": "11" } }
+, { "desc": "Alpine Linux", "platform": "linux", "file": { "/etc/alpine-release": "3.3\n" }, "expected": { "dist": "Alpine Linux", "os": "linux", "release": "3.3" } }
+, { "desc": "Amazon Linux", "platform": "linux", "file": { "/etc/system-release": "Amazon Linux AMI release 2016.03"}, "expected": {"dist": "Amazon Linux", "os": "linux", "release": "2016.03"}}
+, { "desc": "Arch Linux", "platform": "linux", "file": { "/etc/lsb-release": "LSB_VERSION=1.4\nDISTRIB_ID=Arch\nDISTRIB_RELEASE=rolling\nDISTRIB_DESCRIPTION=\"Arch Linux\""}, "expected": {"dist": "Arch Linux", "os": "linux", "release": "rolling"}}
+, { "desc": "Linux Mint", "platform": "linux", "file": { "/etc/lsb-release": "DISTRIB_ID=LinuxMint\nDISTRIB_RELEASE=18\nDISTRIB_CODENAME=sarah\nDISTRIB_DESCRIPTION=\"Linux Mint 18 Sarah\""}, "expected": {"dist": "Linux Mint", "os": "linux", "codename": "sarah", "release": "18"}}
+, { "desc": "Raspbian 8", "platform": "linux", "file": { "/etc/os-release": "PRETTY_NAME=\"Raspbian GNU/Linux 8 (jessie)\"\nNAME=\"Raspbian GNU/Linux\"\nVERSION_ID=\"8\"\nVERSION=\"8 (jessie)\"\nID=raspbian\nHOME_URL=\"http://www.raspbian.org/\"\nSUPPORT_URL=\"http://www.raspbian.org/RaspbianForums\"\nBUG_REPORT_URL=\"http://www.raspbian.org/RaspbianBugs\"" }, "expected": { "codename": "jessie", "dist": "Raspbian", "os": "linux", "release": "8" } }
+, { "desc": "Manjaro Linux", "platform": "linux", "file": { "/etc/lsb-release": "DISTRIB_ID=ManjaroLinux\nDISTRIB_RELEASE=17.1.10\nDISTRIB_CODENAME=Hakoila\nDISTRIB_DESCRIPTION=\"Manjaro Linux\"" }, "expected": { "codename": "hakoila", "dist": "Manjaro Linux", "os": "linux", "release": "17.1.10" } }
+, { "desc": "NixOS", "platform": "linux", "file": { "/etc/NIXOS": " " }, "expected": { "dist": "NixOS", "os": "linux" } }
+]

tests/mocktests.js

@@ -0,0 +1,40 @@
+var test = require('tape')
+var fs = require('fs')
+var os = require('os')
+var mockdata = require('./mockdata')
+
+var currentData
+
+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.readFile = function (file, enc, callback) {
+ process.nextTick(function () {
+ if (!currentData.file[file]) { return callback(new Error()) }
+ callback(null, currentData.file[file])
+ })
+}
+
+mockdata.forEach(function (data) {
+ test('test ' + data.desc, function (t) {
+ // reload each time to avoid internal caching
+ require.cache[require.resolve('../')] = null
+ var getos = require('../')
+
+ currentData = data
+
+ getos(function (err, os) {
+ t.error(err, 'no error')
+ t.deepEqual(os, data.expected, 'correct os data')
+ t.end()
+ })
+ })
+})

tests/runTest.js

@@ -0,0 +1,79 @@
+var color = require('cli-color')
+var execSync = require('child_process').execSync || require('execSync').exec
+var fs = require('fs')
+var path = require('path')
+
+/**
+ * So most of this stuff will be sync, because we are moving
+ * files around building docker images, etc. These all have
+ * to be done in a specific order or chaos ensues
+ */
+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) + '... ')
+ try {
+ var dockerResult = execSync('docker build -t "getos:' + v1 + v2 + '" .', { stdio: [] })
+ } catch (e) {
+ dockerResult = dockerResult || {}
+ dockerResult.code = e
+ }
+ if (dockerResult.code && dockerResult.code !== 0) {
+ failed.push(dockerResult)
+ process.stdout.write('[' + color.red('FAILED!') + ']\n')
+ } else {
+ 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: [] })
+ } catch (e) {
+ nodeResult = nodeResult || {}
+ nodeResult.code = e
+ }
+ if (nodeResult.code && nodeResult.code !== 0) {
+ failed.push(nodeResult)
+ process.stdout.write('[' + color.red('FAILED!') + ']\n')
+ } else {
+ try {
+ var dockerLog = execSync('sleep 2s && docker logs ' + (nodeResult.stdout || nodeResult.toString()), { stdio: [] })
+ } catch (e) {
+ dockerLog = dockerLog || {}
+ dockerLog.code = e
+ }
+ if (dockerLog.code && dockerLog.code !== 0) {
+ failed.push(dockerLog)
+ 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())
+ }
+ }
+ }
+ // Delete the dockerfile
+ fs.unlinkSync(path.join(process.cwd(), 'Dockerfile'))
+ })
+})
+
+if (failed.length > 0) {
+ fs.writeFileSync('tests.log', JSON.stringify(failed, null, ' '))
+}
+
+function capitalize (str) {
+ return str.charAt(0).toUpperCase() + str.slice(1)
+}

tests/ubuntu/13.10/Dockerfile

@@ -0,0 +1,18 @@
+FROM ubuntu:13.10
+
+RUN apt-get update && \
+ apt-get install -y --force-yes \
+ curl \
+ apt-transport-https \
+ lsb-release \
+ build-essential \
+ python-all
+
+RUN curl -sL https://deb.nodesource.com/setup | bash -
+RUN apt-get update
+RUN apt-get install nodejs -y --force-yes
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node","test.js"]

tests/ubuntu/14.04/Dockerfile

@@ -0,0 +1,18 @@
+FROM ubuntu:14.04
+
+RUN apt-get update && \
+ apt-get install -y --force-yes \
+ curl \
+ apt-transport-https \
+ lsb-release \
+ build-essential \
+ python-all
+
+RUN curl -sL https://deb.nodesource.com/setup | bash -
+RUN apt-get update
+RUN apt-get install nodejs -y --force-yes
+
+ADD . /usr/src/
+WORKDIR /usr/src/
+
+CMD ["node","test.js"]