#!/bin/sh # @(#)addclipr.sh 1.6 8/25/95 trap "" 1 2 15 LMPATHS="`/bin/dirname $0`/../lib/lmpaths" if [ -f ${LMPATHS} ] then . ${LMPATHS} else . lmpaths fi oulimit=`ulimit` ulimit 512 prname=$2 clname=`echo $1 | tr "[A-Z]" "[a-z]"` prtype=$3 # # check that the user is root # if [ -x /usr/bin/id ] then eval `/usr/bin/id | sed 's/(/ \# /'` if [ "${uid:=0}" -ne 0 ] then echo "You must be super-user (root) to execute this script." exit 1 fi else echo "$0: Cannot check user id." exit 1 fi if [ $# -lt 3 ] then echo "usage: addclipr " exit 1 fi # # Make sure the setuid bit is on in disable. # uidbit=`/bin/ls -l $LPDISABLE_PATH | cut -c4` if [ "$uidbit" != "s" ] then echo echo " To use client printers, '$PUBLIC_FILE_OWNER' must be allowed \c" echo " to disable printers." echo " The 'disable' command on this machine is restricted \c" echo " to 'lp' and 'root'." ans=x while [ "$ans" != "y" -a "$ans" != "Y" -a "$ans" != "n" -a "$ans" != "N" -a "$ans" != "" ] do echo " Can 'disable' privileges be granted to all users? [y/n] y\b\c" read ans done if [ "$ans" = "n" -o "$ans" = "N" ] then echo echo " Client printer not added." exit 1 fi /bin/chmod u+s $LPDISABLE_PATH fi action="add" echo echo " Adding the device..." if [ "$clname" = "" -o "$prtype" = "" ] then echo echo " You must enter the client name and printer type," echo " as requested." echo echo " Client printer not added." exit 1 fi for i in config spool clipr standard do if [ "$clname" = "$i" ] then echo echo " The client printer name you selected is reserved." echo echo " Client printer not added." exit 1 fi done # # You can only set up one printer per client. # file=`grep "CLIENT=$clname$" $CONFIGDIR_PATH/* 2>/dev/null \ | cut -d: -f1` if [ -n "$file" ] then echo echo " There is already a printer shared on \"$clname\"." echo echo " Client printer not added." exit 1 fi notrunning=`$LPSTAT_PATH -r | grep not` if [ -n "$notrunning" ] then echo echo " The LP Spooler is not currently running." echo " It must be running in order to $action the client printer." echo ans=x while [ "$ans" != "y" -a "$ans" != "Y" -a "$ans" != "n" -a "$ans" != "N" -a "$ans" != "" ] do echo " Would you like to restart the Spooler now [y/n]? y\b\c" read ans done if [ "$ans" != "n" -a "$ans" != "N" ] then echo echo " The Spooler will be restarted... " $LPSCHED_PATH >/dev/null 2>/dev/null if [ "$?" -ne 0 ] then echo echo " Cannot restart the LP Spooler." echo echo " Follow the printer instructions in your System " echo " Administration manual to restart the Spooler " echo " and then $action the client printer." if [ "$action" = "add" ] then exit 1 fi exit 1 fi else echo echo " Follow the printer instructions in your System " echo " Administration manual to restart the Spooler " echo " and then $action the client printer." exit 1 fi fi # # See if the client name has already been used for a printer name. # If it hasn't been used, use the client name. Else, use a variation. # if [ "$prname" = "" ] then prname=`echo $clname | cut -c1-8` fi ( cd $LANMAN_PATH if [ "$action" = "add" ] then prtlist=`$LPSTAT_PATH -p 2>/dev/null | cut -d' ' -f2` for name in $prtlist do if [ "$name" = "$prname" ] then nameinuse=0 fi done # # If the LP Spooler name has already been used fail this operation # if [ "$nameinuse" = "0" ] then echo echo " The printer name \"$prname\" is already in use\c" echo " by the LP Spooler." echo " Please try this command again with a different printer\c" echo " name." echo >/tmp/nogo$$ 2>/dev/null exit 1 fi # # Try to create a client share that is associated with this printer. # This is where jobs will be queued for the client printer. # clshare=0 newname=`echo $prname | cut -c1-7` for ltr in z y x w v u t s r q p do $LMSHARE_PATH -f $newname$ltr 1 >/dev/null 2>/dev/null if [ "$?" -ne 0 ] then clshare=$newname$ltr break; fi done if [ "$clshare" = "0" ] then echo echo " Unable to create a client spool share using the sharename \c" echo " [$prname]." echo echo " Please select a printer name other than [$prname]." >/tmp/nogo$$ 2>/dev/null exit 1 fi # # Create client spool directory share and verify that it happened. # (Share it as READ-ONLY, Maxusers = 1.) ulimit $oulimit >/dev/null 2>/dev/null $LMSHARE_PATH -a -i >/dev/null 2>/dev/null </dev/null 2>/dev/null if [ "$?" -ne 0 ] then echo echo " Unable to share [$clshare]." echo echo " Please select a sharename other than [$prname]." >/tmp/nogo$$ 2>/dev/null exit 1 fi # # Create client spool directory for client printer to match that # specified in the share name above. # CLISHARE=$CLIPRDIR_PATH/$prname if [ ! -d "$CLISHARE" ] then mkdir $CLISHARE fi chmod 777 $CLISHARE chown $PUBLIC_DIR_OWNER $CLISHARE # # Grant access to client spool dir to Domain Users and Domain Guests. # $NET_PATH access c:$CLIPRDIR_PATH/$prname /grant "Domain Users":r "Domain Guests":r >/dev/null 2>/dev/null ulimit 512 JOBFILE=$CLISHARE/job if [ ! -f "$JOBFILE" ] then > $JOBFILE fi chmod 666 $JOBFILE chown $PUBLIC_FILE_OWNER $JOBFILE # # Create configuration directory for client printers if it doesn't exist. # Create the printers config file in it. # if [ ! -d $CONFIGDIR_PATH ] then mkdir $CONFIGDIR_PATH fi chown $PUBLIC_DIR_OWNER $CONFIGDIR_PATH echo "CLIENT=$clname" > $CONFIGDIR_PATH/$prname echo "#PRTYPE=$prtype" >> $CONFIGDIR_PATH/$prname echo "CLSHARE=$clshare" >> $CONFIGDIR_PATH/$prname # ensure everybody can read it chmod g+r $CONFIGDIR_PATH/$prname chmod o+r $CONFIGDIR_PATH/$prname else # make sure you didn't use a variation on the client name. if [ ! -f $CONFIGDIR_PATH/$prname ] then newname=`echo $clname | cut -c1-7` for num in 0 1 2 3 4 5 6 7 8 9 do newname=$newname$num if [ -f $CONFIGDIR_PATH/$newname ] then prname=$newname break; fi done fi fi # # Do the lp stuff... # Change LOGNAME so alerts come from the right source. # Null out the environmment to be sure things run right. # cd / so printer alerts won't cd to the current directory. # tmptype="" #if [ -f "$PORTSET_DATABASE_PATH" ] #then # tmptype=`grep "^$prtype " $PORTSET_DATABASE_PATH` #else # tmptype=`grep "^$prtype " $DATABASE_PATH` #fi if [ -n "$tmptype" ] then realtype=`echo $tmptype | cut -d' ' -f4` else realtype=$prtype fi if [ "$realtype" = "ps" ] then realtype="PS" fi cd / if [ "$action" = "add" ] then env - LOGNAME=lp OnChAnGe=1 $LPADMIN_PATH -p$prname \ -v/dev/null -i $TMPL_IFC_PATH \ -T$realtype -onobanner \ -fdeny:none -Fcontinue \ -o stty=-opost else # # Only make the change if the printer type is really being changed. # samepr=`grep "PRTYPE" $CONFIGDIR_PATH/$prname | grep $prtype` if [ -n "$samepr" ] then # The printer type is NOT being changed! >/tmp/nochg$$ 2>/dev/null else env - LOGNAME=lp OnChaAnGe=1 $LPADMIN_PATH -p$prname \ -T$realtype >/dev/null 2>/dev/null grep -v "PRTYPE" $CONFIGDIR_PATH/$prname > /tmp/$prname$$ echo "#PRTYPE=$prtype" >> /tmp/$prname$$ cp /tmp/$prname$$ $CONFIGDIR_PATH/$prname rm -f /tmp/$prname$$ fi fi if [ "$?" -ne 0 ] then echo if [ "$action" = "add" ] then echo " Unable to add \"$prname\" to LP administration." echo # # Undo what's been done. Since there's alot of stuff, just call # delcli ... # $DELCLIPR_PATH $prname "no" echo else echo " Unable to modify \"$prname\"." fi >/tmp/nogo$$ 2>/dev/null exit 1 else echo if [ "$action" = "add" ] then echo " The printer connected to the client PC named\c" echo " \"$clname\" has been added to the" echo " LP Spooler." echo " This device can be accessed by UNIX users via the\c" echo " \"lp -d$prname\"" echo " command." echo echo " To make the client print device available over the\c" echo " network you must: " echo " 1. Share a print queue that sends jobs to the device \c" echo "\"$prname\"." echo " 2. Activate the printer connected to the client PC\c" echo " named \"$clname\"." echo " (Consult your manual for more details.) " else if [ ! -f /tmp/nochg$$ ] then echo " The client printer named \"$prname\" has been changed." fi fi fi if [ "$action" = "add" ] then # # Accept and enable the printer. # $LPACCEPT_PATH $prname >>/dev/null 2>>/dev/null if [ "$?" -ne 0 ] then echo echo " Unable to get \"$prname\" to accept new jobs." echo echo " Follow the printer instructions in your System Administration manual" echo " to accept new jobs on your client printer \"$prname\" when you want" echo " it to become active." fi $LPENABLE_PATH $prname >>/dev/null 2>>/dev/null if [ "$?" -ne 0 ] then echo echo " Could not enable \"$prname\"." echo echo " Follow the printer instructions in your System Administration manual" echo " to accept new jobs on your client printer \"$prname\" when you want" echo " it to become active." fi fi if [ "$realtype" = "PS" ] then env - LOGNAME=lp OnChAnGe=1 $LPADMIN_PATH -p$prname -Ipostscript \ >/dev/null 2>/dev/null if [ $? -ne 0 ] then echo echo " The type of printer that you selected was postscript." echo echo " In order for jobs to print successfully on this printer," echo " you must set the content type for $prname to postscript." echo echo " Consult your System Administrator's Guide for the exact " echo " procedure." fi fi ) if [ -f /tmp/nogo$$ ] then /bin/rm -f /tmp/nogo$$ >/dev/null 2>/dev/null exit 1 fi echo if [ "$action" = "add" ] then echo " The addition of the client printer to LP is complete." echo else if [ ! -f /tmp/nochg$$ ] then echo " The change is now complete." else echo " The printer type for $clname was already $prtype." echo echo " Change aborted." /bin/rm -f /tmp/nochg$$ >/dev/null 2>/dev/null fi fi exit 0