
Parms=$*; if [ "-n Z" = "`echo -n Z`" ]; then C="\c"; else N="-n"; fi;
Ver=8

#LANG -- 
#LANG -- Language Selection Menu (Default-all)
#LANG -- -------------------------------------
#LANG ce ce) English-Canadian
#LANG cf cf) French-Canadian
#LANG de de) German-National
#LANG es es) Spanish
#LANG fr fr) French-National
#LANG it it) Italian
#LANG nl nl) Dutch
#LANG oz oz) English-Australian
#LANG uk uk) English-United Kingdom
#LANG us us) English-US

#TAPE 
#TAPE Media Selection Menu (Default-None)
#TAPE -----------------------------------
#TAPE 1) : odt60b   : /wp/tardir   : /dev/rct0         : 1/4 inch
#TAPE 2) : ncrpenta : /wp3/tardir  : /dev/rmt/c0t1d0s0 : 1/4 inch
#TAPE 3) : ibm560   : /wp/tardir   : /dev/rmt0         : 8mm Cartridge
#TAPE 4) : hp715    : /wp/tardir   : /dev/rmt/0m       : 4mm Cartridge
#TAPE 5) : hp50     : /wp/tardir   : /dev/rmt/0m       : 4mm Cartridge

do_parm() {
	set dummy $Parms; shift;
	while [ "$1" != "" ]; do
		if   [ "$1" = -t ]; then Type=$2; shift;
		elif [ "$1" = "-f" ]; then Overwrite="y";
		elif [ "$1" = -n ]; then Name=$2; shift;
		elif [ "$1" = -d ]; then Device=$2; shift;
		else wlngs="$wlngs $1"; fi;
		shift;
	done
}

getName() {
	Prod2="prod2_$Name"
	while [ "$Name" = "" -o "$Overwrite" != "y" ]; do
		echo; echo $N "  Enter a 1-6 char description: $C"; read Name;
		Prod2="prod2_$Name"
		if [ -d $Prod2 ]; then
			if [ "$Overwrite" != "y" ]; then
				echo; echo $N "  Warning: $Prod2 exists.  Overwrite? (n) $C";
				read Overwrite; fi;
			if [ "$Overwrite" != "y" ]; then Name=""; continue; fi;
		else
			Overwrite=y;
		fi;
	done;
	if [ -d $Prod2 ]; then echo "  rm -rf $Prod2;"; rm -rf $Prod2; fi;
	mkdir $Prod2;
}

do_main() {
	RSH=rsh;
	for f in `echo $PATH | sed "y/:/ /"`; do
		if [ -x $f/remsh ]; then RSH=remsh; fi;
		if [ -x $f/rcmd ]; then RSH=rcmd; fi;
	done;

	if [ -d dat ]; then Type=0; getName; fi;
}

do_plat() {							# try to determine the platform
	Work=`uname -X 2>/dev/null \
	| grep Release | sed 's/.*v//' | sed 's/\..*$//'`;
	if [ "$Work" = "" ]; then
		OSVer=`uname -v | awk '{ print substr($1,1,1) }'`;
	else
		OSVer=$Work; fi;
	SYNam=`uname -r | sed 's/\..*/-/g'`;
	HWNam=`uname -m | awk '{ print substr($1,1,1) }'`;
	set $SYNam $OSVer $HWNam;

	PlatInfo=shared/l_info;
	Platform=`grep " Platform " $PlatInfo | sed 's/ * /:/g' \
	| grep ":$1" | grep ":$2" | grep ":$3"'$' | cut -d":" -f1`;

	if [ -f .platform ]; then Platform=`cat .platform`; fi;

	if [ "$Platform" = "" ]; then
		echo "  Error: Unable to determine the platform.";
		exit;
	fi;
}

do_init() {							# get echo parameters
	UNAME_N=`uname -n`;
	PROD=`pwd`;

	List=$PROD/shared/ship;
	sed -n '/^#ifdef ALL$/,/^#endif ALL$/p' $List > $Prod2/TmP;
    sed -n '/^#ifdef '$Platform'$/,/^#endif '$Platform'$/p' $List >> $Prod2/TmP;
    sed -e '/^#/d' -e '/^$/d' $Prod2/TmP | sort -u \
		> $PROD/shared/worklist; rm $Prod2/TmP;
	List=$PROD/shared/worklist;
}

