#!/bin/sh
# front end to turboprint config that removes symlink to ramdisk
# so spool is written out to persistent storage...
# this should only be run on flash.


if [ "$BOOTSOURCE" = "flash" ]; then

   ln -sf /root/lpd /var/spool/

fi

#strip off line continuations \
rm -f /tmp/.printcap.orig
if [ -f /etc/printcap ]; then
	sed -e 's/:\\//' -e 's/:$//g' /etc/printcap > /tmp/.printcap.orig
	cp /tmp/.printcap.orig /etc/printcap
fi


/usr/sbin/turboprintcfg
			

# add continuation characters to /etc/printcap so ICA can process it....
if [ -f /etc/printcap ]; then
	rm -f /tmp/.printcap
	cat /etc/printcap | while IFS= read i
	do
		# look for all lines that aren't a comment
		line=`echo $i |  sed -n '/^[^#]/p'`
		if [ "$line" ] ; then
	
                        # check for input filter line... this is last line in an entry
                        ifline=`echo $line | sed -n '/.*:if/p'`
                        if [ "$ifline" = "" ] ; then
                                echo "$i:\\" >> /tmp/.printcap
                        else
                                echo "$i:" >> /tmp/.printcap
                        fi
		else
			echo "$i" >> /tmp/.printcap
		fi
	done

	cp /tmp/.printcap /etc/printcap
	rm -f /tmp/.printcap
fi

if [ "$BOOTSOURCE" = "flash" ]; then

   ln -sf /tmp/printspool /var/spool

   cp -a /root/lpd /tmp/printspool

   /etc/rc.d/init.d/lpd stop

   /etc/rc.d/init.d/lpd start

fi

