#!/bin/bash
#
# hwup-ctc
# $Id: hwup-ctc 1069 2004-09-02 18:23:18Z zoz $
#
# Configuration script for CTC devices
# Sets the protocol mode if configured and 
# sets the adapter online
#

SCRIPTNAME=${0##*/}
HWDESC=$1

# Read in common functions
. ./scripts/functions
test -r ./config && . ./config

# Check for variables
if test -z "$SYSFS"; then
    message "sysfs not mounted, aborting."
    exit 1
fi

if [ -z "$DEVPATH" ]; then
    message "no device path given, aborting."
    exit 1
fi

# Read in the configuration file
. ./hwcfg-${HWDESC}

# Set sysfs paths
_ccwgroup_dir=${SYSFS}${DEVPATH}

# Check whether the channel group is configured
message_n "Configuring device ${_ccwgroup_dir##*/}: "
if test -d "$_ccwgroup_dir" ; then
    read _online < $_ccwgroup_dir/online
    # We do not check for the value of CCW_CHAN_MODE, since we
    # might want to switch back and forth between several modes
    if test "$_online" -eq "0" ; then
	if [ "$CCW_CHAN_MODE" ]; then
	    message_n "(protocol $CCH_CHAN_MODE) "
	    echo "$CCW_CHAN_MODE" > $_ccwgroup_dir/protocol
	else
	    CCW_CHAN_MODE=0
	fi
	echo "1" > $_ccwgroup_dir/online
	message "ok."
    else
	message "already online."
    fi
else
    message "not available."
fi

#EOF