dosel() {							# ask for input
	echo; echo $N "  Enter Selection(s): $C";
	read Parms;
	if [ "$Parms" = "q" ]; then exit; fi;
}

do_lngs() {							# display available languages
	for Dir in `ls lng`; do
		if [ -d lng/$Dir ]; then Dirs="$Dirs$Dir|"; fi; done;
	if [ "$wlngs" = "" ]; then
		grep '^'#LANG mm | egrep "$Dirs--" | sed -n 's/#LANG .. /  /p'; fi;
	if [ "$wlngs" = "" ]; then dosel; do_parm; fi;
	if [ "$wlngs" = "" ]; then
		lngs=`echo $Dirs | sed 's/|/ /g'`;
	else
		for wlng in $wlngs; do
			List=shared/ship;
			for xlng in `egrep "\.$wlng$|$wlng\....$" $List \
			| sed 's/ * / /g' | egrep "lng/" \
			| sed 's/lng\///' | cut -d" " -f3 | sort -u`; do
				lngs="$lngs $xlng";
			done;
		done;
	fi;

	rm -f /tmp/TeMp;
	for lang in $lngs; do echo $lang >> /tmp/TeMp; done;
	lngs="";
	for lang in us `sort -u /tmp/TeMp | sed '/^us$/d'`; do
		lngs="$lngs $lang"; done;
	rm -f /tmp/TeMp;
}


mklinks() { for file in `cd $1; ls -d * .??* 2>/dev/null`; do
	if [ ! -d $1/$file ]; then ln $1/$file $2; fi; done; }

cplink() {
	if [ -d $1 ]; then (cd $1; mkdir -p $2; \
	find . -depth -print | cpio -pdlm $2 2>&1 | grep -v "0 blocks" ); fi; }

