#!/bin/sh failure() { echo "[FAIL] $1" insmod /lib/uhci-hcd.ko exec /bin/ash } configure_network() { rm -f /tmp/netconf insmod /lib/e1000e.ko insmod /lib/bnx2.ko # insmod /lib/xfrm_nalgo.ko # insmod /lib/ipv6.ko sleep 1 for tries in 2 1 0; do /bin/ifconfig -a | while read ifc link encap ignore; do if [ "$link" = Link ]; then if [ "$encap" = "encap:Ethernet" ]; then ifconfig $ifc up echo "Trying DHCP on $ifc ..." udhcpc -n -q -s /bin/mknetconf -i $ifc > /tmp/udhcp.out 2>&1 # If udhcpc is successful, mknetconf will create /tmp/netconf if [ -e /tmp/netconf ]; then echo "ifc=$ifc" >> /tmp/netconf break fi fi fi done if [ -e /tmp/netconf ]; then . /tmp/netconf break fi if [ $tries -gt 0 ]; then echo "Didn't get any DHCP replies, will try $tries more times ..." for s in 4 3 2 1; do echo -n " Sleeping for $s seconds ... " sleep 1 done echo " " fi done if [ ! -e /tmp/netconf ]; then failure "Unable to configure any interfaces with DHCP" fi echo Configuring $ifc with address $ip ifconfig $ifc $ip netmask $mask up if [ -n "$router" ]; then route add default gw $router fi } harvest() { basemac=`ifconfig eth0 | grep HWaddr | awk '{ print $5 }'` if [ X"$basemac" = X ]; then basemac=unk fi fname=`echo sys.$basemac | sed -e s/://g` numcpu=`grep "^processor" /proc/cpuinfo | wc -l` echo "| Number of CPUs | $numcpu |" > $fname ifconfig -a | grep HWaddr | while read if lx ex hx mac ignore; do echo "| Interface $if | $mac |" >> $fname done cpumod=`grep "model name" /proc/cpuinfo | head -1 | sed -e 's/.* *://'` echo "| CPU model | $cpumod |" >> $fname manuf=`/bin/dmidecode | grep -A7 "System Information" | \ grep "Manufacturer:" | sed -e "s/.*Manufacturer://"` m2=`/bin/dmidecode | grep -A7 "Base Board Information" | \ grep "Manufacturer:" | sed -e "s/.*Manufacturer://"` if [ X"$m2" != X ]; then manuf=$m2 fi if [ X"$manuf" != X ]; then echo "| Manufacturer | $manuf |" >> $fname fi model=`/bin/dmidecode | grep -A8 "System Information" | \ grep "Product Name:" | sed -e "s/.*Product Name://" -e "s/ //g"` m2=`/bin/dmidecode | grep -A8 "Base Board Information" | \ grep "Product Name:" | sed -e "s/.*Product Name://" -e "s/ //g"` if [ X"$model$m2" != X ]; then echo "| System model | $model ($m2) |" >> $fname fi sn=`/bin/dmidecode | grep -A8 "System Information" | \ grep "Serial Number:" | sed -e "s/.*Serial Number://"` if [ X"$sn" != X ]; then if [ `echo $sn | wc -c` = 8 ]; then echo "| Service tag | $sn |" >> $fname else echo "| Serial number | $sn |" >> $fname fi else sn=`/bin/dmidecode | grep -A8 "Base Board Information" | \ grep "Serial Number:" | sed -e "s/.*Serial Number://"` if [ X"$sn" != X ]; then if [ `echo $sn | wc -c` = 8 ]; then echo "| Service tag | $sn |" >> $fname else echo "| Serial number | $sn |" >> $fname fi fi fi memkb=`grep "^MemTotal:" < /proc/meminfo | awk '{ print $2 }'` memmb=`expr $memkb / 1024` echo "| Memory | $memmb MB |" >> $fname grep -v "major minor" /proc/partitions | while read maj min bks name ign; do if [ `echo $name | wc -c ` = 4 ]; then if [ $blks -gt 1000000 ]; then gb=`echo $blks 1024 / 1024 / p | dc` if [ X"$gb" != X ]; then echo "| Drive $name | $gb GB |" >> $fname fi fi fi done cat $fname if [ "X$router" != X ]; then echo "Sending $fname back to $router" fi ftpput -u harvest -p corn $router $fname $fname } ##################################### MAIN ################################## echo "Harvesting system vitals ..." /bin/mount -t proc /proc /proc /bin/mount -t sysfs none /sys configure_network harvest echo "Enable USB keyboard ..." insmod /lib/uhci-hcd.ko sleep 2 cat $fname echo " " exec /bin/ash