#!/bin/sh
#     cfgdiska.sh  - script to configure ATA disks
#
logfile=$DeploymentStore/cfgdiska.log
devata=`queryProperty Disk device - type=ATA`
devscsi=`queryProperty Disk device - type=SCSI`
wce=0
ADDLOG=addLogRecord
# ADDLOG=echo

# init the logfile
date >$logfile
devlist="$devscsi $devata"

if [ "$devlist" = " " ]
then
   $ADDLOG $0 ERROR "No ATA disk devices found"
   exit 1
fi
for dev in $devlist
do
  isDisk=0
  # save the disk parameters
  echo "hdparm -I $dev"  >>$logfile
  hdparm -I $dev  >>$logfile 2>/dev/null
  if [ $? -eq 0 ]
  then
    # filter these for only non-removable media
    hdparm -I $dev 2>/dev/null|grep "non-removable media" >/dev/null 2>&1
    ret=$?
    if [ $ret -eq 0 ]
    then
      $ADDLOG $0 INFO "Cfg Disk: hdparm -I $dev"
      isDisk=1
    fi
  fi

  if [ $isDisk -eq 1 ]
  then
    # set the write cache on/off for this disk
    echo "hdparm -W${wce} $dev"  >>$logfile 
    hdparm -W${wce} $dev  >>$logfile 2>&1
    ret=$?
    if [ $ret -eq 0 ]
    then
     $ADDLOG $0 INFO "Success: hdparm -W${wce} $dev"
    else
     $ADDLOG $0 ERROR "Error $ret: hdparm -W${wce} $dev"
    fi
  fi
done

exit $ret 
