Class: Hwid::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hwid/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#systemidObject

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_idObject



77
78
79
80
81
82
# File 'lib/hwid/base.rb', line 77

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_idObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/hwid/base.rb', line 64

def get_linuxdebian_id
  res="Serial: unknown"
  # lshw -quiet -class cpu -disable usb -disable network -disable pci -disable cpuinfo -disable dmi -disable memory -disable isapnp -disable ide -disable device-tree -disable spd | grep -oP '(serial: )\K.*
  # res=run_cmd("lshw -quiet -class cpu -disable usb -disable network -disable pci -disable cpuinfo -disable dmi -disable memory -disable isapnp -disable ide -disable device-tree -disable spd | grep -oP '(serial: )\\K.*'")
  res=run_cmd("lshw -quiet -class cpu -class network -disable usb -disable pci -disable cpuinfo -disable dmi -disable memory -disable isapnp -disable ide -disable device-tree -disable spd | grep -oP '(serial: )\\K.*'")
  res=res.gsub("0000-","")
  res=res.gsub("\n","")
  #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_idObject



60
61
62
63
# File 'lib/hwid/base.rb', line 60

def get_mac_id
  res=run_cmd('/usr/sbin/system_profiler SPHardwareDataType -timeout 0 | grep Serial')
  self.parse(res)
end

#get_platformObject

returns array of platforms



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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 << "ubuntu" if  `uname -a`.include?('Ubuntu')
  platform << "linux" if (/linux/ =~ RUBY_PLATFORM) != nil
  platform
end

#get_rasp_idObject



56
57
58
59
# File 'lib/hwid/base.rb', line 56

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

#platformObject



13
14
# File 'lib/hwid/base.rb', line 13

def platform
end

#run_cmd(cmd) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/hwid/base.rb', line 47

def run_cmd(cmd)
  res=""
  begin
    res=`#{cmd}`
  rescue Exception => e
    res="Serial: unknown"
  end
  res
end