#!/bin/sh -e
# $Id: probe.sh,v 1.19 2004/11/18 13:19:28 abs Exp $
# Cannot use $() on Solaris. Even in sections protected by if []. Great...
PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Basic uname information
#
echo osname=`uname -s`
echo osver=`uname -r`
echo machine=`uname -m`
machine_arch=`uname -p 2>/dev/null || true`
if [ -n "$machine_arch" ]; then
    echo machine_arch=$machine_arch
fi

# Check for X11 libraries in standard place
#
if [ -f /usr/X11R6/lib/libX11.so -o -f /usr/X11R6/lib/libX11.a ] ; then
    echo x11=x11
else
    echo x11=nox11
fi

# If we are on redhat (not my first choice, but...), report its version
#
if [ -f /etc/redhat-release ] ; then
    echo redhat=`sed -e 's/Red Hat Linux release //' \
		     -e 's/ .*//' /etc/redhat-release`
fi

# Sample system monitoring - report 'clean' or 'DIRTY' raidframe partitions
#
if [ `uname -s` = NetBSD ] ; then
    DISKS="`sysctl -n hw.disknames|fmt -1|sort`"

    # RAID status as raid={clean,DIRTY}, plus per disk raid0, raid1, ...
    overall_raid_status=clean
    for disk in `echo $DISKS | fmt -1 | grep '^raid[0-9]'` ; do
	raid_present=1
	status=`raidctl -s $disk 2>/dev/null | awk '/^  *\/dev\//{if($2 != "optimal"){status="component_"$2}}/Parity status:/{if(status == ""){status=$3}}END{print status}'`
	if [ -z "$status" ] ; then
	    status=unknown
	fi
	echo $disk=$status
	if [ "$status" != clean ] ; then
	    overall_raid_status=$status
	fi
    done
    if [ -n "$raid_present" ]; then
	echo raid=$overall_raid_status
    fi

    # smart status on per disk basis smart_wdNN={enabled,disabled}
    for disk in `echo $DISKS | fmt -1 | grep '^wd[0-9]'`; do
	status=`atactl $disk smart status 2>&1 | grep SMART | tail -1`
	case "$status" in
	    "atactl: unknown command: smart"|"")
		;; # Do not output anything
	    *)
		status=`echo $status|sed -e 's/.*SMART //' -e 's/ /-/g'`
		echo "smart_$disk=$status"
		;;
	esac
    done

    # Kernel name
    echo kernel=`uname -v | awk '{gsub("[()]",""); print $3}'`
    echo kernel_date=`uname -v | sed -e 's/  .*//' -e 's/.*: ... //'`
fi

# Example: Determine ssh version and location of config files
#
# ssh=`which ssh`
# if [ -x "$ssh" ] ; then
#      echo sshver=`ssh -V 2>&1 | \
#          sed -n -e '1s/^[^0-9][^0-9]* //' -e '1s/[, ].*//p'`
#      echo sshetc=`strings -a $ssh | grep '/etc.*/ssh_host_key' | \
#          sed -e 's:/ssh_host_key::' -e 's:/::g'` 
# fi

# Update this when this script is changed. This must be after any important tags
#
echo probe_version='$Id: probe.sh,v 1.19 2004/11/18 13:19:28 abs Exp $'
