#!/bin/bash

cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo )
cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo )
tram=$( free -m | awk 'NR==2 {print $2}' )
swap=$( free -m | awk 'NR==4 {print $2}' )
up=$(uptime|awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }')


printf "\n\n"
printf "Rasanegar Server Test\n"

printf "CPU model : $cname\n"
printf "Number of cores : $cores\n"
printf "CPU frequency : $freq MHz\n"
printf "Total amount of ram : $tram MB\n"
printf "Total amount of swap : $swap MB\n"
printf "System uptime : $up \n\n"


printf "Listing Memory Modules \n"

memory=$( dmidecode --type 17 | grep -i "size\|locator\|type:\|speed\|manufacturer\|serial\|asset\|part" | sed 's/Size/\n &/g' )
printf "$memory"


printf "\nListing HAL Info \n"


if which hal-find-by-property >/dev/null; then


udi=$(hal-find-by-property --key info.product --string Computer)

mobomfg=$(hal-get-property --udi $udi --key system.board.vendor 2>/dev/null)
if [ -z "$mobomfg" ]; then
printf "Board Manufacturer: $mobomfg\n"

fi
mobomodel=$(hal-get-property --udi $udi --key system.board.product 2>/dev/null)
if [ -z "$mobomodel" ]; then
printf "Model: $mobomodel\n"
fi

moboversion=$(hal-get-property --udi $udi --key system.board.version 2>/dev/null)
if [ -z "$moboversion" ]; then
printf "Version: $moboversion\n"
fi

moboserial=$(hal-get-property --udi $udi --key system.board.serial 2>/dev/null)
if [ -z "$moboserial" ]; then
printf "Serial No.: $moboserial\n"
fi

moborelease=$(hal-get-property --udi $udi --key system.firmware.release_date 2>/dev/null)
if [ -z "$moborelease" ]; then
printf "Release Date: $moborelease\n"
fi

mobofirmware=$(hal-get-property --udi $udi --key system.firmware.version 2>/dev/null)
if [ -z "$mobofirmware" ]; then
printf "Bios Version: $mobofirmware\n"
fi

mobouuid=$(hal-get-property --udi $udi --key system.hardware.uuid 2>/dev/null)
if [ -z "$mobouuid" ]; then
printf "Motherboard UUID: $mobouuid\n"
fi


printf "\n\nDisk Listing\n"

 printf "VENDOR  -   MODEL   -    DEVICE  -   MOUNT  -   LABEL  -    SIZE \n"

for udi in $(/usr/bin/hal-find-by-capability --capability storage)
do

        unset vendor
        unset model
        unset device
        unset mount
        unset label
        unset size
        device=$(hal-get-property --udi $udi --key block.device)
    vendor=$(hal-get-property --udi $udi --key storage.vendor)
    model=$(hal-get-property --udi $udi --key storage.model)


        parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
        mount=$(hal-get-property --udi $parent_udi --key volume.mount_point)
        label=$(hal-get-property --udi $parent_udi --key volume.label)
        media_size=$(hal-get-property --udi $udi --key storage.removable.media_size)
        size=$((media_size / 10**9))

if [ -z "$vendor" ]; then
    vendor="Vendor-N/A"
fi


if [ -z "$model" ]; then
    model="Model-N/A"
fi


if [ -z "$device" ]; then
    device="Device-N/A"
fi

if [ -z "$mount" ]; then
    mount="Mount-N/A"
fi

if [ -z "$label" ]; then
    label="Label-N/A"
fi

   printf "\n $vendor - $model - $device - $mount -  $label -  "${size}GB" \n"

done


printf "\n\nUSB Disks\n"


for udi in $(/usr/bin/hal-find-by-capability --capability storage)
do
device=$(hal-get-property --udi $udi --key block.device)
vendor=$(hal-get-property --udi $udi --key storage.vendor)
model=$(hal-get-property --udi $udi --key storage.model)
if [[ $(hal-get-property --udi $udi --key storage.bus) = "usb" ]]
then
parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
mount=$(hal-get-property --udi $parent_udi --key volume.mount_point)
label=$(hal-get-property --udi $parent_udi --key volume.label)
media_size=$(hal-get-property --udi $udi --key storage.removable.media_size)
size=$((media_size / 10**9))
printf "$vendor $model $device $mount $label "${size}GB" \n"
fi
done


printf "\n\nCDROM Drives\n"

for i in $(hal-find-by-property --key storage.drive_type --string cdrom)
do
printf "Manufacturer: $(hal-get-property --udi $i --key storage.vendor)\n"
printf " Model: $(hal-get-property --udi $i --key block.device)\n"
printf " Bus: $(hal-get-property --udi $i --key storage.model)\n"
printf " Path: $(hal-get-property --udi $i --key storage.bus)\n"
done

else

printf "\n\nLinux HAL not found, skipping advanced hardware detection \n\n"


fi

printf "\n\nNetwork Tests\n"

cachefly=$( wget -O /dev/null http://cachefly.cachefly.net/100mb.test 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from CacheFly: $cachefly "
coloatatl=$( wget -O /dev/null http://speed.atl.coloat.com/100mb.test 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Coloat, Atlanta GA: $coloatatl "
sldltx=$( wget -O /dev/null http://speedtest.dal05.softlayer.com/downloads/test100.zip 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Dallas, TX: $sldltx "
linodejp=$( wget -O /dev/null http://speedtest.tokyo.linode.com/100MB-tokyo.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Linode, Tokyo, JP: $linodejp "
#linodeuk=$( wget -O /dev/null http://speedtest.london.linode.com/100MB-london.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
#echo "Download speed from Linode, London, UK: $linodeuk "
leaseweb=$( wget -O /dev/null http://mirror.leaseweb.com/speedtest/100mb.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Leaseweb, Haarlem, NL: $leaseweb "
slsg=$( wget -O /dev/null http://speedtest.sng01.softlayer.com/downloads/test100.zip 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Singapore: $slsg "
slwa=$( wget -O /dev/null http://speedtest.sea01.softlayer.com/downloads/test100.zip 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Seattle, WA: $slwa "
slsjc=$( wget -O /dev/null http://speedtest.sjc01.softlayer.com/downloads/test100.zip 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, San Jose, CA: $slsjc "
slwdc=$( wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test100.zip 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Washington, DC: $slwdc "
ldc=$( wget -O /dev/null http://mirror.dacentec.com/1000MB.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from CentriLogic, Lenoir, NC USA: $ldc "

printf "\n\nDisk IO Test\n"
io=$( ( dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
printf "I/O speed : $io\n\n"

