Coder Social home page Coder Social logo

getos's Introduction

getos

Greenkeeper badge

getos

Build Status

NPMNPM

JavaScript Style Guide

Get the OS/Distribution name of the environment you are working on

Problem

os.platform() returns linux. If you want the distrubtion name, you're out of luck.

Solution

This. Simply call:

var getos = require('getos')

getos(function(e,os) {
  if(e) return console.log(e)
  console.log("Your OS is:" +JSON.stringify(os))
})

The os object conforms to:

{
  os: [OS NAME],
  dist:[DIST NAME],
  codename:[CODENAME],
  release:[VERSION]
}

For example:

{
  os: "linux",
  dist: "Ubuntu",
  codename: "precise",
  release: "12.04"
}

Disclaimer

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.

If you have a distrubtion not in os.json, please identify your resource file and submit it's name and content along with your distrbution/version in an issue.

Thanks for helping make this tool great.

Unit Tests

Unit tests stub out the behaviour of the OS files and libraries we depend on to ensure the behaviour of the application is sound. You can run these simply by running npm test

Authors and Contributors

getos has been made possible by these fantastic contributors:

Benjamin E. CoeGitHub/bcoeTwitter/@benjamincoe
Eugene SharyginGitHub/eush77Twitter/@eush77
David RouthieauGitHub/root-iounknown
LawrenceGitHub/mindmeltingTwitter/@mindmelting
Roman JurkovGitHub/winfinitTwitter/@winfinit
Rod VaggGitHub/rvaggTwitter/@rvagg
Zeke SikelianosGitHub/zekeTwitter/@zeke
AlexanderGitHub/alex4ZeroTwitter/@alex4Zero

getos's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

getos's Issues

fix up outdated README.md

  • README.md should be updated to reflect the fact that getos now detects release information.
  • we should also document the fact that getos now accepts a callback.

Unable to bundle getos using webpack

Thanks for this awesome package.
Currently we're using it in our Python Extension for VS Code.

The following line of code doesn't make it easy to bundle getos using webpack.

getos/index.js

Line 124 in a536ba7

var logic = path.join(__dirname, 'logic/' + name + '.js')

The simple fix is to remove __dirname, that's quite unnecessary, as resolve will start from the current directory when using relative paths as follows require('./local/xyz.js').

For now we've crated a separate webpack loader that makes this change to allow bundling this.

I'm hoping we can remove __dirname and just use var logic = './logic/' + name + '.js'; instead.

What is the license?

I am confused what is the license for this module, in package.json it says ISC but in the readme it says MIT.

Usually adding a LICENSE file to the repo is the standard, it will be great if you can do that so I can use your module.

Add linting

#50 reveals we have a lot to do in the way of linting and enforcing style. Would like to adopt a strict style guide, I'm a fan of AirBnB. What we settle on should support Node.js v4 and greater.

This would officially drop support for versions of Node.js < v4, requiring a major version bump.

Archlinx bad recognized

Contente of /etc/arch-release : empty

Contente of /etc/os-release :

NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
ID_LIKE=archlinux
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"

I use kernel : 4.9.21-1-lts

It indicate me Linux Mint

Need Amazon Linux AMI 2016.03.0 support

Default OS for AWS ElasticBeansTalk is Amazon Linux AMI 2016.03.0. Assume it will be great if getos will support it. Right now it is not possible to deploy packages which have dependencies from getos

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Failed to loads a custom logic module in packaged project

I have packaged my application with https://github.com/zeit/pkg and find that custom logic for detection of linux distributive version cannot be loaded because have incorrect path (https://github.com/zeit/pkg#snapshot-filesystem)

It is possible to replace this path from try { require('./logic/' + name + '.js')(os, file, cb) } catch (e) { cb(null, os) } to try { require(__dirname + '/logic/' + name + '.js')(os, file, cb) } catch (e) { cb(null, os) }

Getting undefined release version in GitHub Action running Ubuntu

Hi!

I'm having trouble getting getos to work in a GitHub action.
It have been working in the past (was some time ago since I checked) but now the release is undefined. (The result is {"os":"linux","dist":"Ubuntu"})

Got the following from /etc/lsb-release:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"

Also checked /etc/os-release:

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Ubuntu 14.04 not detected on Digital Ocean Server

On EC2 instances, getos is working great. When I run getos on an Ubuntu 14.04 AMI I get:

{ os: 'linux',
  dist: 'Ubuntu Linux',
  codename: 'trusty',
  release: '14.04' }

However, on a DigitalOcean Trusty image, seems to fail to detect the distribution.

Alpine linux support

> [email protected] postinstall /myproject/node_modules/mongodb-prebuilt
> node install.js

/myproject/node_modules/mongodb-download/index.js:80
                throw e;
                ^

Error: No unique release file found!
    at /myproject/node_modules/getos/index.js:136:21
    at FSReqWrap.oncomplete (fs.js:82:15)

