Class: Hwid::Base
- Inherits:
-
Object
- Object
- Hwid::Base
- Defined in:
- lib/hwid/base.rb
Instance Attribute Summary collapse
-
#systemid ⇒ Object
Returns the value of attribute systemid.
Instance Method Summary collapse
- #get_linux_id ⇒ Object
- #get_linuxdebian_id ⇒ Object
- #get_mac_id ⇒ Object
-
#get_platform ⇒ Object
returns array of platforms.
- #get_rasp_id ⇒ Object
-
#parse(line) ⇒ Object
parse something like ‘Serial : xxxx’.
- #platform ⇒ Object
- #run_cmd(cmd) ⇒ Object
Instance Attribute Details
#systemid ⇒ Object
Returns the value of attribute systemid.
11 12 13 |
# File 'lib/hwid/base.rb', line 11 def systemid @systemid end |
Instance Method Details
#get_linux_id ⇒ Object
70 71 72 73 74 75 |
# File 'lib/hwid/base.rb', line 70 def get_linux_id res="Serial: unknown" ifconfig_avail = !(ifconfig_path = `which ifconfig`.strip).empty? && File.executable?(ifconfig_path) res=run_cmd('ifconfig | grep HWaddr').split.last if ifconfig_avail res end |
#get_linuxdebian_id ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/hwid/base.rb', line 62 def get_linuxdebian_id res="Serial: unknown" res=run_cmd("lshw | grep -A 10 '*-cpu' | grep -oP '(serial: )\\K.*'") puts "Interim result is #{res.inspect}" res=res.chomp puts "debian command result: #{res}" res end |
#get_mac_id ⇒ Object
58 59 60 61 |
# File 'lib/hwid/base.rb', line 58 def get_mac_id res=run_cmd('/usr/sbin/system_profiler SPHardwareDataType -timeout 0 | grep Serial') self.parse(res) end |
#get_platform ⇒ Object
returns array of platforms
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hwid/base.rb', line 23 def get_platform platform=[] platform << "raspberry" if (/arm-linux/ =~ RUBY_PLATFORM) != nil and `uname -a`.include?('armv6') platform << "raspberry" if `uname -a`.include?('armv6') platform << "raspberry 2" if (/armv7l-linux/ =~ RUBY_PLATFORM) != nil and !`uname -a`.include?('armv6') platform << "mac" if (/darwin/ =~ RUBY_PLATFORM) != nil platform << "arm" if (/arm/ =~ RUBY_PLATFORM) != nil platform << "x86" if (/x86/ =~ RUBY_PLATFORM) != nil platform << "i686" if (/i686/ =~ RUBY_PLATFORM) != nil platform << "debian" if `uname -a`.include?('Debian') platform << "linux" if (/linux/ =~ RUBY_PLATFORM) != nil platform end |
#get_rasp_id ⇒ Object
54 55 56 57 |
# File 'lib/hwid/base.rb', line 54 def get_rasp_id res=run_cmd('grep Serial /proc/cpuinfo') self.parse(res) end |
#parse(line) ⇒ Object
parse something like ‘Serial : xxxx’
16 17 18 19 20 21 |
# File 'lib/hwid/base.rb', line 16 def parse(line) res='unknown' raw=line.split(':') res=raw[1] if raw[1]!=nil res.strip end |
#platform ⇒ Object
13 14 |
# File 'lib/hwid/base.rb', line 13 def platform end |
#run_cmd(cmd) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/hwid/base.rb', line 45 def run_cmd(cmd) res="" begin res=`#{cmd}` rescue Exception => e res="Serial: unknown" end res end |