mk_prd2() {
	echo; echo $N "  Processing... $C";
	cd $Prod2;
	for Enam in manual netscape sdk; do
		cplink ../$Enam ../$Prod2/$Enam;
	done

	cplink ../shared ../$Prod2/shared;
	ln shared/install.wp install.wp;
	ln shared/install.wp remove.wp;

	mkdir $Platform;
	for Dir in bin dat ins trm; do
		cplink ../$Dir ../$Prod2/$Platform/$Dir;
	done

	for lang in $lngs; do
		LNG=$lang;
		echo $N "$lang $C"; echo $LNG >> shared/wplngs;
		cplink ../lng/$LNG ../../$Prod2/$Platform/lng/$LNG;
	done

	cplink ../prn/gu ../../$Prod2/$Platform/prn/gu;
	cplink ../prn/ch ../../$Prod2/$Platform/prn/ch;
		
	mkdir READme;
	cp `find . -name readme.\* -print | egrep "/dat/|/bin/"` READme;
	for file in `ls READme/*`; do
		if [ "$file" = READme/readme ]; then continue; fi;
		if [ -f ../../.hostplat ]; then
			../../`cat ../../.hostplat`/ins/wpdecom $file $file.new;
		else
			$Platform/ins/wpdecom $file $file.new; fi;
		mv $file.new $file; done;
	mv READme readme; chmod 644 readme/*;
	touch shared/cleanup
	
	cd ..; echo;
}

do_tape() {							# see if a tape needs to be written
	while true; do
		sed -n 's/^#TAPE /  /p' mm | sed 's/: /  /g';
		if [ "$Device" = "" ]; then dosel; Device=$Parms; fi;
		if [ "$Device" = "" ]; then return; fi;
		Mch=`grep " $Parms) " mm | cut -d: -f2 | sed 's/ * //g'`;
		Dir=`grep " $Parms) " mm | cut -d: -f3 | sed 's/ * //g'`;
		Dev=`grep " $Parms) " mm | cut -d: -f4 | sed 's/ * //g'`;

		if [ "$Mch" = "" -o "$Dev" = "" ]; then
			echo; echo $N "  Error: Invalid Selection $C"; sleep 1; echo;
			Device=""; continue; fi;

		if [ "$Device" != "" ]; then Device="";
			if [ "$UNAME_N" = $Mch ]; then
				echo "(cd $Prod2; tar cf $Dev *;)"
				(cd $Prod2; tar cf $Dev *;)
			else
				echo; echo $N "  Copy $Prod2 to $Mch:$Dir? (y/n) $C";
				read Resp; 
				if [ "$Resp" = "y" ]; then
					$RSH $Mch "cd $Dir; rm -rf $Prod2";
					List="";
					for DIR in `find $Prod2 -type d -print`; do
						List="$List $DIR"; done;
					$RSH $Mch "cd $Dir; mkdir $List; \
						chmod ug+rwx $List; chmod o+rx $List";
					tar cf - $Prod2 | $RSH $Mch "cd $Dir; tar xf -";
				fi;

				while true; do echo;
					echo $N "  Write $Mch:$Dir/$Prod2 to $Dev? (y/n) $C";
					read Resp; 
					if [ "$Resp" = "y" ]; then
						$RSH $Mch "cd $Dir/$Prod2; tar cf $Dev .";
					else break; fi;
				done;
			fi;
		fi;
	done;
}

mk_list() {
	Plat=`ls -d */dat | sed 's/\/dat//'`

	for file in shared/ship; do
		if [ -f $file ]; then SHIP="$SHIP $file"; fi; done;

	cklist() {
		if [ ! -s $Pdir/$1.tmp ]; then
			rm -f $Pdir/$1.tmp; touch $Pdir/$1.list; return; fi;
		cat $Pdir/$1.tmp | while read j1 File Dir j2 j3 j4 j5; do
			if [ -f $Dir/$File -o -f $Plat/$Dir/$File ]; then
				echo $Dir/$File \
				| sed -e "s|^bin/|$Plat/bin/|" \
				-e "s|^dat/|$Plat/dat/|" \
				-e "s|^ins/|$Plat/ins/|" \
				-e "s|^lng/|$Plat/lng/|" \
				-e "s|^prn/|$Plat/prn/|" \
				-e "s|^trm/|$Plat/trm/|" \
				>> $Pdir/tmp; fi;
		done;
		sort -u $Pdir/tmp > $Pdir/$1.list; rm -f $Pdir/$1.tmp $Pdir/tmp;
	}

	# Create lists for extra features
	find manual -type f -print > $Pdir/g_man.list;
	find sdk -type f -print > $Pdir/g_sdk.list;
	egrep " ins | shared " $SHIP > $Pdir/b_ins.tmp;
	cklist b_ins;
	ls readme/* >> $Pdir/b_ins.list;

	for file in shared/l_s shared/l_f shared/l_l shared/wpdm shared/cleanup; do
		if [ -f $file ]; then echo $file >> $Pdir/b_ins.list; fi; done;

	# Create lists for required files and language files.
	for R in c g b; do
		grep " $R[sml]. " $SHIP | egrep -v " lng/| prn/| ins | shared " \
			> $Pdir/"$R"_req.tmp
		cklist "$R"_req;

		for L in `ls -1d */lng/* | sed -e 's|.*lng/||g' -e 's/\///'`; do
			grep " $R[sml]. " $SHIP | egrep -i "\.$L$|$L\....$" \
			| sed -e '/cmp /d' > $Pdir/"$R"_$L.tmp;
			cklist "$R"_$L;
		done;
	done;

	# Add default printers.
	chr="dm3\.|hp1\.|ms1\.|ps1\.|ps2\."; gui="dm03|hp01|ms01|ps01|ps02";
	CHR="DM3\.|HP1\.|MS1\.|PS1\.|PS2\."; GUI="DM03|HP01|MS01|PS01|PS02"

	grep "\.all" $SHIP | egrep "$chr" > $Pdir/ptr.tmp;
	cklist ptr;
	mv $Pdir/c_req.list $Pdir/TmP12;
	sort -u $Pdir/TmP12 $Pdir/ptr.list >> $Pdir/c_req.list;
	rm -f $Pdir/TmP12 $Pdir/ptr.list;

	grep "\.us\.all" $SHIP | egrep "$gui" > $Pdir/ptr.tmp;
	cklist ptr;
	mv $Pdir/g_req.list $Pdir/TmP12;
	sort -u $Pdir/TmP12 $Pdir/ptr.list >> $Pdir/g_req.list;
	rm -f $Pdir/TmP12 $Pdir/ptr.list;

	grep "graphics\.tar"'$' $Pdir/g_req.list > $Pdir/g_gra.list;
	grep -v "graphics\.tar" $Pdir/g_req.list > $Pdir/g_req.Temp;
	grep "wpdecom"'$' $Pdir/b_ins.list >> $Pdir/g_gra.list;
	mv $Pdir/g_req.Temp $Pdir/g_req.list;

	ls -1 shared/prs_?.us shared/wplngs* | sed '/prscnv/d' >> $Pdir/b_ins.list;

	# Now remake prs*.us files.
	for file in shared/prs_c.us shared/prs_g.us shared/prs_b.us; do
		if [ ! -f $file.bk -a -f $file ]; then
			cp $file $file.bk; rm -f $file; fi; done;
	if [ -f shared/prs_c.us.bk ]; then PRSc=shared/prs_c.us.bk; fi;
	if [ -f shared/prs_g.us.bk ]; then PRSg=shared/prs_g.us.bk; fi;

	rm -f $Pdir/Tmp $Pdir/ptr.list;
	sed -e '//d' -e 's///' -e 's/^-/|/' -e 's/ /_/g' $PRSc $PRSg \
	| while read Line; do
		if [ "$Save" = "" ]; then Save="$Line";
		else echo "$Save $Line" >> $Pdir/Tmp; Save=""; fi;
	done;
	egrep "$CHR|$GUI" $Pdir/Tmp | sort -u > $Pdir/Tmp.o;
	mv $Pdir/Tmp.o $Pdir/Tmp;

	doprs() {
		echo "  Making $Name..."; rm -f $Name;
		egrep "$1" $Pdir/Tmp | sed 's/ .*$//' | sort -u | while read D; do A="";
			for a in `egrep "$1" $Pdir/Tmp | grep '^'"$D " | sed 's/.* //'`; do
				A="$A $a"; done;
			echo "" >> $Name;
			echo $D | sed -e 's/_/ /g' -e 's/|/-/' >> $Name;
			echo $A | sed 's/$//' >> $Name;
		done;
		echo  >> $Name;
	}

	Name=shared/prs_c.us; if [ -f $Name.bk ]; then doprs "$CHR"; fi;
	Name=shared/prs_g.us;  if [ -f $Name.bk ]; then doprs "$GUI"; fi;
	if [ -f shared/prs_c.us.bk -a -f shared/prs_g.us.bk ]; then
		Name=shared/prs_b.us;   if [ -f $Name.bk ]; then doprs "$CHR|$GUI"; fi;
	else touch shared/prs_b.us; fi;
	rm -f $Pdir/Tmp;
}

rm_char1() {
	# remove character files
	grep ' c[sml]. ' shared/ship | while read junk Fil Dir junk; do
		if [ -d $Dir ]; then Plt=.; else Plt=linux; fi;
		if [ -f $Plt/$Dir/$Fil ]; then rm $Plt/$Dir/$Fil; fi;
	done

	sed '/ c[sml]. /d' shared/ship > shared/ship.new;
	rm shared/ship; mv shared/ship.new shared/ship;
	rm -f shared/wpprod; echo "2 " > shared/wpprod;
}

rm_char2() {
	rm -rf ../free; mkdir ../free;
	sed -n -e '/#ifdef.*linux$/,/#endif.*linux$/p' \
	-e '/#ifdef ALL/,/#endif ALL/p' shared/ship \
	| sed -e '/^#/d' -e '/^$/d' -e 's/ * / /g' -e '/ c[sml]. /d' \
	| cut -d" " -f2,3 | sed 's/\(.*\) \(.*\)/\2\/\1/' \
	| sed 's/^bin/linux\/bin/' \
	| sed 's/^dat/linux\/dat/' \
	| sed 's/^ins/linux\/ins/' \
	| sed 's/^lng/linux\/lng/' \
	| sed 's/^prn/linux\/prn/' \
	| sed -e '/\.\/mm/d' -e '/\.mmdata/d' \
	| sort -u | cpio -pdlm ../free 2>&1 | grep -v "0 blocks";
}

rm_misc() {
#m bin xwpdraw xwpdraw
#m lng/?? mprtxt.?? mprtxt...
#m lng/?? wpdr??.hlp wpdr...hlp
#m bin xwpfi xwpfi
#m lng/?? archlrn.?? archlrn...
#m lng/?? archexp.?? archexp...
#m dat address address
#m dat draft.wpg draft.wpg
#m dat form.ltr form.ltr
#m dat letter letter
#m dat newsltr newsltr
#m dat outline outline
#m dat report report
#m dat tables tables
#m bin wpsputl wpsputl
#m lng/?? sputltxt.?? sputltxt...
#m bin wprint wprint
#m bin wpformat wpformat
#m dat readme.lic readme.lic
#m dat readme.flx readme.flx
#m ins check check
#m bin check check
#m dat graphics.tar graphics.tar
grep '^'"#m " $0 | sed 's/^#m //' | while read dir fil1 fil2; do
	rm -f linux/$dir/$fil1;
	grep -v " $fil2 " shared/ship > shared/ship.free;
	rm -f shared/ship; mv shared/ship.free shared/ship;
done
}

do_menu() {
	if [ -d linux ]; then echo;
		echo $N "  Create a free Linux prod? (y) $C"; read work;
		if [ "$work" = "" -o "$work" = "y" ]; then
			# remove character files
			rm_char2;	
			# ensure certain files get copied
			find readme install.wp remove.wp -depth -print \
			| cpio -pdlm ../free 2>&1 | grep -v "0 blocks";
			# copy list of languages
			cp shared/wplngs ../free/shared
			cd ../free;
			# enable special free switches
			touch shared/l_s shared/l_f;
			# remove character shiplist entries
			sed '/ c[sml]. /d' shared/ship > shared/ship.new;
			rm shared/ship; mv shared/ship.new shared/ship;
			# mark as gui only
			echo "2 " > shared/wpprod;
			# remove misc files not shipping on free version
			rm_misc;
			# remove Netscape and Manual
			egrep -v "Netscape|Manual" shared/l_extr > shared/TeMp;
			rm shared/l_extr; mv shared/TeMp shared/l_extr;
			rm -rf netscape manual; mkdir netscape manual sdk;
			rm -f shared/cleanup;
			# replace fonts with small set	
			for file in archafm archpfb wp.drs; do
				rm -f linux/data/$file;
				rcp pebble:/d8/m8/src/psfonts/free/$file linux/dat/$file;
			done
			# new sizes because of deleted files
			rm shared/l_size;
			rcp pebble:/d8/m8/src/install/data/l_size.free shared/l_size;
			# different eula's with free version
			rcp pebble:/d8/m8/src/data/readme/free.\? shared
			for num in 1 2 3 4 5 6; do
				rm -f shared/license.$num;
				mv shared/free.$num shared/license.$num;
			done
			# copy in the new mwp
			rm -f linux/bin/mwp;
			rcp homestead:/wp1/f8/src/wp_s/mwp_d linux/bin/mwp;
			exit;
		fi;
		echo $N "  Create single seat gui-only Linux prod? (y) $C"; read work;
		if [ "$work" = "" -o "$work" = "y" ]; then
			echo "  Removing Character Product...";
			rm_char1; touch shared/l_s;
			echo "  Replacing servers_up and mwp with special versions...";
			rm -f linux/bin/servers_up;
			rcp homestead:/wp1/f8/src/flex/servers_up_s/servers_up_d \
				linux/bin/servers_up;
			rm -f linux/bin/mwp;
			rcp homestead:/wp1/f8/src/wp_s/mwp_d linux/bin/mwp;
#			echo "  Replacing Splash and Program Screens...";
#			rsh pebble \
#				"cd /d8/m8/src/wpicons/linux_s; tar cf - ??/wpicons.??.cmp" \
#				| (cd linux/lng; tar xf -)
#			for file in `ls linux/lng/*/wpicons.??`; do
#				rm $file;
#				mv $file.cmp $file;
#			done
		fi;
	fi;
	if [ "$Type" = "" ]; then Type=99; fi;
	while [ "$Type" -lt 1 -o "$Type" -gt 3 ]; do
		echo; echo "  SDC Prod2 Creation Menu"; echo;
		echo "  1) Demo Prod    ";
		echo "  2) FTP Prod     ";
		echo "  3) Demo FTP Prod";
		dosel; Type=$Parms
		if [ "$Type" = "" ]; then Type=99; fi;
	done;
	while [ ! -d $Pdir/prod$Ver -o "$Pdir" = "" ]; do
		echo; echo $N "  Where would you like your prod? $C";
		read Pdir;
		if [ "$Pdir" = "" ]; then continue; fi;
		if [ "$Pdir" = "." ]; then Pdir=`pwd`; fi;
		if [ ! -d $Pdir/prod$Ver ]; then mkdir -p $Pdir/prod$Ver; fi;
	done;
	Pdir=$Pdir/prod$Ver;
}

incr_cnt() { Cnt=`expr $Cnt + 1`; if [ $Cnt -le 9 ]; then Cnt=0$Cnt; fi; }

do_othr() {
	if [ "$Type" = 1 -o "$Type" = 3 ]; then		# Demo
		touch shared/cleanup shared/wpdm;

		echo; echo "  Converting $Prod2 to a demo...";
		echo "  Removing Netscape...";
		cp shared/l_extr shared/l_extr.bk; rm shared/l_extr;
		sed '/MultiSelect=Netscape/d' shared/l_extr.bk > shared/l_extr;
		rm shared/l_extr.bk;
		rm -rf netscape;

		echo "  Removing licensing files...";
		for suf in lic flx; do
			rm -f */dat/readme.$suf readme/readme.$suf;
			grep -v readme\.$suf shared/ship > shared/ship.new;
			mv shared/ship.new shared/ship;
		done;
		grep -v wpcreatlic shared/ship > shared/ship.new;
		mv shared/ship.new shared/ship;
		rm -f */bin/wpcreatlic */ins/check;

		echo "  Reducing fonts...";
		rcp pebble:/d8/m8/src/psfonts/demo/archafm \
			pebble:/d8/m8/src/psfonts/demo/wp.drs .
		echo "  Reducing Graphics...";
		rcp sun690:/wp7/m7/src/data/graph/graphic1.cmp graphics.tar
		for name in archafm wp.drs graphics.tar; do
			for file in `ls */dat/$name`; do rm $file; cp $name $file; done;
			rm $name;
		done;
	fi;

	if [ "$Type" = 2 -o "$Type" = 3 ]; then		# Ftp
		echo; echo "  Preparing files for ftp access...";

		touch $Pdir/.`ls -d */ins | sed 's|/.*$||'`;

		mk_list;

		echo "  Finding Large Files...";
		for File in `sort -u $Pdir/*.list`; do
			Size=`ls -o $File | sed 's/ * /:/g' | cut -d: -f4`;
			if [ $Size -gt 3000000 ]; then
				Temp=`echo $File | sed 's|graphics\.tar||'`;
				if [ "$Temp" = $File ]; then Large="$Large $File"; fi;
			fi;
		done;

		if   [ "$Platform" = sunos ]; then Opt="-10000";
		elif [ "$Platform" = sco ]; then Opt="-l 10000";
		elif [ "$Platform" = scodt ]; then Opt="";
		else Opt="-b 500000"; fi;

		for File in $Large; do
			echo "  Splitting $File..."; rm -f $File??;
			split $Opt $File $File;
			WFile=`grep '^'"$File"'$' $Pdir/*.list | sed 's/:.*$//'`;
			ls -1 $File?? >> $WFile;
		done;

		echo $N "  Creating tar files: $C";
		for Tar in `ls $Pdir/*.list | sed 's/\.list//' | sed 's/.*\///'`; do
			echo $N "$Tar$C";
			Cnt=00; Tot=0; Pkg="";
			for File in `cat $Pdir/$Tar.list`; do
				if [ -f $File"aa" ]; then continue; fi;
				Size=`ls -o $File | sed 's/ * /:/g' | cut -d: -f4`;
				Tot=`expr $Tot + $Size`; Pkg="$Pkg $File";
				if [ $Tot -gt 4000000 ]; then
					tar cf $Pdir/$Tar$Cnt $Pkg; incr_cnt; Tot=0;Pkg="";fi;
			done;
			if [ "$Pkg" != "" ]; then
				tar cf $Pdir/$Tar$Cnt $Pkg; fi;
			rm -f $Pdir/$Tar.list;
			BkSp=`echo "$Tar" | sed 's/.//g'`; echo $N "$BkSp$C";
			Spac=`echo "$Tar" | sed 's/./ /g'`; echo $N "$Spac$C";
			echo $N "$BkSp$C";
		done; echo;

		cp shared/install.ftp $Pdir/Runme;
		cp shared/readme.ftp $Pdir/Readme;
		cp shared/mm $Pdir/mm;

		for File in $Large; do rm -f $File??; done;
	fi;
}

resp() { Resp="";
	Work=`echo $* | sed 's/.*(//' | sed 's/).*$//' | sed 's/,/ /g'`;
	while [ "$Resp" = "" ]; do
		echo $N "$* $C"; read Resp; echo;
		if [ "$Resp" = all ]; then Resp=$Work; fi;
		if [ "$Resp" = "" ]; then break; fi;
		for Sel in $Resp; do
			if [ "`echo $Work | sed 's/'$Sel'//'`" = "`echo $Work`" ]; then
				Resp="";
			fi;
		done;
	done;
}

dolang() {
	for l in $L; do
		LL="$LL "`egrep "\.$l$|$l\...." shared/ship \
		| grep lng  | grep -v '\.init\.' \
		| sed 's/ * / /g' | grep ' ['$T'].. ' | cut -d" " -f3 \
		| sed 's/lng\///' | sort -u`;
	done;
}

do_tar() { echo; echo "  FTP Tar File Creation Menu";

	if [ "$1" != "" ]; then Name=$1; shift; fi;
	while [ "$Name" = "" ]; do echo;
		echo $N "  Enter the name you would like for your tar file: $C";
		read Name; done;

	if [ "$1" != "" ]; then sl=$1; shift; fi;
	while [ "$sl" != "s" -a "$sl" != "l" ]; do echo;
		echo $N "  What size of tar files? ( s)mall l)arge ): $N2";
		read sl; echo; done;

	if [ "$1" != "" ]; then P=$1; shift;
	else resp "  Which products would you like? (g c b)"; P=$Resp; fi;
	if [ "$P" = "x" ]; then P=""; fi;
	if [ "$P" = "b" ]; then P="c g"; fi;
	if [ "$P" != "" ]; then List="$List `ls b_ins* b_req*`";
		for p in $P; do List="$List `ls ${p}_req*`"; done; fi;

	Avail=`ls -1 *_* | egrep "ce|cf|de|es|fr|it|nl|oz|uk|us" \
	| sed 's/.*_//' | sed 's/0.*$//' | sort -u`;

	if [ "$1" != "" ]; then L=$1; shift;
	else resp "  Which languages? (`echo $Avail`)"; L=$Resp; fi;
	if [ "$L" = "x" ]; then L=""; fi;
	if [ "$L" != "" ]; then List="$List `ls b_ins*`";
		for num in 0 1; do tar xf b_ins0$num shared/ship 2>/dev/null; done;
		if [ "$1" != "" ]; then P=$1; shift; fi;
		while [ "$P" = "" ]; do
			resp "  For which product? (g c b)"; P=$Resp; done;
		if [ "$P" = "x" ]; then P=""; fi;
		if [ "$P" = "b" ]; then P="c g"; fi;
		T=`echo "b $P" | sed 's/ //g'`; dolang; L=$LL;
		for p in $P; do
			for l in $L; do List="$List `ls b_${l}* ${p}_${l}*`"; done;
		done;
	fi;

	if [ "$1" != "" ]; then E=$1; shift;
	else resp "  Which extra packages? (man gra sdk)"; E=$Resp; fi;
	if [ "$E" = "x" ]; then E=""; fi;
	if [ "$E" != "" ]; then
		for e in $E; do
			if [ "$e" = man ]; then  List="$List `ls b_ins*`"; fi;
			List="$List `ls *_${e}*`";
		done;
	fi;

	rm -f list; for list in $List; do echo $list >> list; done;
	List=`sort -u list | sed 's/ //g' | sed '/^$/d'`; rm -f list;

	if [ "$List" != "" ]; then
		if [ "$sl" = s ]; then LIST="";
			Cnt=0; rm -f Moves; echo "$Name" > Name;
			for file in $List; do
				Size=`ls -o $file | sed 's/ * /:/g' | cut -d: -f4`;
				if [ "$Size" -gt 3000000 ]; then Cnt=`expr $Cnt + 1`;
					if [ "$Cnt" -lt 10 ]; then Cnt="0$Cnt"; fi;
					echo ln $file $Name$Cnt; ln $file $Name$Cnt;
					echo "$Name$Cnt $file" >> Moves;
				else
					LIST="$LIST $file"; fi;
			done;
			set -x; tar cf $Name"00" Runme Readme Moves Name $LIST;
			rm -f Moves Name;
		else
			echo; set -x; tar cf $Name"00" Readme Runme $List; fi;
	fi;
}

WCD=`pwd | sed 's|.*/||'`;
if [ "$WCD" = CD$Ver ]; then echo;
	echo "Error: Invalid request for a CD prod."; echo; exit; fi;

if [ -f Runme ]; then				# if an ftp work area
	do_tar $*; exit;
elif [ -d dat ]; then				# if a normal prod
	do_parm;
	do_main;
	do_plat;
	do_init;
	do_lngs;
	mk_prd2;
	do_tape;
else								# if a prod2
	do_parm;
	do_main;
	do_menu;
	do_plat;
	do_othr;
fi;

echo;

