#!/bin/sh -e

# source debconf library
. /usr/share/debconf/confmodule

if [ "$1" = "configure" ]; then
	if [ ! -f /usr/lib/em8300/em8300.uc ] && [ ! -f /usr/lib/em8300/microcode0.bin ]; then
	   db_get em8300/download_microcode
	   DO_DOWNLOAD="$RET"
	   if [ "$DO_DOWNLOAD" = "false" ]; then
	      db_get em8300/have_vxd
	      VXDSRC="$RET"
	      if [ -f "$VXDSRC" ]; then 
	      	 if [ -n "`echo $VXDSRC | /bin/grep '_$'`" ]; then
		    [ -x /usr/share/em8300/msexpand.pl ] && \ 
		      /usr/share/em8300/msexpand.pl "$VXDSRC"
		    VXDSRC="`echo $VXDSRC | sed 's/.vx_$/.vxd/'`"
		 fi

	  	 [ -x /usr/share/em8300/microcode_extract.pl ] && \
	  	   /usr/share/em8300/microcode_extract.pl "$VXDSRC" /usr/lib/em8300

	     	 if [ -f /usr/lib/em8300/microcode0.bin ]; then
		    ln -sf /usr/lib/em8300/microcode0.bin /etc/dxr3.ux
		 fi
	      fi
	   else
	       [ -x /usr/bin/wget ] && \
	       	 cd /usr/lib/em8300 && /usr/bin/wget http://birme.se/em8300.uc
	       if [ -f /usr/lib/em8300/em8300.uc ]; then
	       	  ln -sf /usr/lib/em8300/em8300.uc /etc/dxr3.ux
	       fi
           fi	   
   	fi
 
	[ -x /sbin/ldconfig ] && /sbin/ldconfig
fi

db_stop
