#!/bin/csh -f #!/bin/csh -fx # # ihcp.INSTALL # # Copyright (c) 1990, Sun Microsystems, Inc. All Rights Reserved. # Sun considers its source code as an unpublished, proprietary # trade secret, and it is available only under strict license # provisions. This copyright notice is placed here only to protect # Sun in the event the source is deemed a published work. # Disassembly, decompilation, or other means of reducing the # object code to human readable form is prohibited by the license # agreement under which this code is provided to the user or # company in possession of this copy. # # RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the # Government is subject to restrictions as set forth in # subparagraph (c)(1)(ii) of the Rights in Technical Data and # Computer Software clause at DFARS 52.227-7013 and in similar # clauses in the FAR and NASA FAR Supplement. # # These examples are provided with no warranties of any kind, # including without limitation accuracy and usefulness, and Sun # expressly disclaims all implied warranties of merchantability, # fitness for a particular purpose and non-infringement. In no # event shall Sun be liable for any damages, including without # limitation, direct, special, indirect, or consequential damages # arising out of, or relating to, use of these examples by customer # or any third party. Sun is under no obligation to provide support # to customer. # # # @(#) ihcp.INSTALL ihcp.LOAD ihcp.UNLOAD ihcp.MKDEV ihcp.RMDEV: # @(#) ihcp.INSTALL 1.5 90/02/12 SMI # # # This script may be called by root as: # ihcp.INSTALL from any directory or /dev/ihcp.INSTALL # to install the ihcp driver and make the devices # # This script may be called by /etc/loadable, ihcp.INSTALL, or root as: # /dev/ihcp.LOAD [] # to load the ihcp driver and make the devices # where NIHCP is the number of devices to make. # # This script may be called by /etc/loadable, ihcp.MKDEV, or root as: # /dev/ihcp.UNLOAD # to remove the ihcp driver and devices. # # This script may be called by modload as: # /dev/ihcp.MKDEV # # This script may be called by modunload as: # /dev/ihcp.RMDEV # or # /dev/ihcp.RMDEV # # The arg module_id is a small positive integer. # This module id is used to unload the ihcp driver with modunload. # The module id number is available at any time while the module is loaded # from the modstat command, but for ease of programmable unloading we will # store the id number in the /dev/ihcp.ID file. # # The arg module_type will always be 0x12345600 unless VDMAGIC_DRV in # vddrv.h changes. Note that for a pseudo device driver (without hardware) # the value for VDMAGIC_PSEUDO would be used. # # The arg block_major is not used by the ihcp driver. # # The arg char_major is used to make the device nodes. # # # Default number of nodes to make. # This may not match number that a configured in driver can handle. # set DEFAULT_NIHCPS = 2 # # Remove any leading components of the pathname. # Check the names although wrong names should not happen. # set MYNAME = $0 set MYNAME = $MYNAME:t if ( $MYNAME != ihcp.INSTALL && \ $MYNAME != ihcp.LOAD && $MYNAME != ihcp.UNLOAD \ && $MYNAME != ihcp.MKDEV && $MYNAME != ihcp.RMDEV ) then echo -n "Invocation names: ihcp.INSTALL ihcp.LOAD " echo "ihcp.UNLOAD ihcp.MKDEV ihcp.RMDEV" exit 1 endif # # Check for superuser status. # touch /tmp/sutest$$ chown root /tmp/sutest$$ >& /dev/null if ($status != 0) then echo "${MYNAME}: must be super user." rm -f /tmp/sutest$$ exit 1 endif rm -f /tmp/sutest$$ # # Install or upgrade the loadable driver. It is presumed that at this # point two files have been read into the current directory which may # or may not be /dev. They are ihcp.INSTALL and ihcp.o. Both may be # symbolic links to another location, such as /sys/sbusdev. # if ($MYNAME == ihcp.INSTALL) then # # If we are not in /dev, make symbolic links from /dev to here # for ihcp.INSTALL and ihcp.o. Symbolic links must be used # because /dev may be a different filesystem. # if ($cwd != /dev) then # # Remove any previous versions of the driver. # rm -f /dev/ihcp.INSTALL rm -f /dev/ihcp.o # # Make links to the new driver sources. # ln -s $cwd/ihcp.INSTALL /dev/ihcp.INSTALL ln -s $cwd/ihcp.o /dev/ihcp.o # # Invoke ihcp.INSTALL from /dev # cd /dev ihcp.INSTALL sync # for safety after writing /dev exit $status endif # # Check for an entry in /etc/rc.local to invoke /etc/loadable if # /etc/loadable exists. If this entry does not exist, append it. # This single entry will serve all loadable modules. For safety, # we do not actually edit the /etc/rc.local file. /etc/rc.local # is too critical to the booting process to take chances with!!! # grep -s "/etc/loadable" /etc/rc.local if ($status == 1) then # no match and no error echo "#" >> /etc/rc.local echo "# Load loadable modules." >> /etc/rc.local echo "#" >> /etc/rc.local echo "if [ -f /etc/loadable ]; then" >> /etc/rc.local echo " sh /etc/loadable > /dev/console" \ >> /etc/rc.local echo "fi" >> /etc/rc.local echo "" >> /etc/rc.local endif sync # for safety after writing /etc # # if it does not exist, create /etc/loadable for all to use. # Make it executable and flag it as a borne shell script to # allow calling by root as /etc/loadable. # if (! -e /etc/loadable) then echo ":" > /etc/loadable chmod u+x /etc/loadable endif sync # for safety after writing /etc # # Make an entry in /etc/loadable to invoke /dev/ihcp.LOAD if # /dev/ihcp.AUTOLOAD exists. # A maximum of one such entry will be appended. Because this # script can be run multiple times and we do not want to edit # the /etc/loadable file, the automatic loading of ihcp on reboot # is conditional on both /dev/ihcp.LOAD and /dev/ihcp.AUTOLOAD. # grep -s "IHCP_DRIVER_INSTALLED" /etc/loadable if ($status == 1) then # no match and no error echo "#" >> /etc/loadable echo "# Load the ihcp driver if desired." \ >> /etc/loadable echo "#" >> /etc/loadable echo "rm -f /dev/ihcp.ID" >> /etc/loadable echo "if [ -f /dev/ihcp.LOAD ]; then" \ >> /etc/loadable echo " if [ -f /dev/ihcp.AUTOLOAD ]; then" \ >> /etc/loadable echo -n " csh /dev/ihcp.LOAD" \ >> /etc/loadable echo " # IHCP_DRIVER_INSTALLED" >> /etc/loadable echo " fi" >> /etc/loadable echo "fi" >> /etc/loadable echo "" >> /etc/loadable endif sync # for safety after writing /etc # # Automatic modload on reboot is optional. The default is yes. # Ask the installer if automatic loading of the driver is desired. # echo -n "Do you want the ihcp driver to be automatically loaded " echo -n "during each reboot? [y|n] (y): " set RESPONSE = $< if ("$RESPONSE" != "n" && "$RESPONSE" != "N" \ && "$RESPONSE" != "no" && "$RESPONSE" != "NO") then touch /dev/ihcp.AUTOLOAD else rm -f /dev/ihcp.AUTOLOAD endif # # Ask how many ihcp devices to make. # Store the value for ihcp.LOAD. # echo -n "How many ihcp devices do you want? ($DEFAULT_NIHCPS): " set RESPONSE = $< if ("$RESPONSE" == "") set RESPONSE = $DEFAULT_NIHCPS # check for numeric value @ NUMBER_IHCPDEVS = $RESPONSE echo $NUMBER_IHCPDEVS >! /dev/ihcp.NIHCPS # # Remove any previous versions of this script. # rm -f /dev/ihcp.LOAD rm -f /dev/ihcp.UNLOAD rm -f /dev/ihcp.MKDEV rm -f /dev/ihcp.RMDEV # # Since /dev may be a different filesystem, # copy ihcp.INSTALL to ihcp.LOAD. # cp /dev/ihcp.INSTALL /dev/ihcp.LOAD # # Make the rest of the links. # ln /dev/ihcp.LOAD /dev/ihcp.UNLOAD ln /dev/ihcp.LOAD /dev/ihcp.MKDEV ln /dev/ihcp.LOAD /dev/ihcp.RMDEV # # Do a ihcp.LOAD to load the driver and make the device nodes. # /dev/ihcp.LOAD sync # for safety after writing /dev exit $status endif # # Decide how many nodes to make. If an NIHCPS arg was passed to # ihcp.LOAD, then make that many. If no arg passed in but # /dev/ihcp.NIHCPS exists, then make the number contained therein. # Failing that, use the default. Save the NIHCPS value in # /dev/ihcp.NIHCPS for use by ihcp.MKDEV because we cannot pass # it through from modload. # if ($MYNAME == ihcp.LOAD && $#argv == 1) then # check for numeric value @ NUMBER_IHCPDEVS = $1 echo $NUMBER_IHCPDEVS >! /dev/ihcp.NIHCPS shift else if (-f /dev/ihcp.NIHCPS) then set NUMBER_IHCPDEVS = `cat /dev/ihcp.NIHCPS` else set NUMBER_IHCPDEVS = $DEFAULT_NIHCPS endif # # Handle invocation as ihcp.LOAD. # Multiple invocations of ihcp.LOAD are intended to be benign. # if ($MYNAME == ihcp.LOAD) then if ($#argv != 0) then # any arg1 was shifted out above echo "Usage: $MYNAME []" exit 1 endif # # Modload the driver, arranging for /dev/ihcp.MKDEV to be called. # # comment out the MKDEV invocation - something is fishy !!!!! echo -n "ihcp: " modload /dev/ihcp.o -entry _ihcp_vdcmd -exec /dev/ihcp.MKDEV set exit_status = $status # clean up from modload rm -f /dev/ihcp sync # for safety after writing /dev exit $exit_status endif # # Handle invocation as ihcp.UNLOAD. # Multiple invocations of ihcp.UNLOAD are intended to be benign. # if ($MYNAME == ihcp.UNLOAD) then if ($#argv != 0) then echo "Usage: $MYNAME" exit 1 endif modunload -id `cat /dev/ihcp.ID` if ($status == 0) then # remove /dev info after device /dev/ihcp.RMDEV # unloaded successfully endif sync # for safety after writing /dev exit $status endif # # If we got here, then I was invoked as ihcp.MKDEV or ihcp.RMDEV. # # # Check args for ihcp.MKDEV and ihcp.RMDEV ... # if ($MYNAME == ihcp.MKDEV) then if ($#argv != 4) then echo -n "Usage: $MYNAME " echo " " exit 1 endif endif # # At 4.0.3c modunload passes 4 args to the -exec file. # At 4.1 modunload passes 2 args to the -exec file. # #if ($MYNAME == ihcp.RMDEV) then # if ($#argv != 4 && $#argv != 2) then # echo -n "Usage: $MYNAME " # echo "[ ]" # exit 1 # endif #endif # # Note that even though this is a hex number, no 0x is used in it... # if ("$2" != "12345600") then echo "${MYNAME}: ${2}: bad module type." exit 1 endif # # Handle invocation as ihcp.MKDEV. # Multiple invocations of ihcp.MKDEV are intended to be benign. # if ($MYNAME == ihcp.MKDEV) then set CHARMAJOR = $4 set MODULE_ID = $1 # # If a previous ihcp driver was loaded, try to unload it. # if (-f /dev/ihcp.ID) then set OLD_ID = `cat /dev/ihcp.ID` echo ${MYNAME}: A ihcp driver was already loaded. echo ${MYNAME}: Removing previous driver number $OLD_ID. /dev/ihcp.UNLOAD if ($status != 0) then # # At this point the new driver is already loaded, # so we may as well go ahead and use it. The old # one may have failed to unload because it was in # use by a process. # echo -n "${MYNAME}: Unable to remove " echo previous ihcp driver. endif endif # # Store the module ID for future use... # echo $MODULE_ID >! /dev/ihcp.ID # # Make the device nodes... # @ THIS_IHCP = 0 while ($THIS_IHCP < $NUMBER_IHCPDEVS) rm -f /dev/ihcp$THIS_IHCP mknod /dev/ihcp$THIS_IHCP c $CHARMAJOR $THIS_IHCP chmod 666 /dev/ihcp$THIS_IHCP @ THIS_IHCP = $THIS_IHCP + 1 end sync # for safety after writing /dev exit 0 endif # # Handle invocation as ihcp.RMDEV. # Multiple invocations of ihcp.RMDEV are intended to be benign. # if ($MYNAME == ihcp.RMDEV) then rm -f /dev/ihcp.ID # # Remove the device nodes... # rm -f /dev/ihcp[0-9]* sync # for safety after writing /dev exit 0 endif