#!/bin/bash # # ihcp_install-2.6 # Script to compile and load Tahoma Technology # hardcopy driver for Linux version 2.6. # Can also configure rc.local and /etc/ihcp for driver autoload on boot. # This code released under the GPL, and in the public domain # References to IKON left in place for compatibility and historical # reasons # # Tahoma Technology # (formerly Ikon Corporation) # 107 2nd Avenue North # Seattle, WA, USA 98109 # # 206.728.6465 # http://www.tahomatech.com # tahoma@tahomatech.com # ***************************************** # SEE BELOW FOR USER CONFIGURABLE VARIABLES # ***************************************** # general script variables IHCP_SCRIPT_NAME="ihcp_install-2.6" IHCP_SCRIPT_DATE="3 JUNE, 2007 08:07" IHCP_SCRIPT_DESC="Tahoma Technology (formerly Ikon Corporation) hardcopy driver installer" IHCP_LINUX_VERS="for Linux version 2.6.x including x86_64" IHCP_THISDIR=`pwd` # make and copy variables IHCP_MAKE=make IHCP_GREP=grep IHCP_SOURCE=ihcp_driver IHCP_CFLAGS_EXTRA= IHCP_DFLAGS= IHCP_MODULE=ihcp IHCP_KERNEL_VERSION=`uname -r` IHCP_KERNEL_SOURCE_DIR=/lib/modules/$IHCP_KERNEL_VERSION/build IHCP_MODULE_DIR=/lib/modules/$IHCP_KERNEL_VERSION/misc IHCP_TEST_DIR= # load (insmod) and dev node variables IHCP_INSMOD=/sbin/insmod IHCP_RMMOD=/sbin/rmmod IHCP_FFLAG= IHCP_INT_NODELIST="" IHCP_INT_NODE="" IHCP_TEMP=ihcp_temp IHCP_DRIVER=$IHCP_MODULE IHCP_NODENAME=$IHCP_MODULE IHCP_MINOR=0 IHCP_GROUP=bin IHCP_OWNER=bin IHCP_PERM=666 IHCP_INIT_SCRIPT="/etc/rc.d/rc.local" IHCP_INSTALL_SCRIPT_DIR=/etc/ihcp IHCP_INSTALL_SCRIPT_PERM=744 IHCP_INSTALL_SCRIPT_DIR_PERM=755 # *****USER CONFIGURABLE SCRIPT BEHAVIOR VARIABLES***** # these control variables have two or three options # those with YES|NO options force the associated # behavior -- those with an AUTO option allow the # script and/or the driver to autoconfigure the # associated behavior IHCP_USER_DMA=AUTO # NO|AUTO - dma direct from user buffer # AUTO = YES unless kernel configured for > 4G RAM # NO or > 4G RAM = dma from kernel copy buffer IHCP_ENB_DEBUG=NO # YES|NO - YES or cmd line option = debug mode IHCP_FORCE_LOAD=NO # YES|NO - force module load # *****USER CONFIGURABLE LOAD-TIME VARIABLES***** # the following will be passed to insmod and may # be edited to control driver and device configuration # IHCP_BOARDS determines the number of boards probed # for and device nodes created IHCP_BOARDS=4 #number of boards and dev nodes IHCP_MAX_PHYS_ORDER=4 #max dma xfer in "orders" of pages #also controls size of copy buffer (if not user dma) #larger user buffers will be done in max_phys chunks #max = PAGE_SIZE*(2**IHCP_MAX_PHYS_ORDER) #w/current 4K page size, 0=4K, 1=8K, 2=16K, 3=32K, 4=64K ... IHCP_VERS_SPEED=1 #versatec speed: 0=fastest, 3=slowest IHCP_CENT_SPEED=1 #centronics speed: 0=fastest, 3=slowest IHCP_MODE=1 #versatec mode: 1=plot, 0=print IHCP_DMA_TIME=1800 #dma timeout in seconds IHCP_FIFO_TIME=1800 #fifo & ready timeout in seconds IHCP_BYTE_ORDER=0 #byte endian mode, 0=low byte first, 1=high byte first echo # if no argument, print usage if [ -z $1 ] then echo "$IHCP_SCRIPT_NAME: $IHCP_SCRIPT_DATE" echo "$IHCP_SCRIPT_DESC" echo "$IHCP_LINUX_VERS" echo echo "usage: $IHCP_SCRIPT_NAME [compile|load|autoload|remove|all]" echo echo " compile: compiles driver and copies to module directory" echo " load: loads driver into running kernel and creates device node(s)" echo " autoload: copies this script to $IHCP_INSTALL_SCRIPT_DIR/" echo " adds entry to rc.local to autoload driver at boot time" echo " remove: unloads driver, deletes module, removes autoload entry," echo " script copy and directory, and device nodes" echo " all: remove, compile, load, and autoload" echo echo " compile and all may take an optional second argument: debug, which" echo " causes the driver to be compiled in debug mode (many printfs to log)" echo echo " some compile/install options are autodetected by this script and/or the" echo " driver code -- autodetected and hard coded options may be changed by" echo " editing this script" echo exit 0 fi # if arg #2 is debug, or debug enabled in script - set debug compile mode if [ $IHCP_ENB_DEBUG = YES ] then IHCP_DFLAGS=-DIHCP_DEBUG fi if ! [ -z $2 ] then if [ $2 = debug ] then IHCP_DFLAGS=-DIHCP_DEBUG else echo "***** unrecognized 2nd argument!" ./$IHCP_SCRIPT_NAME exit 1 fi fi # compile driver module and copy to module directory # first sort out the compile options if [ $1 = compile ] then echo "$IHCP_SCRIPT_NAME: command is $1 $2" echo "removing old $IHCP_MODULE.o .ko .mod.c .mod.o files (if any)" rm -f $IHCP_MODULE.o rm -f $IHCP_MODULE.ko rm -f $IHCP_MODULE.mod.c rm -f $IHCP_MODULE.mod.o # pass user dma/copy buffer mode to compiler if [ $IHCP_USER_DMA = AUTO ] then echo "auto dma/copy buffer mode" IHCP_CFLAGS_EXTRA="$IHCP_CFLAGS_EXTRA -DIHCP_DMA_MODE_AUTO" else echo "forcing copy buffer mode" IHCP_CFLAGS_EXTRA="$IHCP_CFLAGS_EXTRA -DIHCP_DMA_MODE_COPY" fi if [ -n "$IHCP_DFLAGS" ] then echo "debug compile enabled" fi echo "compiling $IHCP_SOURCE.c using kbuild make" if ! $IHCP_MAKE -C $IHCP_KERNEL_SOURCE_DIR SUBDIRS=$PWD EXTRA_CFLAGS="$IHCP_DFLAGS $IHCP_CFLAGS_EXTRA" modules then echo "***** make error!" exit 1 fi if ! [ -d $IHCP_MODULE_DIR ] then echo "creating $IHCP_MODULE_DIR" mkdir $IHCP_MODULE_DIR fi echo "copying $IHCP_MODULE.ko to $IHCP_MODULE_DIR" if ! cp $IHCP_MODULE.ko $IHCP_MODULE_DIR/ then echo "***** error copying $IHCP_MODULE.ko to $IHCP_MODULE_DIR!" exit 1 fi echo "compile and copy complete" exit 0 fi # [force] load module into kernel and create device nodes if [ $1 = load ] then echo "$IHCP_SCRIPT_NAME: command is $1" if [ $IHCP_FORCE_LOAD = YES ] then IHCP_FFLAG='-f' echo "forced load enabled" fi echo "loading module into kernel" if ! $IHCP_INSMOD $IHCP_FFLAG $IHCP_MODULE_DIR/$IHCP_MODULE.ko\ vers_speed_def=$IHCP_VERS_SPEED\ cent_speed_def=$IHCP_CENT_SPEED mode_def=$IHCP_MODE\ dma_time_def=$IHCP_DMA_TIME fifo_time_def=$IHCP_FIFO_TIME\ max_phys_order=$IHCP_MAX_PHYS_ORDER max_boards=$IHCP_BOARDS\ byte_order_def=$IHCP_BYTE_ORDER then echo "***** insmod error!" exit 1 fi echo "removing stale device nodes (if any)" rm -f /dev/$IHCP_NODENAME* echo "getting device major number from /proc/devices" IHCP_MAJOR=`cat /proc/devices | awk "\\$2==\"$IHCP_DRIVER\" {print \\$1}"` echo "getting node list from /proc/interrupts" IHCP_INT_NODELIST=`$IHCP_GREP -E -o "\<$IHCP_NODENAME[[:digit:]]+" /proc/interrupts` echo "creating device node(s)" while [ $IHCP_BOARDS -gt 0 ] do for IHCP_INT_NODE in $IHCP_INT_NODELIST do if [ "$IHCP_INT_NODE" = $IHCP_NODENAME$IHCP_MINOR ] then if ! mknod /dev/$IHCP_NODENAME$IHCP_MINOR c $IHCP_MAJOR $IHCP_MINOR then echo "***** mknod error!" exit 1 fi echo "created device node /dev/$IHCP_NODENAME$IHCP_MINOR" echo "setting device node ownership" chown $IHCP_OWNER /dev/$IHCP_NODENAME$IHCP_MINOR chgrp $IHCP_GROUP /dev/$IHCP_NODENAME$IHCP_MINOR chmod $IHCP_PERM /dev/$IHCP_NODENAME$IHCP_MINOR fi done IHCP_BOARDS=$( expr $IHCP_BOARDS - 1 ) IHCP_MINOR=$( expr $IHCP_MINOR + 1 ) done echo "driver loaded and device nodes created" echo "load complete" exit 0 fi # copy this script to script dir (/etc/ihcp, probably) # invoke it (load) from /etc/rc.d/rc.local if [ $1 = autoload ] then echo "$IHCP_SCRIPT_NAME: command is $1" echo "removing old $IHCP_SCRIPT_NAME (if present) from $IHCP_INSTALL_SCRIPT_DIR" if [ -d $IHCP_INSTALL_SCRIPT_DIR ] then rm -f $IHCP_INSTALL_SCRIPT_DIR/$IHCP_SCRIPT_NAME* fi echo "creating $IHCP_INSTALL_SCRIPT_DIR (if necessary) and setting permissions" if [ -d $IHCP_INSTALL_SCRIPT_DIR ] then echo "$IHCP_INSTALL_SCRIPT_DIR exists, leaving permissions unchanged" else if ! mkdir $IHCP_INSTALL_SCRIPT_DIR then echo "***** error creating $IHCP_INSTALL_SCRIPT_DIR!" exit 1 fi if ! chmod $IHCP_INSTALL_SCRIPT_DIR_PERM $IHCP_INSTALL_SCRIPT_DIR then echo "***** error setting permissions on $IHCP_INSTALL_SCRIPT_DIR!" exit 1 fi fi echo "copying $IHCP_SCRIPT_NAME to $IHCP_INSTALL_SCRIPT_DIR and setting permissions" if ! cp $IHCP_SCRIPT_NAME $IHCP_INSTALL_SCRIPT_DIR/ then echo "***** error copying $IHCP_SCRIPT_NAME to $IHCP_INSTALL_SCRIPT_DIR!" rmdir --ignore-fail-on-non-empty $IHCP_INSTALL_SCRIPT_DIR exit 1 fi if ! chmod $IHCP_INSTALL_SCRIPT_PERM $IHCP_INSTALL_SCRIPT_DIR/$IHCP_SCRIPT_NAME then echo "***** error setting permissions on $IHCP_SCRIPT_NAME!" exit 1 fi echo "removing old $IHCP_SCRIPT_NAME entry (if any) from $IHCP_INIT_SCRIPT" if ! sed /$IHCP_SCRIPT_NAME/d $IHCP_INIT_SCRIPT > ./$IHCP_TEMP then echo "***** sed error removing entry from $IHCP_INIT_SCRIPT!" exit 1 fi if ! cp ./$IHCP_TEMP $IHCP_INIT_SCRIPT then echo "***** error writing back $IHCP_INIT_SCRIPT!" exit 1 fi echo "adding $IHCP_SCRIPT_NAME to $IHCP_INIT_SCRIPT" if ! echo "if [ -x $IHCP_INSTALL_SCRIPT_DIR/$IHCP_SCRIPT_NAME ] ; then { date ; echo ; echo \"\$0: calling $IHCP_INSTALL_SCRIPT_DIR/$IHCP_SCRIPT_NAME load\" ; $IHCP_INSTALL_SCRIPT_DIR/$IHCP_SCRIPT_NAME load ; } > $IHCP_INSTALL_SCRIPT_DIR/$IHCP_SCRIPT_NAME.bootlog 2>&1 ; fi" >> $IHCP_INIT_SCRIPT then echo "***** error adding entry to $IHCP_INIT_SCRIPT!" exit 1 fi rm -f ./$IHCP_TEMP echo "$IHCP_SCRIPT_NAME added to $IHCP_INIT_SCRIPT" exit 0 fi # unload driver and clean up if [ $1 = remove ] then echo "$IHCP_SCRIPT_NAME: command is $1" echo "unloading module from kernel (if present)" $IHCP_RMMOD $IHCP_MODULE echo "removing device nodes" rm -f /dev/$IHCP_NODENAME* echo "deleting $IHCP_MODULE.ko module from $IHCP_MODULE_DIR" rm -f $IHCP_MODULE_DIR/$IHCP_MODULE.ko echo "removing $IHCP_MODULE_DIR (if present and empty)" rmdir --ignore-fail-on-non-empty $IHCP_MODULE_DIR echo "removing $IHCP_SCRIPT_NAME entry (if any) from $IHCP_INIT_SCRIPT" if ! sed /$IHCP_SCRIPT_NAME/d $IHCP_INIT_SCRIPT > ./$IHCP_TEMP then echo "***** sed error removing entry from $IHCP_INIT_SCRIPT!" exit 1 fi if ! cp ./$IHCP_TEMP $IHCP_INIT_SCRIPT then echo "***** error writing back $IHCP_INIT_SCRIPT!" exit 1 fi rm -f ./$IHCP_TEMP echo "deleting $IHCP_SCRIPT_NAME (if present) from $IHCP_INSTALL_SCRIPT_DIR" if ! rm -f $IHCP_INSTALL_SCRIPT_DIR/$IHCP_SCRIPT_NAME* then echo "***** error deleting $IHCP_INIT_SCRIPT from $IHCP_INSTALL_SCRIPT_DIR!" exit 1 fi echo "removing $IHCP_INSTALL_SCRIPT_DIR (if present and empty)" rmdir --ignore-fail-on-non-empty $IHCP_INSTALL_SCRIPT_DIR echo "remove complete" exit 0 fi # remove, compile, load, build nodes, and set autoload if [ $1 = all ] then echo "$IHCP_SCRIPT_NAME: command is $1 $2" if ! ./$IHCP_SCRIPT_NAME remove then echo "***** remove error!" exit 1 fi if ! ./$IHCP_SCRIPT_NAME compile $2 then echo "***** compile error!" exit 1 fi if ! ./$IHCP_SCRIPT_NAME load then echo "***** load error!" exit 1 fi if ! ./$IHCP_SCRIPT_NAME autoload then echo "***** autoload error!" exit 1 fi echo "" echo "remove, compile, load, and autoload complete" exit 0 fi # if unrecognized arg, bitch, and print usage echo "***** unrecognized 1st argument!" ./$IHCP_SCRIPT_NAME exit 1