#!/bin/bash
#########################################################
#                                                       #
# This is BashStyle-NG 7.3                              #
#                                                       #
# Licensed under GNU LESSER GENERAL PUBLIC LICENSE v3   #
#                                                       #
# Copyright 2007 - 2008 Christopher Bratusek            #
#                                                       #
#########################################################

smoothblue=$(bs-ng-parse-echo $smoothblue)
white=$(bs-ng-parse-echo $white)
green=$(bs-ng-parse-echo $green)

_help()
{
	echo -e "${smoothblue}Possible Options:\
	\n\t${green} --cpu\t\t${white} Display CPU Model and Frequency\
	\n\t${green} --kernel\t${white} Display Kernel Version, Release and Machine\
	\n\t${green} --memory\t${white} Display Total, Free and Used RAM\
	\n\t${green} --partitions\t${white} Display Major, Minor, Blocks and Node for all Paritions\
	\n\t${green} --pci\t\t${white} Display Infos about all PCI Devices (and their kernel-module)\
	\n\t${green} --usb\t\t${white} Display Infos about all USB Devices (and their kernel-module)\
	\n\t${green} --bios\t\t${white} Display SMBIOS/DMI Informations\
	\n\t${green} --mounts\t${white} Display all mounted devices"
	tput sgr0
}

_cpu()
{
	echo -e "${smoothblue}CPU:\n" 
	echo -e "${green}Model:${white} $(grep "model name" /proc/cpuinfo | sed -e 's/.*: //g')"
	echo -e "${green}MHz  :${white} $(grep "cpu MHz" /proc/cpuinfo | sed -e 's/.*: //g')\n"
	tput sgr0
}

_kernel()
{
	echo -e "${smoothblue}Kernel:\n"
	echo -e "${green}Release:${white} $(uname -r)"
	echo -e "${green}Version:${white} $(uname -v)"
	echo -e "${green}Machine:${white} $(uname -m)\n"
	tput sgr0
}

_memory()
{
	echo -e "${smoothblue}RAM:\n"
	echo -e "${green}Total:${white} $(((`showmem --free`) + (`showmem --used`))) MB"
	echo -e "${green}Free :${white} $(showmem --free) MB"
	echo -e "${green}Used :${white} $(showmem --used) MB\n"
	tput sgr0
}

_partitions()
{
	echo -e "${smoothblue}Partitions:${green}\n"
	echo -e "major minor blocks device-node ${white}\
	\n$(cat /proc/partitions | sed -e '1,2d')" | column -t
	echo ""
	tput sgr0
}

_pci()
{
	echo -e "${smoothblue}PCI Devices:\n${white}"
	lspci -vkmm
	echo ""
	tput sgr0
}

_usb()
{
	echo -e "${smoothblue}USB Devices:\n${white}"
	lsusb -v
	echo ""
	tput sgr0
}

_mounts()
{
	echo -e "${smoothblue}Mounts:\n${green}\
	\ndevice-node on mount-point type filesystem options\n" ${white} "\n\n$(mount)" | column -t
	echo ""
	tput sgr0
}

_bios()
{
	if [[ $EUID != 0 ]]; then
		echo -e "How to auth as root? (sudo or su)\n"
		read auth

		if [[ $auth == sudo ]]; then
			echo -e "${smoothblue}SMBIOS/DMI Infos:${white}\n"
			sudo dmidecode -q
			tput sgr0
		elif [[ $auth == su ]]; then
			echo -e "${smoothblue}SMBIOS/DMI Infos:${white}\n"
			su -c "dmidecode -q"
			tput sgr0
		else	echo "wrong auth command"
		fi
	else	echo -e "${smoothblue}SMBIOS/DMI Infos:${white}\n"
		dmidecode -q
		tput sgr0
	fi
}

case $1 in
	*cpu*)
		_cpu
	;;

	*kernel*)
		_kernel
	;;

	*mem*)
		_memory
	;;

	*partitions*)
		_partitions
	;;

	*pci*)
		_pci
	;;

	*usb*)
		_usb
	;;

	*mounts*)
		_mounts
	;;

	*bios*)
		_bios
	;;

	*)
		_help
	;;
esac

