#!/bin/sh

PROCESSORS=`ruby -e "text = File.read('/proc/cpuinfo')
infos = text.split('processor')
infos.shift

cores = infos.map do |inf|
	{ :vendor => inf.grep(/vendor_id/)[0].to_s.gsub(/^vendor_id.*: /, '').chomp,
	:model => inf.grep(/model name/)[0].to_s.gsub(/^model name.*: /, '').chomp,
	:core_id => inf.grep(/core id/)[0].to_s.gsub(/^core id.*: /, '').chomp.to_i }
end

processors = cores.select{ |c| c[:core_id] == 0 }.map do |c|
	\"CPU_VENDOR='#{c[:vendor]}'; CPU_MODEL='#{c[:model]}'\"
end

processors.each{ |p| puts p }"`

echo "$PROCESSORS" | while read I; do
	eval "$I"
	CPU_VENDOR=`echo "$CPU_VENDOR" | sed 's/^vendor: \([^;]*\);.*$/\1/' | sed 's/Genuine//g;s/Authentic//g;'`
	CPU_MODEL=`echo "$CPU_MODEL" | sed 's/^.*model: \([^;]*\);.*$/\1/' | sed 's/(R)//g;s/(tm)//g;s/processor//ig;s/CPU//g;s/Intel//g;s/AMD//g;s/Genuine/Core Solo/;s/@ //;s/  */ /g;s/^ *//g;'`
	$SHARE_DIR/add-component CPU "$CPU_VENDOR" "$CPU_MODEL" ''	
done
