#!/bin/bash
#
# sp_system_hwinfo
#
# (c) 2013 SUSE Linux GmbH, Germany.
# GNU Public License. No warranty.
#
# Version: 2013-09-09
#

EXE=$(basename $0)
LOG="/var/log/$EXE.log"
ERR=/dev/null
PWD=${2:-"suse1234"}

CFG="/etc/sysconfig/spock"
test -s $CFG && source $CFG

test -z "${SPCMD_USER}" && SPCMD_USER="admin"
test -z "${SPCMD_PASS}" && SPCMD_PASS="${PWD}"


function help() {
	echo "usage:	$(basename $0) OPTION <passwd>"
	echo
	echo "show basic hardware info for client systems"
	echo
	echo " --show		show hw info"
	echo " --version	show version"
	echo " --help		show help"
	echo
}


function do_list() {

 SYST_LIST=$(spacecmd -u $SPCMD_USER -p $SPCMD_PASS system_list 2>>$ERR)

 echo "==="
 for s in $SYST_LIST; do
	echo "hostname: " $s
	spacecmd -u $SPCMD_USER -p $SPCMD_PASS system_listhardware $s 2>>$ERR |\
	awk -F ":" '$1=="Count"||$1=="Model" {print $0}
		$1=="RAM"||$1=="Swap" {print $0}
		$1=="board"||$1=="system"||$1=="BIOS Release" {print $0}
		$1=="System" {print $0}
 #		TODO MACs last $1=="MAC Address"||$1=="Interface" {print $0}
	'
	echo "==="
 done
}


# main()
case $1 in
 # TODO -c|--csv
 -s|--show)
	# TODO 3rd and more args are fqdn for systems to show 
	do_list
 ;;
 -v|--version)
	echo -n "$(basename $EXE) "
	head -11 $EXE | grep "^# Version: "
 ;;
 *)
	help
 ;;
esac
#
