1#!/bin/bash
2
3#####################################################################
4##
5##  smb.conf parser class
6##
7##  Copyright (C) Kurt Pfeifle <kpfeifle@danka.de>, 2004.
8##
9##  This program is free software; you can redistribute it and/or modify
10##  it under the terms of the GNU General Public License as published by
11##  the Free Software Foundation; either version 3 of the License, or
12##  (at your option) any later version.
13##
14##  This program is distributed in the hope that it will be useful,
15##  but WITHOUT ANY WARRANTY; without even the implied warranty of
16##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17##  GNU General Public License for more details.
18##
19##  You should have received a copy of the GNU General Public License
20##  along with this program; if not, see <http://www.gnu.org/licenses/>.
21##
22######################################################################
23
24######################################################################
25## Here an example calling sequence
26##!/bin/sh 
27## set -x
28## source VampireDriversFunctions
29
30##
31## Start local variables
32##
33## You must define these variable (possibly in a source script)
34
35## nthost=192.168.17.1
36## printeradmin=Administrator
37## adminpasswd=not4you
38
39## smbhost=knoppix
40## smbprinteradmin=knoppix
41## smbadminpasswd=knoppix
42##
43## End of local variables
44##
45
46##
47## functions to call
48##
49
50## fetchenumdrivers3listfromNThost      # repeat, if no success at first
51## createdrivernamelist 
52## createprinterlistwithUNCnames        # repeat, if no success at first
53## createmapofprinterstodriver
54## splitenumdrivers3list
55## makesubdirsforWIN40driverlist
56##  splitWIN40fileintoindividualdriverfiles
57##  fetchtheWIN40driverfiles
58##  uploadallWIN40drivers
59## makesubdirsforW32X86driverlist
60##  splitW32X86fileintoindividualdriverfiles
61##  fetchtheW32X86driverfiles
62##  uploadallW32X86drivers
63
64## End of example calling sequence
65######################################################################
66
67
68# -----------------------------------------------------------------------------
69# -----------------------------------------------------------------------------
70function vampiredrivers_readme()
71{
72echo -e " \n\
73############################################################################
74# 
75#    About the \"Vampire Printer Drivers\" set of functions....
76#    --------------------------------------------------------
77#
78# (C) Kurt Pfeifle <kpfeifle@danka.de>, 2004
79# License: GPL
80#
81# ------------------------------------------------------------
82#
83# Version: 0.8 (largely \"self-documented\" now, but not yet 
84#               completely -- if it ever will be....)
85#
86# Thanks a lot to Fabian Franz for helping me with some important
87# Bash-Scripting-Questions!
88#
89# This set of functions provides a framework to snatch all printer
90# driver info and related files from a Windows NT print server.
91# It then uploads and installs the drivers to a Samba server. (The
92# Samba server needs to be prepared for this: a valid [print$]
93# share, with write access set for a \"printer admin\".)
94#
95# The main commands used are \"smbclient\" and \"rpcclient\" combined
96# with \"grep\", \"sed\" and \"awk\". Probably a Perl or Python script
97# would be better suited to do this, mainly because we have to cope
98# with printer and driver names which are containing spaces in
99# them, so a lot of shell escaping is required to handle these.
100# Also, I am not very savvy in scripting, so I invented some very
101# obscure methods to work around my knowledge gaps. When I download
102# the driver files from the Windows NT box, I put all related driver
103# files into their own sub directory, using the same name as the
104# driver. Also, driver versions \"0\", \"2\" and \"3\" are placed in
105# further subdirectories.
106#
107# 
108# Known problems:  
109# --------------- 
110# 
111# 1) I found one printer driver containing a \"slash\" which is not 
112#    handled by this script: \"HP Color LaserJet 5/5M PS\". (There 
113#    are more of these in the wild, of course.)  -- The reason: I 
114#    didn't find a way to create a Unix directory containing a \"slash\".
115#    UPDATE: The script replaces the \"/\" with a \"_\" and also renames
116#    the drivername accordingly, when it is uploaded to the Samba 
117#    [print$] share....
118# 
119# 2) There is an unsolved problem in case a real file name deviates  
120#    in its case sensitive spelling from how it is displayed by the 
121#    \"rpcclient enumdrivers\" command. I encountered cases where 
122#    rpcclient displayed \"PS5UI.DLL\" as a file name, but \"smbclient 
123#    mget\" retrieved \"ps5ui.dll\" from the NT printserver, and the 
124#    driverinstallation failed because \"smbclient mput\" tried to put 
125#    \"PS5UI.DLL\" back onto the Samba server where UNIX only had
126#    \"ps5ui.dll\" available (which of course failed). -- UPDATE: this
127#    is now solved. All files are renamed now to the same 
128#    case-sensitive spelling as \"rpcclient ... enumdrivers 3\" 
129#    announces. This includes renaming into both, uppercase or
130#    lowercase, as the case might be....
131# 
132# 3) This script is probably not portable at all and relies on lots
133#    of Bash-isms.
134# 
135# 4) This script runs with rpcclient from Samba-3.0.2a (or later) only
136#    (because it uses the \"Version\" parameter for \"adddriver\").
137#
138# The following functions use a few external variables to log
139# into the 2 hosts. We suggest that you create a file which 
140# contains the variables and that you source that file at the
141# beginning of this script... 
142# 
143# #################################################################
144#
145# ntprinteradmin=Administrator   # any account on the NT host 
146#                                # with \"printer admin\" privileges
147# ntadminpasswd=not4you          # the \"printer admin\" password on 
148#                                # the NT print server
149# nthost=windowsntprintserverbox # the netbios name of the NT print 
150#                                # server
151#	
152# smbprinteradmin=knoppix        # an account on the Samba server 
153#                                # with \"printer admin\" privileges
154# smbadminpasswd=2secret4you     # the \"printer admin\" password on 
155#                                # the Samba server
156# smbhost=knoppix                # the netbios name of the Samba 
157#                                # print server
158#
159# #################################################################
160#
161# 
162# NOTE: these functions also work for 2 NT print servers: snatch all 
163# drivers from the first, and upload them to the second server (which 
164# takes the role of the \"Samba\" server). Of course they also work 
165# for 2 Samba servers: snatch all drivers from the first (which takes 
166# the role of the NT print server) and upload them to the second....
167# 
168# 
169#           ............PRESS \"q\" TO QUIT............" \
170|less
171}
172
173
174#set -x
175
176
177# -----------------------------------------------------------------------------
178# ----------- print a little help... ------------------------------------------
179# -----------------------------------------------------------------------------
180
181function helpwithvampiredrivers()
182{
183if stringinstring help $@ ; then
184helpwithvampiredrivers ;
185else
186	echo "  ";
187	echo "  1. Run the functions of this script one by one.";
188	echo "  ";
189	echo "  2. List all functions with the \"enumallfunctions\" call.";
190	echo "  ";
191	echo "  3. After each functions' run, check if it completed successfully.";
192	echo "  ";
193	echo "  4. For each function, you can ask for separate help by typing";
194	echo "     \"<functionname> --help\"."
195	echo "  ";
196	echo "  5. Often network conditions prevent the MS-RPC calls"
197	echo "     implemented by Samba to succeed at the first attempt."
198	echo "     You may have more joy if you try more than once or twice....";
199	echo "  ";
200	echo "  6. I can not support end-users who have problems with this script."
201	echo "     However, we are available for paid, professional consulting,"
202	echo "     training and troubleshooting work.";
203	echo "  ";
204	echo "  ";
205fi
206}
207
208# -----------------------------------------------------------------------------
209# ----------- enumerate all builtin functions... ------------------------------
210# -----------------------------------------------------------------------------
211function enumallfunctions()
212{
213if stringinstring help $@ ; then
214helpwithvampiredrivers ;
215else
216	echo " "
217	echo " "
218	echo "--> Running now function enumallfunctions()..."
219	echo "=============================================="
220	echo -e " \n\
221   
222       NOTE: run the listed functions in the same order as listed below. 
223   
224    EXAMPLE: \"knoppix@ttyp6[knoppix]$ helpwithvampiredrivers\"
225   
226       HELP: the \"--help\" parameter prints usage hints regarding a function.
227   	 
228    EXAMPLE: \"knoppix@ttyp6[knoppix]$ fetchenumdrivers3listfromNThost --help\"      
229
230   
231   function vampiredrivers_readme()
232   function enumallfunctions() 
233   function helpwithvampiredrivers()
234   function fetchenumdrivers3listfromNThost()  # repeat, if no success at first
235   function createdrivernamelist() 
236   function createprinterlistwithUNCnames()    # repeat, if no success at first
237   function createmapofprinterstodrivers() 
238   function splitenumdrivers3list()
239   function makesubdirsforW32X86driverlist()
240     function splitW32X86fileintoindividualdriverfiles()
241     function fetchallW32X86driverfiles()
242     function uploadallW32X86drivers()
243   function makesubdirsforWIN40driverlist()
244     function splitWIN40fileintoindividualdriverfiles()
245     function fetchallWIN40driverfiles()
246     function uploadallWIN40drivers()"
247   echo " "
248fi
249}
250
251# this is a helperfunction (Thanks to Fabian Franz!)
252function stringinstring()
253{
254	case "$2" in *$1*) 
255		return 0 
256		;;
257	esac 
258		return 1
259}
260
261# -----------------------------------------------------------------------------
262# ----------- Create an "enumprinters 3" list --------------------- -----------
263# -----------------------------------------------------------------------------
264#
265
266function helpwithfetchenumdrivers3listfromNThost()
267{
268echo -e " \n\
269################################################################################
270# 
271#                About fetchenumdrivers3listfromNThost()....
272#                -------------------------------------------
273#
274# PRECONDITIONS: 1) This function expects write access to the current directory. 
275#		 2) This function expects to have the '\$nthosts', 
276#		    '\$ntprinteradmin' and '\$ntadminpasswd' variables set to 
277#		    according values.
278#
279# WHAT IT DOES: This function connects to the '\$nthost' (using the credentials
280#		'\$ntprinteradmin' with '\$ntadminpasswd', retrieves a list of 
281#		drivers (with related file names) from that host, and saves the
282#		list under the name of '\${nthost}/enumdrivers3list.txt' (ie. it
283#		also creates the '\$nthost' subdirectory in the current one). It
284#		further prints some more info to stdout.
285#
286# IF IT DOESN'T WORK: It may happen that the function doesn't work at the first
287#		      time (there may be a connection problem). Just repeat a
288#		      few times. It may work then. You will recognize if it 
289#		      does.
290#
291# HINT: The current values: 'nthost'=\"$nthost\"
292#			    'ntprinteradmin'=\"$ntprinteradmin\"
293#			    'ntadminpasswd'=<not shown here, check yourself!>
294# 
295################################################################################"
296echo " "
297}
298
299# -----------------------------------------------------------------------------
300
301function fetchenumdrivers3listfromNThost()
302{
303if stringinstring help $@ ; then
304helpwithfetchenumdrivers3listfromNThost;
305else
306	echo " "
307	echo " "
308	echo "--> Running now function fetchenumdrivers3listfromNThost"
309	echo "========================================================"
310	[ -d ${nthost} ] || mkdir "${nthost}";
311	rpcclient -U${ntprinteradmin}%${ntadminpasswd} -c 'enumdrivers 3' ${nthost} \
312	| sed  -e '/^.*Driver Name: \[.*\]/ y/\//_/' \
313	| tee \
314	${nthost}/enumdrivers3list.txt;
315	
316	NUMBEROFDIFFERENTDRIVERNAMES=$( grep "Driver Name:" ${nthost}/enumdrivers3list.txt \
317	| sort -f \
318	| uniq \
319	| wc -l );
320
321	echo " ";
322	echo "--> Finished in running function fetchenumdrivers3listfromNThost....";
323	echo "===================================================================="
324	echo "NUMBEROFDIFFERENTDRIVERNAMES retrieved from \"${nthost}\" is $NUMBEROFDIFFERENTDRIVERNAMES".;
325	echo "  -->  If you got \"0\" you may want to try again. <---";
326	echo "================================================================";
327	echo " ";
328	enumdrivers3list=`cat ${nthost}/enumdrivers3list.txt`;
329fi
330}
331
332
333# -----------------------------------------------------------------------------
334# ----------- Create a list of all available drivers installed ----------------
335# ------------------------on the NT print server-------------------------------
336# -----------------------------------------------------------------------------
337#
338
339function helpwithcreatedrivernamelist()
340{
341echo -e " \n\
342################################################################################
343# 
344#                About createdrivernamelist()...
345#                -------------------------------
346#
347# PRECONDITIONS: 1) This function expects to find the subdirectory '\$nthost' 
348#		    and the file '\${nthost}/enumdrivers3list.txt' to exist.
349#		 2) This function expects to have the '\$nthosts' variable set 
350#		    to an according value.
351#
352# WHAT IT DOES: This function dissects the '\${nthost}/enumdrivers3list.txt' 
353#		and creates other textfiles from its contents:
354#		- '\${nthost}/drvrlst.txt'
355#		- '\${nthost}/completedriverlist.txt'
356#		and further prints some more info to stdout.
357#
358# HINT: The current value: 'nthost'=\"$nthost\"
359# 
360################################################################################"
361}
362
363# -----------------------------------------------------------------------------
364
365function createdrivernamelist()
366{
367if stringinstring help $@ ; then
368helpwithcreatedrivernamelist;
369else
370	echo " ";
371	echo " ";
372	echo "--> Running now function createdrivernamelist....";
373	echo "=================================================";
374	cat ${nthost}/enumdrivers3list.txt \
375	| grep "Driver Name:" \
376	| awk -F "[" '{ print $2 }' \
377	| awk -F "]" '{ print $1 }' \
378	| sort -f \
379	| uniq \
380	| tr / _ \
381	| sed -e 's/$/\"/' -e 's/^ */\"/' \
382	| tee \
383	${nthost}/drvrlst.txt;
384	drvrlst=$(echo ${nthost}/drvrlst.txt);
385	
386	cat ${nthost}/enumdrivers3list.txt \
387	| grep "Driver Name:" \
388	| awk -F "[" '{ print $2 }' \
389	| awk -F "]" '{ print $1 }' \
390	| sort -f \
391	| uniq \
392	| sed -e 's/$/\"/' \
393	| cat -n \
394	| sed -e 's/^ */DRIVERNAME/' -e 's/\t/\="/' \
395	| tee \
396	${nthost}/completedriverlist.txt;
397	
398	NUMBEROFDRIVERS=`cat ${nthost}/completedriverlist.txt| wc -l`;
399	echo " ";
400	echo "--> Finished in running function createdrivernamelist....";
401	echo "==============================================================================="
402	echo "NUMBEROFDRIVERS retrieve-able from \"${nthost}\" is $NUMBEROFDRIVERS".;
403	echo "  -->  If you got \"0\" you may want to run \"fetchenumdrivers3listfromNThost\""
404	echo "       again. <---";
405	echo "===============================================================================";
406	echo " ";
407	driverlist=`cat ${nthost}/completedriverlist.txt`;
408
409	# alternative method suggested by Fabian Franz:
410	# | awk 'BEGIN {n=1} { print "DRIVERNAME"n"=\""$0"\""; n=n+1 } '
411fi
412}
413
414
415
416# -----------------------------------------------------------------------------
417# ----------- Create a list of all available printers -------------------------
418# -----------------------------------------------------------------------------
419#
420
421function helpwithcreateprinterlistwithUNCnames()
422{
423echo -e " \n\
424################################################################################
425# 
426#                About createprinterlistwithUNCnames()...
427#                ----------------------------------------
428#
429# PRECONDITIONS: 1) This function expects write access to the current directory. 
430#		 2) This function expects to have the '\$nthost', 
431#		    '\$ntprinteradmin' and '\$ntadminpasswd' variables set to
432#		    according values.
433#
434# WHAT IT DOES: This function connects to the '\$nthost' (using the credentials
435#		'\$ntprinteradmin' with '\$ntadminpasswd'), retrieves a list of
436#		printqueues (with associated driver names) from that host (with
437#		the help of the 'rpcclient ... enumprinters' utility, and saves
438#		it under name and path '\${nthost}/printerlistwithUNCnames.txt'
439#		(ie. it also creates the '\$nthost' subdirectory in the current 
440#		one). It further prints some more info to stdout.
441#
442# IF IT DOESN'T WORK: It may happen that the function doesn't work at the first
443#		      time (there may be a connection problem). Just repeat a
444#		      few times. It may work then. You will recognize if it does.
445#
446# HINT: The current values: 'nthost'=\"$nthost\"
447#			    'ntprinteradmin'=\"$ntprinteradmin\"
448#			    'ntadminpasswd'=<not shown here, check yourself!>
449# 
450################################################################################"
451}
452
453# -----------------------------------------------------------------------------
454
455function createprinterlistwithUNCnames()
456{
457if stringinstring help $@ ; then
458helpwithcreateprinterlistwithUNCnames ;
459else
460	[ -d ${nthost} ] || mkdir -p ${nthost};
461	echo " "
462	echo " "
463	echo " "
464	echo "--> Running now function createprinterlistwithUNCnames()...."
465	echo "============================================================"
466	rpcclient -U"${ntprinteradmin}%${ntadminpasswd}" -c 'enumprinters' ${nthost} \
467	| grep "description:" \
468	| awk -F "[" '{ print $2 }' \
469	| awk -F "]" '{ print $1 }' \
470	| sort -f \
471	| uniq \
472	| tee \
473	${nthost}/printerlistwithUNCnames.txt;
474
475	NUMBEROFPRINTERS=`cat ${nthost}/printerlistwithUNCnames.txt| wc -l`;
476	echo " ";
477	echo "--> Finished in running function createprinterlistwithUNCnames....";
478	echo "=========================================================================="
479	echo "NUMBEROFPRINTERS retrieved from \"${nthost}\" is $NUMBEROFPRINTERS".;
480	echo "  -->  If you got \"0\" you may want to try again. <---";
481	echo "==========================================================================";
482	echo " ";
483	printerlistwithUNCnames=`cat ${nthost}/printerlistwithUNCnames.txt`;
484fi
485}
486
487
488# -----------------------------------------------------------------------------
489# ----------- Create a list of all printers which have (no) drivers -----------
490# -----------------------------------------------------------------------------
491#
492
493function helpwithcreatemapofprinterstodrivers()
494{
495echo -e " \n\
496################################################################################
497# 
498#                About createmapofprinterdrivers()...
499#                ------------------------------------
500#
501# PRECONDITIONS: 1) This function expects to find a subdirectory '\$nthost' and
502#		    the file '\${nthost}/printerlistwithUNCnames.txt' to exist.
503#		 2) This functions expects to have the '\$nthosts' variable set 
504#		    to an according value.
505#
506# WHAT IT DOES: This function dissects '\${nthost}/printerlistwithUNCnames.txt' 
507#		and creates some other textfiles from its contents:
508#		- '\${nthost}/allprinternames.txt'
509#		- '\${nthost}/alldrivernames.txt'
510#		- '\${nthost}/allnonrawprinters.txt'
511#		- '\${nthost}/allrawprinters.txt'
512#		- '\${nthost}/printertodrivermap.txt'
513#		and further prints some more info to stdout.
514#
515# HINT: You currently have defined: 'nthost'=\"$nthost\", which resolves above
516#	mentioned paths to:
517#			    - '${nthost}/allprinternames.txt'
518#			    - '${nthost}/alldrivernames.txt'
519#			    - '${nthost}/allnonrawprinters.txt'
520#			    - '${nthost}/allrawprinters.txt'
521#			    - '${nthost}/printertodrivermap.txt'
522#               
523################################################################################"
524}
525
526# -----------------------------------------------------------------------------
527
528function createmapofprinterstodrivers()
529{
530if stringinstring help $@ ; then
531helpwithcreatemapofprinterstodrivers ;
532else
533	echo " "
534	echo " "
535	echo "--> Running now function createmapofprinterstodrivers()...."
536	echo "==========================================================="
537	echo " "
538	echo " "
539	echo "ALL PRINTERNAMES:"
540	echo "================="
541	echo " "
542	cat ${nthost}/printerlistwithUNCnames.txt \
543	| awk -F "\\" '{ print $4 }' \
544	| awk -F "," '{print $1}' \
545	| sort -f \
546	| uniq \
547	| tee \
548	${nthost}/allprinternames.txt; 
549	
550	echo " "
551	echo " "
552	echo "ALL non-RAW PRINTERS:"
553	echo "====================="
554	echo " "
555	cat ${nthost}/printerlistwithUNCnames.txt \
556	| grep -v ",," \
557	| awk -F "\\" '{ print $4 }' \
558	| awk -F "," '{print $1}' \
559	| sort -f \
560	| uniq \
561	| tee \
562	${nthost}/allnonrawprinters.txt; 
563	
564	echo " "
565	echo " "
566	echo "ALL RAW PRINTERS:"
567	echo "================"
568	echo " "
569	cat ${nthost}/printerlistwithUNCnames.txt \
570	| grep ",," \
571	| awk -F "\\" '{ print $4 }' \
572	| awk -F "," '{print $1}' \
573	| sort -f \
574	| uniq \
575	| tee \
576	${nthost}/allrawprinters.txt; 
577	
578	echo " "
579	echo " "
580	echo "THE DRIVERNAMES:"
581	echo "================"
582	cat ${nthost}/printerlistwithUNCnames.txt \
583	| awk -F "," '{print $2 }' \
584	| grep -v "^$" \
585	| tee \
586	${nthost}/alldrivernames.txt;
587
588	echo " "
589	echo " "
590	echo "THE PRINTER-TO-DRIVER-MAP-FOR-non-RAW-PRINTERS:"
591	echo "==============================================="
592	cat ${nthost}/printerlistwithUNCnames.txt \
593	| awk -F "\\" '{ print $4 }' \
594	| awk -F "," '{ print "\"" $1 "\":\"" $2 "\"" }' \
595	| grep -v ":\"\"$" \
596	| tee \
597	${nthost}/printertodrivermap.txt 
598	echo -e "##########################\n#  printer:driver  #" >> ${nthost}/printertodrivermap.txt
599fi
600}
601
602
603# -----------------------------------------------------------------------------
604# ----------- Create a list of all printers which have drivers ----------------
605# -----------------------------------------------------------------------------
606#
607
608function helpwithgetdrivernamelist()
609{
610echo -e " \n\
611################################################################################
612# 
613#                About getdrivernamelist()...
614#                ----------------------------
615#
616# PRECONDITIONS: 1) This function expects to find the subdirectory '\$nthost\'
617#		    otherwise it creates it...
618#
619# WHAT IT DOES: This function creates the '\${nthost}/printernamelist.txt'
620#		and also prints it to <stdout>. To do so, it must contact the
621#		'\$nthost' via rpcclient (which in turn needs '\$ntprinteradmin'
622#		'\$ntadminpasswd' to log in....).
623# 
624# HINT: The current values: 'nthost'=\"$nthost\"
625#			    'ntprinteradmin'=\"$ntprinteradmin\"
626#			    'ntadminpasswd'=<not shown here, check yourself!>
627#       which resolves above mentioned path to:
628#				    - '${nthost}/printernamelist.txt'
629#               
630################################################################################"
631}
632
633# -----------------------------------------------------------------------------
634
635function getdrivernamelist()
636{
637if stringinstring $@ ; then
638helpwithgetdrivernamelist ;
639else
640	[ -d ${nthost} ] || mkdir -p ${nthost};
641	echo " "
642	echo " "
643	echo "--> Running now function getdrivernamelist()...."
644	echo "================================================"
645	rpcclient -U${ntprinteradmin}%${ntadminpasswd} -c 'enumprinters' ${nthost} \
646	| grep "description:" \
647	| grep -v ",," \
648	| awk -F "," '{ print $2 }' \
649	| sort -f \
650	| uniq \
651	| tee \
652	${nthost}/drivernamelist.txt
653fi
654}
655
656
657# -----------------------------------------------------------------------------
658# ----------- Split the driverfile listing between the architectures ----------
659# -----------------------------------------------------------------------------
660#
661
662function helpwithsplitenumdrivers3list()
663{
664echo -e " \n\
665################################################################################
666# 
667#                About splitenumdrivers3list()...
668#                --------------------------------
669#
670# PRECONDITIONS: 1) This function expects write access to the current directory
671#		    and its subdirs '\$nthost/*'. 
672#		 2) This function expects to have the '\$nthost' variable set to
673#		    the according value.
674# 
675# WHAT IT DOES: This function dissects the '\$nthost/enumdrivers3list.txt' 
676#		(using "sed", "cat", "awk" and "grep"). It splits the list up
677#		into two different files representing a complete list of drivers
678#		and files for each of the 2 supported architectures. It creates 
679#		'\${nthost}/W32X86/${nthost}-enumdrivers3list-NTx86.txt'
680#		and '\${nthost}/WIN40/${nthost}-enumdrivers3list-WIN40.txt'.
681# 
682# IF IT DOESN'T WORK: The function "fetchenumdrivers3listfromNThost" may not 
683#		      have been run successfully. This is a precondition for
684#		      the current function.
685#
686# HINT: You currently have defined: 'nthost'=\"$nthost\", which resolves above 
687# mentioned paths to:
688#		      - '${nthost}/WIN40/${nthost}-enumdrivers3list-NTx86.txt'
689#		      - '${nthost}/W32X86/${nthost}-enumdrivers3list-NTx86.txt'
690#
691################################################################################"
692}
693
694# -----------------------------------------------------------------------------
695
696function splitenumdrivers3list()
697{
698if stringinstring help $@ ; then
699helpwithsplitenumdrivers3list ;
700else
701	echo " "
702	echo " "
703	echo "--> Running now function splitenumdrivers3list()...."
704	echo "===================================================="
705	
706	[ -d ${nthost}/WIN40 ]  || mkdir -p ${nthost}/WIN40;
707	[ -d ${nthost}/W32X86 ] || mkdir -p ${nthost}/W32X86;
708	
709	cat ${nthost}/enumdrivers3list.txt \
710	| sed -e '/^\[Windows NT x86\]/,$ d' \
711	| tee \
712	${nthost}/WIN40/${nthost}-enumdrivers3list-WIN40.txt ;
713	
714	cat ${nthost}/WIN40/${nthost}-enumdrivers3list-WIN40.txt \
715	| grep Version \
716	| sort -f \
717	| uniq \
718	| awk -F "[" '{ print $2 }' \
719	| awk -F "]" '{ print $1 }' \
720	| tee ${nthost}/WIN40/availableversionsWIN40.txt ;
721
722#	cd ${nthost}/WIN40/ ;
723#	mkdir $( cat availableversionsWIN40.txt ) 2> /dev/null ;
724#	cd - ;
725	
726	cat ${nthost}/enumdrivers3list.txt \
727	| sed -e '/^\[Windows NT x86\]/,$! d' \
728	| tee \
729	${nthost}/W32X86/${nthost}-enumdrivers3list-NTx86.txt ;
730	
731	cat ${nthost}/W32X86/${nthost}-enumdrivers3list-NTx86.txt \
732	| grep Version \
733	| sort -f \
734	| uniq \
735	| awk -F "[" '{ print $2 }' \
736	| awk -F "]" '{ print $1 }' \
737	| tee ${nthost}/W32X86/availableversionsW32X86.txt ;
738
739#	cd ${nthost}/W32X86/ ;
740#	mkdir $( cat availableversionsW32X86.txt ) 2> /dev/null ;
741#	cd - ;
742fi
743}
744
745
746# -----------------------------------------------------------------------------
747# ---------- Make subdirs in ./${sambahost}/WIN40/ for each driver.... -------
748# -----------------------------------------------------------------------------
749#
750
751function helpwithmakesubdirsforWIN40driverlist()
752{
753echo -e " \n\
754################################################################################
755# 
756# About makesubdirsforWIN40driverlist() and makesubdirsforWIN40driverlist ()...
757# -----------------------------------------------------------------------------
758#
759# PRECONDITIONS: 1) These functions expect write access to the current directory
760#		 2) These functions expect to have the '\$nthost' variable set 
761#		    to the according value.
762#		 3) These functions expect to find the two files
763#		    '\${nthost}/WIN40/\${nthost}-enumdrivers3list-WIN40.txt' and
764#		    '\${nthost}/W32X86/\${nthost}-enumdrivers3list-NTx86.txt' to
765#		    work on.
766#
767# WHAT IT DOES: These functions dissect the '$nthost/enumdrivers3list.txt' 
768#		(using "sed", "cat", "awk" and "grep"). They split the input 
769#		files up into individual files representing driver(version)s and
770#		create appropriate subdirectories for each driver and version 
771#		underneath './\$nthost/<architecture>'. They use the drivernames
772#		(including spaces) for the directory names. ("/" -- slashes -- 
773#		in drivernames are converted to underscores).
774#
775# IF IT DOESN'T WORK: The function "fetchenumdrivers3listfromNThost" and 
776#		      consecutive ones may not have been run successfully. This
777#		      is a precondition for the current function.
778#
779# HINT: You currently have defined: 'nthost'=\"$nthost\", which resolves above
780#	mentioned paths to:
781#		     - '\${nthost}/WIN40/\${nthost}-enumdrivers3list-NTx86.txt'
782#		     - '\${nthost}/W32X86/\${nthost}-enumdrivers3list-NTx86.txt'
783# 
784################################################################################
785#           ............PRESS \"q\" TO QUIT............" \
786|less
787}               
788
789# -----------------------------------------------------------------------------
790
791function makesubdirsforWIN40driverlist()
792{	
793if stringinstring help $@ ; then
794helpwithmakesubdirsforWIN40driverlist ;
795else
796	cat ${nthost}/WIN40/${nthost}-enumdrivers3list-WIN40.txt \
797	| grep "Driver Name:" \
798	| awk -F "[" '{ print $2 }' \
799	| awk -F "]" '{ print $1 }' \
800	| sort -f \
801	| uniq \
802	| tr / _ \
803	| sed -e 's/$/\"/' \
804	| sed -e 's/^/mkdir -p '"\"${nthost}"'\/WIN40\//' \
805	| tee \
806	${nthost}/makesubdirsforWIN40driverlist.txt;
807	
808	sh -x ${nthost}/makesubdirsforWIN40driverlist.txt;
809
810#	rm ${nthost}/makesubdirsforWIN40driverlist.txt;
811fi
812}
813
814
815# -----------------------------------------------------------------------------
816# ---------- Make subdirs in ./${sambahost}/W32X86/ for each driver.... -------
817# -----------------------------------------------------------------------------
818#
819
820function makesubdirsforW32X86driverlist()
821{	
822if stringinstring help $@ ; then
823helpwithvampiredrivers ;
824else
825	cat ${nthost}/W32X86/${nthost}-enumdrivers3list-NTx86.txt \
826	| grep "Driver Name:" \
827	| awk -F "[" '{ print $2 }' \
828	| awk -F "]" '{ print $1 }' \
829	| sort -f \
830	| uniq \
831	| tr / _ \
832	| sed -e 's/$/\"/' \
833	| sed -e 's/^ */mkdir '\""${nthost}"'\/W32X86\//' \
834	| tee \
835	${nthost}/makesubdirsforW32X86driverlist.txt;
836	
837	sh -x ${nthost}/makesubdirsforW32X86driverlist.txt;
838
839#	rm ${nthost}/makesubdirsforW32X86driverlist.txt;
840fi
841}
842
843
844
845
846# -----------------------------------------------------------------------------
847# ----------- Split the WIN40 driverfile listing of each architecture ---------
848# ------------------------ into individual drivers ----------------------------
849# -----------------------------------------------------------------------------
850#
851
852function helpwithmakesubdirsforWIN40driverlist()
853{
854echo -e " \n\
855################################################################################
856# 
857#	    About splitWIN40fileintoindividualdriverfiles() and 
858#	       splitW32X86fileintoindividualdriverfiles()...
859#           ---------------------------------------------------
860#
861# PRECONDITIONS: 1) These functions expect write access to the current directory
862#		    and its subdirs '\$nthost/*/'. 
863#		 2) These functions expect to have the '\$nthost' variable set
864#		    to the according value.
865#		 3) These functions expect to find the two files
866#		    '\${nthost}/WIN40/\${nthost}-enumdrivers3list-WIN40.txt' and
867#		    '\${nthost}/W32X86/\${nthost}-enumdrivers3list-NTx86.txt' to
868#		    work on.
869#
870# WHAT IT DOES: 1) These functions create a directory for each printer driver. 
871#		   The directory name is identical to the driver name. 
872#		2) For each supported driver version (\"0\", \"2\" and \"3\") it
873#		   creates a subdirectory as required underneath 
874#		   './\$nthost/<architecture>'. 
875#		3) The directories use the drivernames (including spaces) for 
876#		   their names. ("/" - slashes - in drivernames are converted to
877#		   underscores).
878#		4) In each subdirectory they dissect the original 
879#		   '\$nthost/enumdrivers3list.txt' (using "sed", "cat", "awk" 
880#		   and "grep") and store that part describing the related driver
881#		   (under the name \"driverfilesversion.txt\". 
882#		5) For each driver the files \"Drivername\", \"DriverPath\", 
883#		   \"Drivername\", \"Configfile\", \"Helpfile\", \"AllFiles\" and
884#		   \"Dependentfilelist\" are stored in the according directory
885#		   which hold contend that is used by other (downstream) 
886#		   functions.
887#		6) It creates a file named \"AllFilesIAskFor\" which holds the 
888#		   case sensitive names of files it wanted to download. It also 
889#		   creates a file named \"AllFilesIGot\" which holds the case 
890#		   sensitive spelling of the downloaded files. (Due to 
891#		   Microsoft's ingenious file naming tradition, you may have 
892#		   asked for a \"PS5UI.DLL\" but gotten a \"ps5ui.dll\".
893#		7) The 2 files from 6) will be later compared with the help of
894#		   the \"sdiff\" utility to decide how to re-name the files so
895#		   that the subsequent driver upload command's spelling 
896#		   convention is met.
897#
898# IF IT DOESN'T WORK: The function \"fetchenumdrivers3listfromNThost\" and 
899#		      consecutive ones may not have been run successfully. This
900#		      is a precondition for the current function.
901#
902# HINT: You currently have defined: 'nthost'=\"$nthost\".
903# 
904################################################################################
905#           ............PRESS \"q\" TO QUIT............" \
906|less
907}               
908
909# -----------------------------------------------------------------------------
910
911function splitWIN40fileintoindividualdriverfiles()
912{
913if stringinstring help $@ ; then
914helpwithmakesubdirsforWIN40driverlist ;
915else
916	echo " "
917	echo " "
918	echo "--> Running now function splitWIN40fileintoindividualdriverfiles()..."
919	echo "====================================================================="
920	
921	for i in ${nthost}/WIN40/*/; do
922		CWD1="$( pwd )" ;
923		cd "${i}" ;
924	echo " "
925	echo " "
926	echo " ###########################################################################################"
927	echo " "
928	echo "   Next driver is \"$( basename "$( pwd)" )\""
929	echo " "
930	echo " ###########################################################################################"
931
932#####		echo "yes" | cp -f ../../../${nthost}/WIN40/${nthost}-enumdrivers3list-WIN40.txt . 2> /dev/null ;
933		ln -s -f ../${nthost}-enumdrivers3list-WIN40.txt ${nthost}-enumdrivers3list-WIN40.lnk ;
934
935	tac ${nthost}-enumdrivers3list-WIN40.lnk \
936	| sed -e '/'"$(basename "$(echo "$PWD")")"'/,/Version/ p' -n \
937	| grep Version  \
938	| uniq \
939	| awk -F "[" '{ print $2 }' \
940	| awk -F "]" '{ print "mkdir \"" $1 "\"" }' \
941	| tee mkversiondir.txt ;
942
943	sh mkversiondir.txt 2> /dev/null ;
944
945	cat ${nthost}-enumdrivers3list-WIN40.lnk \
946	| sed -e '/\['"$(basename "$(echo "$PWD")")"'\]/,/Monitor/ w alldriverfiles.txt' -n ;
947
948	for i in */; do 
949	CWD2="$( pwd )" ;
950	cd "${i}";
951	echo "yes" | cp ../alldriverfiles.txt . 2> /dev/null ;
952
953	cat alldriverfiles.txt \
954	| egrep '(\\'"$(basename "$( pwd )")"'\\|Driver Name)' \
955	| tee driverfilesversion.txt ;
956
957	Drivername=$( grep "Driver Name:" driverfilesversion.txt \
958	| awk -F "[" '{ print $2 }' \
959	| awk -F "]" '{ print $1 }' \
960	| sort -f \
961	| uniq \
962	| tee Drivername ) ;
963
964	DriverPath=$( grep "Driver Path:" driverfilesversion.txt \
965	| awk -F "[" '{ print $2 }' \
966	| awk -F "]" '{ print $1 }' \
967	| awk -F "WIN40" '{ print $2 }' \
968	| awk -F "\\" '{ print $3 }'  \
969	| sort -f \
970	| uniq ) ;
971	echo "${DriverPath}" \
972	| tee DriverPath ;
973
974	Datafile=$( grep "Datafile:" driverfilesversion.txt \
975	| awk -F "[" '{ print $2 }' \
976	| awk -F "]" '{ print $1 }' \
977	| awk -F "WIN40" '{ print $2 }' \
978	| awk -F "\\" '{ print $3 }' \
979	| sort -f \
980	| uniq  ) ;
981	echo "${Datafile}" \
982	| tee Datafile ;
983
984	Configfile=$( grep "Configfile:" driverfilesversion.txt \
985	| awk -F "[" '{ print $2 }' \
986	| awk -F "]" '{ print $1 }' \
987	| awk -F "WIN40" '{ print $2 }' \
988	| awk -F "\\" '{ print $3 }'  \
989	| sort -f \
990	| uniq ) ;
991	echo "${Configfile}" \
992	| tee Configfile ;
993
994	Helpfile=$( grep "Helpfile:" driverfilesversion.txt \
995	| awk -F "[" '{ print $2 }' \
996	| awk -F "]" '{ print $1 }' \
997	| awk -F "WIN40" '{ print $2 }' \
998	| awk -F "\\" '{ print $3 }'  \
999	| sort -f \
1000	| uniq ) ;
1001	echo "${Helpfile}" \
1002	| tee Helpfile ;
1003
1004	Dependentfilelist=$( grep "Dependentfiles:" driverfilesversion.txt \
1005	| awk -F "[" '{ print $2 }' \
1006	| awk -F "]" '{ print $1 }' \
1007	| awk -F "WIN40" '{ print $2 }' \
1008	| awk -F "\\" '{ print $3 }'  \
1009	| sort -f \
1010	| uniq ) ;
1011
1012	Dependentfiles=$( echo $Dependentfilelist \
1013	| sed -e 's/ /,/g ' ) ;
1014
1015	echo "${Dependentfiles}" \
1016	| tee Dependentfiles
1017
1018	AllFiles=$( echo ${Dependentfilelist}; echo ${Helpfile}; echo ${Configfile}; echo ${Datafile}; echo ${DriverPath} ); 
1019	
1020	echo "${AllFiles}" \
1021	| sort -f \
1022	| uniq \
1023	| tee AllFiles ;
1024
1025	for i in $( cat AllFiles ); do echo ${i}; done \
1026	| sort -f \
1027	| uniq \
1028	| tee AllFilesIAskFor ;
1029
1030	cd "${CWD2}" 1> /dev/null ;
1031	done
1032
1033#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1034#	-c "adddriver \"${Architecture}\" \"${DriverName}:${DriverPath}:${Datafile}:${Configfile}:${Helpfile}:NULL:RAW:${Dependentfiles}\" ${Version}" \ ${smbhost}
1035
1036#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1037#	-c "setdriver \"${printername}\" \"${DriverName}\"" \
1038#	${smbhost}
1039#
1040#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1041#	-c "setprinter \"${printername}\" \"Driver was installed and set via MS-RPC (utilized by Kurt Pfeifle\'s set of \"Vampire Printerdrivers\" scripts from Linux)\"" \
1042#	${smbhost}
1043
1044	cd "${CWD1}" 1> /dev/null ;
1045	done;
1046fi
1047}
1048
1049
1050
1051
1052# -----------------------------------------------------------------------------
1053# ---------- Split the W32X86 driverfile listing of each architecture ---------
1054# ------------------------ into individual drivers ----------------------------
1055# -----------------------------------------------------------------------------
1056#
1057
1058function splitW32X86fileintoindividualdriverfiles()
1059{
1060if stringinstring help $@ ; then
1061helpwithmakesubdirsforWIN40driverlist ;
1062else
1063	echo " "
1064	echo " "
1065	echo "--> Running now function splitW32X86fileintoindividualdriverfiles()..."
1066	echo "======================================================================"
1067	
1068	for i in ${nthost}/W32X86/*/; do
1069		CWD1="$( pwd )" ;
1070		cd "${i}" ;
1071	echo " "
1072	echo " "
1073	echo " ###########################################################################################"
1074	echo " "
1075	echo "   Next driver is \"$( basename "$( pwd)" )\""
1076	echo " "
1077	echo " ###########################################################################################"
1078
1079######		echo "yes" | cp -f ../../../${nthost}/W32X86/${nthost}-enumdrivers3list-NTx86.txt . 2> /dev/null ;
1080		ln -s -f ../${nthost}-enumdrivers3list-NTx86.txt ${nthost}-enumdrivers3list-NTx86.lnk ;
1081
1082	tac ${nthost}-enumdrivers3list-NTx86.lnk \
1083	| sed -e '/'"$(basename "$(echo "$PWD")")"'/,/Version/ p' -n \
1084	| grep Version \
1085	| uniq \
1086	| awk -F "[" '{ print $2 }' \
1087	| awk -F "]" '{ print "mkdir \"" $1 "\"" }' \
1088	| tee mkversiondir.txt ;
1089
1090	sh mkversiondir.txt 2> /dev/null ;
1091
1092	cat ${nthost}-enumdrivers3list-NTx86.lnk \
1093	| sed -e '/\['"$(basename "$(echo "$PWD")")"'\]/,/Monitor/ w alldriverfiles.txt' -n ;
1094
1095	for i in */; do 
1096	CWD2="$( pwd )" ;
1097	cd "${i}";
1098	echo "yes" | cp ../alldriverfiles.txt . 2> /dev/null ;
1099
1100	cat alldriverfiles.txt \
1101	| egrep '(\\'"$(basename "$( pwd )")"'\\|Driver Name)' \
1102	| tee driverfilesversion.txt ;
1103
1104	Drivername=$( grep "Driver Name:" driverfilesversion.txt \
1105	| awk -F "[" '{ print $2 }' \
1106	| awk -F "]" '{ print $1 }' \
1107	| sort -f \
1108	| uniq \
1109	| tee Drivername ) ;
1110#	echo "${Drivername}" \
1111#	| tee Drivername ;
1112
1113
1114	DriverPath=$( grep "Driver Path:" driverfilesversion.txt \
1115	| awk -F "[" '{ print $2 }' \
1116	| awk -F "]" '{ print $1 }' \
1117	| awk -F "W32X86" '{ print $2 }' \
1118	| awk -F "\\" '{ print $3 }'  \
1119	| sort -f \
1120	| uniq ) ;
1121	echo "${DriverPath}" \
1122	| tee DriverPath ;
1123
1124	Datafile=$( grep "Datafile:" driverfilesversion.txt \
1125	| awk -F "[" '{ print $2 }' \
1126	| awk -F "]" '{ print $1 }' \
1127	| awk -F "W32X86" '{ print $2 }' \
1128	| awk -F "\\" '{ print $3 }' \
1129	| sort -f \
1130	| uniq  ) ;
1131	echo "${Datafile}" \
1132	| tee Datafile ;
1133
1134	Configfile=$( grep "Configfile:" driverfilesversion.txt \
1135	| awk -F "[" '{ print $2 }' \
1136	| awk -F "]" '{ print $1 }' \
1137	| awk -F "W32X86" '{ print $2 }' \
1138	| awk -F "\\" '{ print $3 }'  \
1139	| sort -f \
1140	| uniq ) ;
1141	echo "${Configfile}" \
1142	| tee Configfile ;
1143
1144	Helpfile=$( grep "Helpfile:" driverfilesversion.txt \
1145	| awk -F "[" '{ print $2 }' \
1146	| awk -F "]" '{ print $1 }' \
1147	| awk -F "W32X86" '{ print $2 }' \
1148	| awk -F "\\" '{ print $3 }'  \
1149	| sort -f \
1150	| uniq ) ;
1151	echo "${Helpfile}" \
1152	| tee Helpfile ;
1153
1154	Dependentfilelist=$( grep "Dependentfiles:" driverfilesversion.txt \
1155	| awk -F "[" '{ print $2 }' \
1156	| awk -F "]" '{ print $1 }' \
1157	| awk -F "W32X86" '{ print $2 }' \
1158	| awk -F "\\" '{ print $3 }'  \
1159	| sort -f \
1160	| uniq ) ;
1161
1162	Dependentfiles=$( echo $Dependentfilelist \
1163	| sed -e 's/ /,/g ' ) ;
1164	
1165	echo "${Dependentfiles}" \
1166	| tee Dependentfiles
1167
1168	AllFiles=$( echo ${Dependentfilelist}; echo ${Helpfile}; echo ${Configfile}; echo ${Datafile}; echo ${DriverPath} ) ;
1169	
1170	echo "${AllFiles}" \
1171	| sort -f \
1172	| uniq \
1173	| tee AllFiles ;
1174
1175	for i in $( cat AllFiles ); do echo ${i}; done \
1176	| sort -f \
1177	| uniq \
1178	| tee AllFilesIAskFor ;
1179
1180	cd "${CWD2}" 1> /dev/null ;
1181	done
1182
1183#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1184#	-c "adddriver \"${Architecture}\" \"${DriverName}:${DriverPath}:${Datafile}:${Configfile}:${Helpfile}:NULL:RAW:${Dependentfiles}\" ${Version}" \ ${smbhost}
1185
1186#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1187#	-c "setdriver \"${printername}\" \"${DriverName}\"" \
1188#	${smbhost}
1189#
1190#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1191#	-c "setprinter \"${printername}\" \"Driver was installed and set via MS-RPC (utilized by Kurt Pfeifle\'s set of \"Vampire Printerdrivers\" scripts from Linux)\"" \
1192#	${smbhost}
1193
1194	cd "${CWD1}" 1> /dev/null ;
1195	done;
1196fi
1197}
1198
1199
1200
1201# -----------------------------------------------------------------------------
1202# ------------------ First download the driverfiles........... ----------------
1203# -----------------------------------------------------------------------------
1204#
1205
1206function helpwithfetchallW32X86driverfiles()
1207{
1208echo -e " \n\
1209################################################################################
1210# 
1211#		    About fetchallW32X86driverfiles()...
1212#           	    ------------------------------------
1213#
1214# PRECONDITIONS: 1) This function expects to have the \'\$nthost\' variable set
1215#		    to the according value.
1216#		 2) This function expects to find files \"AllFiles\", 
1217#		    \"AllFilesIAskFor\", and \"AllFilesIGot\" in the directories 
1218#		    \'\${nthost}/<architecture>/<drivername>/<version>/\'. 
1219#
1220# WHAT IT DOES: These functions use \"smbclient\" to connect to the NT print 
1221#		server \"\$nthost\" and download the printer driver files from 
1222#		there. To achieve that in an orderly fashion, the previously 
1223#		created subdirectories (named like the drivers to fetch) are 
1224#		visited in turn and the related files are downloaded for each 
1225#		driver/directory.
1226#
1227# IF IT DOESN'T WORK: The function \"fetchenumdrivers3listfromNThost\" and 
1228#		      consecutive ones may not have been run successfully. This
1229#		      is a precondition for the current function.
1230#               
1231# HINT: The current values: 'nthost'=\"$nthost\"
1232#			    'ntprinteradmin'=\"$ntprinteradmin\"
1233#			    'ntadminpasswd'=<not shown here, check yourself!>
1234# 
1235################################################################################"
1236}               
1237
1238# -----------------------------------------------------------------------------
1239
1240function fetchallW32X86driverfiles()
1241{
1242if stringinstring help $@ ; then
1243helpwithfetchallW32X86driverfiles ;
1244else
1245	echo " "
1246	echo " "
1247	echo "--> Running now function fetchallW32X86driverfiles()...."
1248	echo "========================================================"
1249
1250	CURRENTWD=${PWD} ;
1251	for i in ${nthost}/W32X86/*/*/ ; do \
1252	cd "${i}"; 
1253	
1254	driverversion="$(basename "$(echo "$PWD")")" ;
1255	echo "$(basename "$(echo "$PWD")")" > driverversion ;
1256	
1257	AllFiles=$( cat AllFiles ) ;
1258	
1259	[ -d TheFiles ] || mkdir TheFiles; 
1260	
1261	cd TheFiles;
1262	
1263	echo " "
1264	echo "===================================================="
1265	echo "Downloading files now to ${PWD}....";
1266	echo "===================================================="
1267	echo " "
1268	
1269	# Fetch the Driver files from the Windoze box (printserver)
1270	smbclient -U"${ntprinteradmin}%${ntadminpasswd}" -d 2 \
1271	//${nthost}/print\$ -c \
1272	"cd W32X86\\${driverversion};prompt;mget ${AllFiles}"
1273
1274	ls -1 \
1275	| sort -f \
1276	| uniq \
1277	| tee ../AllFilesIGot ;
1278
1279	cd ${CURRENTWD} ;
1280
1281	done ;
1282fi
1283}
1284
1285
1286# -----------------------------------------------------------------------------
1287# -------------- Now upload the driverfiles and activate them! ----------------
1288# Upload files into root "Architecture" directory of Samba'a [print$] share...
1289# -----------------------------------------------------------------------------
1290#
1291
1292function helpwithuploadallW32X86drivers()
1293{
1294echo -e " \n\
1295################################################################################
1296# 
1297#		    About uploadallW32X86drivers()...
1298#           	    ---------------------------------
1299#
1300# PRECONDITIONS: 1) This function expects to have the '\$nthost', 
1301#		    '\$ntprinteradmin' and '\$ntadminpasswd' variables set to
1302#		    according values.
1303#		 2) This function expects to find the files \"AllFiles\",
1304#		    \"AllFilesIGot\" and \"AllFilesIAskFor\" in the 
1305#		    \"\${nthost}/W32X86<drivername>/<driverversion>/TheFiles\"
1306#		    subdirectory.
1307#
1308# WHAT IT DOES: This function uses "smbclient" to connect to the new Samba print
1309#		server 	"\$nthost" and upload the printer driver files into the
1310#		\"[print\$]\" share there. To achieve that in orderly fashion,
1311#		the previously created subdirectories (named like the drivers
1312#		fetched previously from \$smbhost) are visited in turn and the
1313#		related files are uploaded for each driver/directory. For this 
1314#		to really succeed, the files \"AllFilesIGot\" and \"AllFilesIAskFor\"
1315#		are compared with the help of the \"sdiff\" utility to decide
1316#		how to re-name the mis-matching filenams, so that the used 
1317#		driver upload command's spelling convention is met....
1318#
1319# IF IT DOESN'T WORK: The function "fetchenumdrivers3listfromNThost" and 
1320#		      consecutive ones may not have been run successfully. This
1321#		      is a precondition for the current function.
1322#               
1323# HINT: The current values: 'nthost'=\"$nthost\"
1324#			    'ntprinteradmin'=\"$ntprinteradmin\"
1325#			    'ntadminpasswd'=<not shown here, check yourself!>
1326# 
1327################################################################################
1328#           ............PRESS \"q\" TO QUIT............" \
1329|less
1330}               
1331
1332# -----------------------------------------------------------------------------
1333
1334function uploadallW32X86drivers()
1335{
1336if stringinstring help $@ ; then
1337helpwithuploadallW32X86drivers ;
1338else
1339	echo " "
1340	echo " "
1341	echo "--> Running now function uploadallW32X86drivers()...."
1342	echo "====================================================="
1343	
1344	for i in ${nthost}/W32X86/*/*/; do \
1345	CURRENTWD=${PWD} ;
1346	cd "${i}" ;
1347							# we are now in [..]/W32X86/[drvrname]/[2|3]/ 
1348	
1349	driverversion="$(basename "$(echo "$PWD")")" ;
1350
1351	echo "$(basename "$(echo "$PWD")")" > driverversion ;
1352
1353	cd TheFiles ;
1354							# we are now in [..]/W32X86/[drvrname]/[2|3]/TheFiles
1355	echo " "
1356	echo "===================================================="
1357	echo "Uploading driverfiles now from ${PWD}....";
1358	echo "===================================================="
1359	echo " "
1360	set -x ;
1361	
1362	smbclient -U"${smbprinteradmin}%${smbadminpasswd}" -d 2 \
1363	//${smbhost}/print\$ \
1364	-c "mkdir W32X86;cd W32X86;prompt;mput $( cat ../AllFilesIGot )";
1365
1366	cd .. ;
1367							# we are now in [..]/W32X86/[drvrname]/[2|3]/ 
1368
1369# Now tell Samba that those files are *printerdriver* files....
1370# The "adddriver" command will move them to the "0" subdir and create or
1371# update the associated *.tdb files (faking the MS Windows Registry on Samba)
1372	Drivername="$( cat Drivername )"
1373
1374	set -x ;
1375	[ x"$( cat Dependentfiles)" == x"" ] && echo NULL > Dependentfiles;
1376
1377	sdiff -s AllFilesIGot AllFilesIAskFor \
1378	| tee sdiff-of-Requested-and-Received.txt ;
1379
1380	[ -s sdiff-of-Requested-and-Received.txt ] \
1381	|| rm -f sdiff-of-Requested-and-Received.txt \
1382	&& cat sdiff-of-Requested-and-Received.txt > ../sdiff-of-Requested-and-Received.txt ;
1383	
1384	cat sdiff-of-Requested-and-Received.txt \
1385	| sed -e 's/^/mv /' \
1386	| sed -e 's/ *|/  /' \
1387	| tee rename-Received-to-Requested-case.txt ;
1388
1389	sh -x rename-Received-to-Requested-case.txt ;
1390
1391	mv rename-Received-to-Requested-case.txt rename-Received-to-Requested-case.done ;
1392
1393        echo " ################ B E G I N  DEBUGGING STATEMENT ############"
1394	echo "rpcclient -U\"${smbprinteradmin}%${smbadminpasswd}\" -d 2 \
1395	-c \'adddriver \"Windows NT x86\" \"$( cat Drivername ):$( cat DriverPath ):$( cat Datafile ):$( cat Configfile ):$( cat Helpfile ):NULL:RAW:$( cat Dependentfiles )\" $( cat driverversion )" \
1396	${smbhost} \' ;
1397        echo " ################ E N D  DEBUGGING STATEMENT ################"
1398	
1399	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" -d 2 \
1400	-c "adddriver \"Windows NT x86\" \"$( cat Drivername ):$( cat DriverPath ):$( cat Datafile ):$( cat Configfile ):$( cat Helpfile ):NULL:RAW:$( cat Dependentfiles )\" $( cat driverversion )" \
1401	${smbhost} ;
1402
1403	set +x ;
1404	
1405	cd ${CURRENTWD} ;
1406							# we are now back to where we started
1407	done;
1408	set +x ;
1409fi
1410}
1411
1412# Now tell Samba which printqueue this driver is associated with....
1413# The "setdriver" command will do just that and create or
1414# update the associated *.tdb files (faking the MS Windows Registry on Samba)
1415#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1416#	-c "setdriver \"${printername}\" \"${DriverName}\"" \
1417#	${smbhost}
1418#  -- NOT YET IMPLEMENTED IN THIS SCRIPT ---
1419#
1420
1421# Now set a nice printer comment and let the world know what we've done
1422# (or not.... ;-)
1423#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1424#	-c "setprinter \"${printername}\" \"Driver was installed and set via MS-RPC (rpcclient commandline from Linux)\"" \
1425#	${smbhost}
1426#  -- NOT YET IMPLEMENTED IN THIS SCRIPT ---
1427#
1428
1429
1430# -----------------------------------------------------------------------------
1431# ------------------ First download the driverfiles........... ----------------
1432# -----------------------------------------------------------------------------
1433#
1434
1435function helpwithfetchallWIN40driverfiles()
1436{
1437echo -e " \n\
1438################################################################################
1439# 
1440#		    About fetchallWIN40driverfiles()...
1441#           	    -----------------------------------
1442#
1443# PRECONDITIONS: 1) This function expects to have the \$nthost variable set to 
1444#		    the according value.
1445#		 2) This function expects to find the \"AllFiles\" file in
1446#		    \"\${nthost}/WIN40<drivername>/<driverversion>/TheFiles\".
1447#
1448# WHAT IT DOES: These functions use "smbclient" to connect to the NT print server
1449#		"\$nthost" and download the printer driver files from there. To
1450#		achieve that in an orderly fashion, the previously created
1451#		subdirectories (named like the drivers to fetch) are visited in
1452#		turn and the related files are downloaded for each 
1453#		driver/directory.
1454#
1455# IF IT DOESN'T WORK: The function "fetchenumdrivers3listfromNThost" and
1456#		      consecutive ones may not have been run successfully. This
1457#		      is a precondition for the current function.
1458#               
1459# HINT: The current values: 'nthost'=\"$nthost\"
1460#			    'ntprinteradmin'=\"$ntprinteradmin\"
1461#			    'ntadminpasswd'=<not shown here, check yourself!>
1462# 
1463################################################################################
1464#           ............PRESS \"q\" TO QUIT............" \
1465|less
1466}               
1467
1468# -----------------------------------------------------------------------------
1469
1470function fetchallWIN40driverfiles()
1471{
1472if stringinstring help $@ ; then
1473helpwithfetchallWIN40driverfiles ;
1474else
1475	echo " "
1476	echo " "
1477	echo "--> Running now function fetchallWIN40driverfiles()...."
1478	echo "======================================================="
1479
1480	CURRENTWD=${PWD} ;
1481
1482	for i in ${nthost}/WIN40/*/*/; do \
1483	cd "${i}"; 
1484	
1485	driverversion="$(basename "$(echo "$PWD")")" ;
1486	echo "$(basename "$(echo "$PWD")")" > driverversion ;
1487
1488	AllFiles=$( cat AllFiles ) ;
1489	
1490	[ -d TheFiles ] || mkdir TheFiles; 
1491	
1492	cd TheFiles;
1493	
1494	echo " "
1495	echo "===================================================="
1496	echo "Downloading files now to ${PWD}....";
1497	echo "===================================================="
1498	echo " "
1499
1500	# Fetch the Driver files from the Windoze box (printserver)
1501	smbclient -U"${ntprinteradmin}%${ntadminpasswd}" -d 2 \
1502	//${nthost}/print\$ -c \
1503	"cd WIN40\\${driverversion};prompt;mget ${AllFiles}" ;
1504
1505	ls -1 \
1506	| sort -f \
1507	| uniq \
1508	| tee ../AllFilesIGot ;
1509
1510	cd ${CURRENTWD} ;
1511
1512	done ;
1513fi
1514}
1515
1516
1517# -----------------------------------------------------------------------------
1518# -------------- Now upload the driverfiles and activate them! ----------------
1519# Upload files into root "Architecture" directory of Samba'a [print$] share...
1520# -----------------------------------------------------------------------------
1521#
1522
1523function helpwithuploadallWIN40drivers()
1524{
1525echo -e " \n\
1526################################################################################
1527# 
1528#		    About uploadallWIN40drivers()...
1529#           	    --------------------------------
1530#
1531# PRECONDITIONS: 1) This function expects to have '\$smbhost', '\$smbprinteradmin'
1532#		    and '\$smbadminpasswd' variables set to according values.
1533#		 2) This function expects to find \"AllFiles\", \"AllFilesIGot\"
1534#		    and \"AllFilesIAskFor\" in the subdirectory 
1535#		    \"\${nthost}/WINI40/<drivername>/<driverversion>/TheFiles\".
1536#
1537# WHAT IT DOES: These function uses \"smbclient\" to connect to the new Samba
1538#		print server "\$nthost" and upload the printer driver files into
1539#		the \"[print\$]\" share there.
1540#		To achieve that in an orderly fashion, the previously created
1541#		subdirectories (named like the drivers fetched previously from
1542#		\$smbhost) are visited in turn and the related files are
1543#		uploaded for each driver/directory.
1544#		For this to really succeed, \"AllFilesIGot\" and \"AllFilesIAskFor\"
1545#		are compared with the help of the \"sdiff\" utility to decide
1546#		how to re-name the mis-matching filenams, so that the used
1547#		driver upload command's spelling convention is met....
1548#
1549# IF IT DOESN'T WORK: The function \"fetchenumdrivers3listfromNThost\" and
1550#		      consecutive ones may not have been run successfully. This
1551#		      is a precondition for the current function.
1552#               
1553# HINT: The current values: 'nthost'=\"$nthost\"
1554#			    'ntprinteradmin'=\"$ntprinteradmin\"
1555#			    'ntadminpasswd'=<not shown here, check yourself!>
1556# 
1557################################################################################
1558#           ............PRESS \"q\" TO QUIT............" \
1559|less
1560}               
1561function uploadallWIN40drivers()
1562{
1563if stringinstring help $@ ; then
1564helpwithuploadallWIN40drivers ;
1565else
1566	echo " "
1567	echo " "
1568	echo "--> Running now function uploadallWIN40drivers()...."
1569	echo "===================================================="
1570	
1571	for i in ${nthost}/WIN40/*/*/; do \
1572	CURRENTWD=${PWD} ;
1573	cd "${i}" ; 
1574							# we are now in [..]/WIN40/[drvrname]/[0]/
1575	
1576	driverversion="$(basename "$(echo "$PWD")")" ;
1577	
1578	echo "$(basename "$(echo "$PWD")")" > driverversion ;
1579
1580	cd TheFiles ;
1581							# we are now in [..]/WIN40/[drvrname]/[0]/TheFiles
1582	echo " "
1583	echo "===================================================="
1584	echo "Uploading driverfiles now from ${PWD}....";
1585	echo "===================================================="
1586	echo " "
1587	set -x ;
1588	
1589	smbclient -U"${smbprinteradmin}%${smbadminpasswd}" -d 2 \
1590	//${smbhost}/print\$ \
1591	-c "mkdir WIN40;cd WIN40;prompt;mput $( cat ../AllFilesIGot )";
1592
1593	cd .. ;
1594							# we are now in [..]/WIN40/[drvrname]/[0]/
1595
1596# Now tell Samba that those files are *printerdriver* files....
1597# The "adddriver" command will move them to the "0" subdir and create or
1598# update the associated *.tdb files (faking the MS Windows Registry on Samba)
1599	Drivername="$( cat Drivername )"
1600	
1601	set -x ;
1602	[ x"$( cat Dependentfiles)" == x"" ] && echo NULL > Dependentfiles;
1603
1604	sdiff -s AllFilesIGot AllFilesIAskFor \
1605	| tee sdiff-of-Requested-and-Received.txt ;
1606
1607	[ -s sdiff-of-Requested-and-Received.txt ] \
1608	|| rm -f sdiff-of-Requested-and-Received.txt \
1609	&& cat sdiff-of-Requested-and-Received.txt > ../sdiff-of-Requested-and-Received.txt ;
1610	
1611	cat sdiff-of-Requested-and-Received.txt \
1612	| sed -e 's/^/mv /' \
1613	| sed -e 's/ *|/  /' \
1614	| tee rename-Received-to-Requested-case.txt ;
1615
1616	sh -x rename-Received-to-Requested-case.txt ;
1617
1618	mv rename-Received-to-Requested-case.txt rename-Received-to-Requested-case.done ;
1619
1620        echo " ################ DEBUGGING STATEMENT "
1621	echo "rpcclient -U\"${smbprinteradmin}%${smbadminpasswd}\" -d 2 \
1622	-c \'adddriver \"Windows NT x86\" \"$( cat Drivername ):$( cat DriverPath ):$( cat Datafile ):$( cat Configfile ):$( cat Helpfile ):NULL:RAW:$( cat Dependentfiles )\" $( cat driverversion )" \
1623	${smbhost}\' ;
1624        echo " ################ DEBUGGING STATEMENT "
1625
1626	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" -d 2 \
1627	-c "adddriver \"Windows 4.0\" \"$( cat Drivername ):$( cat DriverPath ):$( cat Datafile ):$( cat Configfile ):$( cat Helpfile ):NULL:RAW:$( cat Dependentfiles )\" $( cat driverversion )" \
1628	${smbhost} ;
1629	
1630	set +x ;
1631	cd ${CURRENTWD} ;
1632							# we are now back to where we started
1633	done;
1634fi
1635}
1636
1637# Now tell Samba which printqueue this driver is associated with....
1638# The "setdriver" command will do just that and create or
1639# update the associated *.tdb files (faking the MS Windows Registry on Samba)
1640#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1641#	-c "setdriver \"${printername}\" \"${DriverName}\"" \
1642#	${smbhost}
1643#  -- NOT YET IMPLEMENTED IN THIS SCRIPT ---
1644#
1645# Now set a nice printer comment and let the world know what we've done
1646# (or not.... ;-)
1647#	rpcclient -U"${smbprinteradmin}%${smbadminpasswd}" \
1648#	-c "setprinter \"${printername}\" \"Driver was installed and set via MS-RPC (rpcclient commandline from Linux)\"" \
1649#	${smbhost}
1650#  -- NOT YET IMPLEMENTED IN THIS SCRIPT ---
1651#
1652	
1653
1654#source ${0} ;
1655
1656enumallfunctions;
1657