sherlock_os 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ .#*
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,5 @@
1
+ -
2
+ README.md
3
+ version.txt
4
+ LICENSE.txt
5
+ --asset it_s_unix_my_dear_watson.png:it_s_unix_my_dear_watson.png:
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sherlock_os.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dmytro Kovalov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,112 @@
1
+
2
+ ![](it_s_unix_my_dear_watson.png)
3
+ # Name: Sherlock OS
4
+
5
+ This is a simple shell script to detect UNIX/Linux OS and various aspects of the OS. Especially for Linux: distribution type and derivative (such as CentOS/RHEL or Debian/Ubuntu)
6
+
7
+
8
+ Used these sources to start:
9
+
10
+ - http://www.novell.com/coolsolutions/feature/11251.html
11
+ - http://serverfault.com/questions/3331/how-do-i-find-out-what-version-of-linux-is-running
12
+ - http://www.unix.com/slackware/23652-determine-linux-version.html
13
+
14
+ Script outputs results in the format that can either be parsed or directly eval'ed in Bourne shell:
15
+
16
+ Example
17
+ -----------
18
+
19
+ ```
20
+ $ sherlock
21
+ OS=Linux
22
+ MACH=x86_64
23
+ KERNEL=2.6.32-5-amd64
24
+ DISTRIBUTION=debian
25
+ FAMILY=debian
26
+ DERIVATIVE=Debian
27
+ RELEASE=6.0.6
28
+ CODENAME=squeeze
29
+ ```
30
+
31
+ ## Installation
32
+
33
+
34
+ Sherlock OS is just single file shell script. It can be installed and used from any location, but to make distribution for Ruby programmer (i.e. for me) easier it is packaged as gem.
35
+
36
+ Install it yourself as:
37
+
38
+ $ gem install sherlock_os
39
+
40
+ If you don't need gem, then simply grab the file from https://github.com/dmytro/sherlock_os/blob/master/bin/sherlock and put in anywhere you want to use it.
41
+
42
+ ## Usage
43
+
44
+ Simply run `sherlock` and examine output or use it in shell scripts as eval:
45
+
46
+ ```
47
+ eval `sherlock`
48
+ ```
49
+
50
+ ### Output
51
+
52
+ Various OS supported to various degrees, YMMV.
53
+
54
+ These are just examples of output on some OS's I have access to at the time of writing:
55
+
56
+ #### MacOSX (Darwin)
57
+
58
+ ```
59
+ OS=Darwin
60
+ MACH=x86_64
61
+ REV=11.4.2
62
+ ```
63
+
64
+ #### CentOS
65
+
66
+ ```
67
+ OS=Linux
68
+ MACH=x86_64
69
+ KERNEL=2.6.18-308.11.1.el5xen
70
+ DISTRIBUTION=redhat
71
+ FAMILY=rh
72
+ DERIVATIVE=centos
73
+ RELEASE=5.8
74
+ ```
75
+
76
+ #### Debian
77
+
78
+ ```
79
+ OS=Linux
80
+ MACH=x86_64
81
+ KERNEL=2.6.32-5-amd64
82
+ DISTRIBUTION=debian
83
+ FAMILY=debian
84
+ DERIVATIVE=Debian
85
+ RELEASE=6.0.6
86
+ CODENAME=squeeze
87
+ ```
88
+
89
+ #### Ubuntu
90
+
91
+ ```
92
+ OS=Linux
93
+ MACH=i686
94
+ KERNEL=3.2.0-23-generic-pae
95
+ DISTRIBUTION=debian
96
+ FAMILY=debian
97
+ DERIVATIVE=Ubuntu
98
+ RELEASE=12.04
99
+ CODENAME=precise
100
+ ```
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it
105
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
106
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
107
+ 4. Push to the branch (`git push origin my-new-feature`)
108
+ 5. Create new Pull Request
109
+
110
+ # Author
111
+
112
+ Dmytro Kovalov, 2013, March 12-13
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,141 @@
1
+ #!/bin/sh
2
+ #
3
+ # Script to detect UNIX/Linux OS and varios aspects of the
4
+ # OS. Especially for Linux: distribution type and derivarite (such as
5
+ # CentOS/RHEL or Debian/Ubuntu)
6
+ #
7
+ # Author: Dmytro Kovalov, 2013, March 12-13
8
+ #
9
+ # Used these sources to start:
10
+ # http://www.novell.com/coolsolutions/feature/11251.html
11
+ # http://serverfault.com/questions/3331/how-do-i-find-out-what-version-of-linux-is-running
12
+ # http://www.unix.com/slackware/23652-determine-linux-version.html
13
+ #
14
+ # Script outputs results in the format that can either be parsed or
15
+ # directly eval'ed in Bourne shell:
16
+ #
17
+ # Example
18
+ # -----------
19
+ # sherlock
20
+ # OS=Linux
21
+ # MACH=x86_64
22
+ # KERNEL=2.6.32-5-amd64
23
+ # DISTRIBUTION=debian
24
+ # FAMILY=debian
25
+ # DERIVATIVE=Debian
26
+ # RELEASE=6.0.6
27
+ # CODENAME=squeeze
28
+ #
29
+
30
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin
31
+
32
+ ####################################################################
33
+ # Functions
34
+ #
35
+
36
+ ##
37
+ # Main function that call all others
38
+ #
39
+ detect_os () {
40
+
41
+ OS=`uname -s`
42
+ MACH=`uname -m`
43
+
44
+ echo OS=$OS
45
+ echo MACH=$MACH
46
+
47
+ if [ "${OS}" = "SunOS" ] ; then
48
+ echo ARCH=`uname -p`
49
+ OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
50
+ elif [ "${OS}" = "AIX" ] ; then
51
+ echo OSSTR="${OS} `oslevel` (`oslevel -r`)"
52
+ elif [ "${OS}" = "Darwin" ] ; then
53
+ echo REV=`uname -r`
54
+ elif [ "${OS}" = "Linux" ] ; then
55
+ echo KERNEL="`uname -r`"
56
+ linux_distro
57
+ fi
58
+ }
59
+
60
+
61
+
62
+ ## ------------------------------------------------------------
63
+ # Redhat derivatives distros
64
+ #
65
+ redhat_derivative () {
66
+
67
+ local FILE=/etc/redhat-release
68
+
69
+ grep -i 'red.*hat.*enterprise.*linux' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=rhel; return; }
70
+ grep -i 'red.*hat.*linux' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=rh; return; }
71
+ grep -i 'cern.*e.*linux' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=cel; return; }
72
+ grep -i 'scientific linux cern' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=slc; return; }
73
+ grep -i 'centos' $FILE 2>&1 > /dev/null && { echo DERIVATIVE=centos; return; }
74
+
75
+ echo DERIVATIVE=unknown
76
+ }
77
+
78
+
79
+ redhat_release () {
80
+ echo RELEASE=`tr -d 'a-zA-Z [](){}' < /etc/redhat-release`
81
+ }
82
+
83
+ ## ------------------------------------------------------------
84
+ # Debian derivatives
85
+ #
86
+ debian_derivative () {
87
+ if which lsb_release 2>&1 > /dev/null ; then
88
+ echo DERIVATIVE=`lsb_release --id --short 2> /dev/null`
89
+ echo RELEASE=`lsb_release --release --short 2> /dev/null`
90
+ echo CODENAME=`lsb_release --codename --short 2> /dev/null`
91
+ return
92
+ else
93
+ echo RELEASE=`cat /etc/debian_version`
94
+ return
95
+ fi
96
+ }
97
+
98
+ ##
99
+ #
100
+ #
101
+ linux_distro () {
102
+
103
+ if [ -f /etc/redhat-release ] ; then
104
+ echo DISTRIBUTION=redhat
105
+ echo FAMILY=rh
106
+ redhat_derivative
107
+ redhat_release
108
+ elif [ -s /etc/slackware-version ]; then
109
+ echo DISTRIBUTION="slackware"
110
+ elif [ -f /etc/SUSE-release ] ; then
111
+ # TODO - not tested
112
+ echo DISTRIBUTION=suse
113
+ echo PSUEDONAME=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
114
+ echo REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
115
+ echo VERSION=`cat /etc/SuSE-release | grep 'VERSION' | sed -e 's#[^0-9]##g'`
116
+ elif [ -f /etc/mandrake-release ] ; then
117
+ # TODO - not tested
118
+ echo DISTRIBUTION=mandrake
119
+ echo PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
120
+ echo REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
121
+ echo FAMILY=rh
122
+ elif [ -f /etc/debian_version ] ; then
123
+ echo DISTRIBUTION=debian
124
+ echo FAMILY=debian
125
+ debian_derivative
126
+ elif [ -f /etc/UnitedLinux-release ]; then
127
+ echo DISTRIBUTION="united"
128
+ echo VERSION=`cat /etc/UnitedLinux-release`
129
+ elif [ -r /etc/init.d/functions.sh ]; then
130
+ # TODO - not tested
131
+ source /etc/init.d/functions.sh
132
+ [ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && echo DISTRIBUTION="gentoo"
133
+ fi
134
+ }
135
+
136
+ # --------------------------------------------------------------------------------
137
+ # Do it!
138
+ #
139
+ detect_os
140
+
141
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ path = Gem.bin_path('sherlock_os', 'sherlock')
4
+
5
+ path = File.dirname(File.dirname(path))
6
+
7
+ print %x{ #{path}/bin/sherlock 2>&1 }
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.name = "sherlock_os"
4
+ gem.version = File.read('version.txt').chomp.strip
5
+ gem.authors = ["Dmytro Kovalov"]
6
+ gem.email = ["dmytro.kovalov@gmail.com"]
7
+ gem.description = %q{Shell script to detect UNIX/Linux OS name, version and aspects of the OS}
8
+ gem.summary = %q{Shell script to detect UNIX/Linux OS name, version and varios aspects of the OS. Especially for Linux: distribution type and derivarite (such as CentOS/RHEL or Debian/Ubuntu)}
9
+ gem.homepage = "http://dmytro.github.com"
10
+
11
+ gem.files = `git ls-files`.split($/)
12
+
13
+ gem.bindir = 'ruby_bin'
14
+ gem.executables = ['sherlock']
15
+ gem.default_executable = 'sherlock'
16
+
17
+ end
@@ -0,0 +1 @@
1
+ 0.0.2
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sherlock_os
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmytro Kovalov
9
+ autorequire:
10
+ bindir: ruby_bin
11
+ cert_chain: []
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Shell script to detect UNIX/Linux OS name, version and aspects of the
15
+ OS
16
+ email:
17
+ - dmytro.kovalov@gmail.com
18
+ executables:
19
+ - sherlock
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - .yardopts
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/sherlock
30
+ - it_s_unix_my_dear_watson.png
31
+ - ruby_bin/sherlock
32
+ - sherlock_os.gemspec
33
+ - version.txt
34
+ homepage: http://dmytro.github.com
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.8.25
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: ! 'Shell script to detect UNIX/Linux OS name, version and varios aspects
58
+ of the OS. Especially for Linux: distribution type and derivarite (such as CentOS/RHEL
59
+ or Debian/Ubuntu)'
60
+ test_files: []
61
+ has_rdoc: