#!/bin/ksh -p
#
# ident "@(#)utlinuxdrvctl.ksh	1.1	11/01/18 Oracle"
#
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
#

set -u

function disable_drv {
    if [ -d $INSTALLDIR/$1 ]; then
	cd $INSTALLDIR/$1
	echo -e "\n+++ Removing Sun Ray $2 ...\n"
	make clean 
	make uninstall 
	echo -e "\n+++ Done.\n"
    fi
    rm -f /dev/$1
}

function enable_drv {
    if [ -d $INSTALLDIR/$1 ]; then
	rm -f /dev/$1
 	cd $INSTALLDIR/$1
	echo -e "\n+++ Making and installing Sun Ray $2 ...\n"
	make clean 
	if make; then
	    make install
	fi
	echo -e "\n+++ Done.\n"
    fi
}    

function disable {
    # Remove utadem.o from the system
    disable_drv utadem "Audio module"

    # Remove utdiskctl.o and utdisk.o from the system
    disable_drv utdisk "Mass Storage modules"

    # Remove utio.o from the system
    disable_drv utio "UTIO module"
    
    return 0
    

}

function enable {

    # build utadem module and install it on the system
    enable_drv utadem "Audio module"

    # build utdisk and utdiskctl modules and install them on the system
    enable_drv utdisk "Mass Storage modules"
    
    # build utio driver and install it on the system
    enable_drv utio "UTIO module"

    depmod -a >/dev/null 2>&1
    
    # In case of make failure, no need to abort SRSS installation
    # So, always return 0	
    return 0
    
}


########################################################################
# Local Variables
# They must defined here to resolve some of the parameter resolution
# problem
########################################################################
local_variables() {
    INSTALLDIR=/usr/src/SUNWut
    return
}


########################################################################
#
# Configurable parameter
#
########################################################################
# NONE


########################################################################
#
# Variables used in the shared script utctl-shlib
#
########################################################################
DESCR="Installs/uninstalls Linux audio, mass storage, and utio drivers"


########################################################################
#
# Execution starts here
########################################################################
PROGPATH=`dirname $0`
. $PROGPATH/utctl-shlib
