#!/bin/sh
#
# Copyright 2002 Dell Computer Corp
#
# based on ks.cfg script by Amro Hatim
# Initial script: 2002-08-15 Hatim Amro

#Common header items, import function definitions
DIR=$(dirname $0)
DIR=$(cd $DIR; pwd)

. $DIR/../functions.sh

# Make sure we're doing this on servers.

        #set PLATFORM variable
        platform
        logecho "We are running on platform --:${PLATFORM}:--"
        if ! echo ${PLATFORM} | grep -q PowerEdge ; then
                logecho "  This platform doesn't look like a PowerEdge server, skipping."
                exit
        fi

# -----------------------------------------------------------------------------
# This script is for Seagate TR5 ide-tape drive.
# use ide-scsi driver instead of ide-tape.
# ------------------------------------------------------------------------------

tapeset() {
cat >> /etc/rc.d/rc.local << EOF
####!/bin/bash
# This script is for Seagate TR5 ide-tape drive.
# If this drive is found, use ide-scsi driver instead of ide-tape
# and disable DMA.
for i in \`ls /proc/ide/ide?/hd?/media 2>/dev/null\`;
    do
        if [ \`cat \$i\` == cdrom ]; then
             modprobe ide-cd > /dev/null 2>&1
        fi
        if [ \`cat \$i\` == tape ]; then
             tape_dev=\`echo \$i | cut -c16-18\`
             tape_dev="/dev/\$tape_dev"
             rmmod ide-tape > /dev/null
             modprobe ide-scsi > /dev/null
             hdparm -d0 \$tape_dev > /dev/null
             mt -f /dev/st0 stoptions no-blklimits
        fi
    done
#end of Seagate TR5 ide-tape script
EOF
}

for i in `ls /proc/ide/ide?/hd?/media 2>/dev/null`;
    do
        if [ `cat $i` == tape ]; then
             ide_cntrl=`echo $i | cut -c11-14`
             tape_dev=`echo $i | cut -c16-18`
             if [ "`cat /proc/ide/$ide_cntrl/$tape_dev/model`" == "Seagate STT20000A" ] && [ `grep -c "tape_dev=" /etc/rc.d/rc.local` -lt 1 ]; then
                tapeset
             fi
        fi
    done
