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

white=$(bs-ng-parse-echo $white)
orange=$(bs-ng-parse-echo $orange)
iceblue=$(bs-ng-parse-echo $iceblue)

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

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

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

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

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

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

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

_mounts()
{
	echo -e "${white}Mounts:\n${orange}\
	\ndevice-node on mount-point type filesystem options\n" ${iceblue} "\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 "${white}SMBIOS/DMI Infos:${iceblue}\n"
			sudo dmidecode -q
			tput sgr0
		elif [[ $auth == su ]]; then
			echo -e "${white}SMBIOS/DMI Infos:${iceblue}\n"
			su -c "dmidecode -q"
			tput sgr0
		else	echo "wrong auth command"
		fi
	else	echo -e "${white}SMBIOS/DMI Infos:${iceblue}\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
	;;

	*all*)
		_cpu
		_kernel
		_memory
		_partitions
		_pci
		_usb
		_mounts
		_bios
	;;

	*)
		_help
	;;
esac