I guess Alpine linux is not yet supported ? :p (related to #16)

Get release name/version

First off, awesome library. This is exactly what I was looking for for the installer I'm working on for npm Enterprise.

One thing I'd love, would to be able to detect the release version/name of the OS I'm on, e.g.,

{
  os: 'ubuntu',
  name: 'Trusty',
  version: '14.04'
}

What if the values in os.json were optionally a filename/set-of-regexs rather than just a filename? The regexes could be used to detect release name on the given platform (if possible).

Support Release version in Linux Mint

Currently from Linux Mint 19, if i use getos it returns the following output:

{ "os": "linux", "dist": "Linux Mint" }

I would like the library to also return the release number, if it is possible. Thanks!

Improve support for NixOS

In NixOS, there is a /etc/os-release file which contains something like:

NAME=NixOS
ID=nixos
VERSION="20.09.git.54408d8707e (Nightingale)"
VERSION_CODENAME=nightingale
VERSION_ID="20.09.git.54408d8707e"
PRETTY_NAME="NixOS 20.09 (Nightingale)"
LOGO="nix-snowflake"
HOME_URL="https://nixos.org/"
DOCUMENTATION_URL="https://nixos.org/nixos/manual/index.html"
SUPPORT_URL="https://nixos.org/nixos/support.html"
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"

Support for KDE neon

I'm using KDE neon which is based on Ubuntu. When I use getos, it returns the following without codename and release fields.

Your OS is:{"os":"linux","dist":"Ubuntu Linux"}

This is the content of the lsb-release file:

DISTRIB_ID=neon
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="KDE neon User Edition 5.16"

And just wondering if it matters, this is the content of the os-release file:

NAME="KDE neon"
VERSION="5.16"
ID=neon
ID_LIKE="ubuntu debian"
PRETTY_NAME="KDE neon User Edition 5.16"
VARIANT="User Edition"
VERSION_ID="18.04"
HOME_URL="http://neon.kde.org/"
SUPPORT_URL="http://neon.kde.org/"
BUG_REPORT_URL="http://bugs.kde.org/"
LOGO=start-here-kde-neon
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

FWIW, I found out this issue when I was trying to get mongodb-memory-server running on my machine - it couldn't get the release version number of my KDE neon OS, and assume and download the wrong mongo binary file.

Arch Linux shows up as "Raspbian"

I'm running arch linux and the dist property is returning "Raspbian" when it should be returning "Arch Linux". This needs to be fixed.

Incorrectly identifies Alpine Linux as Raspbian

According to https://github.com/retrohacker/getos/blob/master/os.json#L9 only Raspbian can have the os-release file. Therefore when this file is encountered this https://github.com/retrohacker/getos/blob/master/index.js#L62 assumes that since no other distro has been listed the disto has to be Raspbian.

Content of said os-release file:

NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.6.2
PRETTY_NAME="Alpine Linux v3.6"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"

Would it be wiser to check lsb_release first?

It may be good to try lsb_release before looking in files.

eg from ubuntu

root@buildbox01:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty

Just a thought.

An in-range update of tape is breaking the build 🚨

The devDependency tape was updated from 4.11.0 to 4.12.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 9 commits.

  • 42c84d6 v4.12.0
  • 3e0a341 [Deps] update is-regex, string.prototype.trim
  • ba7e2b2 [Dev Deps] update eslint
  • f3a5925 [Tests] use shared travis-ci configs
  • 6e94800 [Deps] update deep-equal, glob, object-inspect, resolve, string.prototype.trim
  • 8150c3b [Refactor] use is-regex instead of instanceof RegExp
  • 24487cb add tap-nyc to pretty-reporters
  • c283615 [New] when the error type is wrong, show the message and stack
  • 44cbbf5 [Tests] add a test for the wrong kind of error

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Linux distro detection mechanism should be aligned with modern approach

Most of modern linux based distro use /etc/os-release only file and do not include lsb or distro specific files, which is the getos using.

As a result the getos incorrectly detects distro as Raspbian for Ubuntu, openSUSE Tumbleweed and Leap, etc.

The os-release file already have NAME or ID variables for that purpose, for example, observe os-release for Leap:

NAME="openSUSE Leap"
VERSION="15.3"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.3"
PRETTY_NAME="openSUSE Leap 15.3"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.3"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"

or Tumbleweed

NAME="openSUSE Tumbleweed"
# VERSION="20210626"
ID="opensuse-tumbleweed"
ID_LIKE="opensuse suse"
VERSION_ID="20210626"
PRETTY_NAME="openSUSE Tumbleweed"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:tumbleweed:20210626"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
DOCUMENTATION_URL="https://en.opensuse.org/Portal:Tumbleweed"
LOGO="distributor-logo"

or Ubuntu:

NAME="Ubuntu"
VERSION="20.10 (Groovy Gorilla)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.10"
VERSION_ID="20.10"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=groovy
UBUNTU_CODENAME=groovy

or Centos:

NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"

and Raspbian:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

For more details read: https://www.linux.org/docs/man5/os-release.html

Windows support?

I tried using Windows 10 Pro on a 64 bit machine.
{"os": "win32"} was returned.
Looking in the README.md and other files, it is not obvious if Windows is and/or will be supported.
If Windows is to be supported please fix the response above and state support for Windows, if not please state which OS range this is for. Regards.

fedora is not detected due to redhat link presence

Fedora for some backwards compatibility, includes /etc/redhat-release, which is causing this module to parse fedora as redhat.

[osboxes@osboxes getos]$ ls -lah /etc/*release
-rw-r--r--. 1 root root 31 May 19  2015 /etc/fedora-release
lrwxrwxrwx. 1 root root 21 May 19  2015 /etc/os-release -> ../usr/lib/os-release
lrwxrwxrwx. 1 root root 14 May 19  2015 /etc/redhat-release -> fedora-release
lrwxrwxrwx. 1 root root 14 May 19  2015 /etc/system-release -> fedora-release

due to structure of os.json, it is picking up RHEL first:

{ os: 'linux', dist: 'RHEL' }

if we move fedora to the top, which i think is safe, because no other release that i know of does this, the fedora would be reported correctly:

{"os":"linux","dist":"Fedora","release":"22","codename":"Twenty Two"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.