#!/bin/sh
# This is a script to test CISS volumes
# Author: Leonid Nevecherya
# Based on a script by Garrett Wollman. (ports/sysutils/smartmontools/files/smart.in as of 1.12 2011/12/01 20:53:31)
#

if [ -r /etc/defaults/periodic.conf ]; then
    . /etc/defaults/periodic.conf
    source_periodic_confs
fi

cciss_vol_status=%%PREFIX%%/bin/cciss_vol_status
: ${daily_cciss_vol_status_flags="-s"}
: ${daily_cciss_vol_status_extra_status_flags="-V"}

case "${daily_cciss_vol_status_devices}" in
       # AUTO mode selects all ciss disks
       [Aa][Uu][Tt][Oo])
               daily_cciss_vol_status_devices="$(ls /dev/ciss*)"
               ;;
       *)      ;;
esac

if [ -z "${daily_cciss_vol_status_devices}" ]; then
       : ${daily_cciss_vol_status_enable="NO"}
else
       : ${daily_cciss_vol_status_enable="YES"}
fi

tmpfile="$(mktemp -t daily)"
trap "rm -f ${tmpfile}" 0 1 3 15

rc=0
case "${daily_cciss_vol_status_enable}" in
       [Yy][Ee][Ss])
               echo
               echo 'CISS volumes status:'
               cd /dev
               for device in ${daily_cciss_vol_status_devices}; do
                       if [ -e ${device} ]; then
                               echo -n "Checking health of ${device}: "
                               ${cciss_vol_status} ${daily_cciss_vol_status_flags} \
                                       ${device} > "${tmpfile}"
                               status=$?
                               if [ ${status} -eq 0 ]; then
                                       echo "OK"
                               else
                                       rc=1
                                       ${cciss_vol_status} \
                                               ${daily_cciss_vol_status_extra_status_flags} \
                                               ${device}
                               fi
                       fi
               done
               ;;
esac

exit "${rc}"
