#!/bin/sh

if [ "$1" = "configure" ]
then
  if [ "$2" != "" ]
  then
      dpkg --compare-versions $2 lt 1.6.0
      if [ $? -eq 0 ]
      then
	if [ -e /var/lib/dpkg/methods/ftp/vars ]
	then
	  echo "/var/lib/dpkg/methods/ftp/vars format has changed since $2."
	  echo -n "Trying to convert the file ... "

	  # Terrible way of converting the old vars file ...
	  
	  perl -e "do '/var/lib/dpkg/methods/ftp/vars';
		   print \"\\\$VAR1 = { proxyhost => '\$proxyhost' ,\n\";
		   print \"site => [ [ '\$ftpsite', '\$ftpdir', ['\";
		   print join(\"','\", split(/\\s/, \$distribs)); 
		   print \"'], \$passive, '\$username', '\$password' ] ], \n\";
		   print \" proxypassword => '\$proxypassword', \n\";
		   print \" proxylogname => '\$proxylogname', 'done' => 1, \n\";
		   print \" use_auth_proxy => \$use_auth_proxy, \n\";
		   print \" dldir => '\$dldir' }; \n\";" \
		   >/var/lib/dpkg/methods/ftp/vars.new
		   
	  mv -f /var/lib/dpkg/methods/ftp/vars /var/lib/dpkg/methods/ftp/vars.old
	  mv -f /var/lib/dpkg/methods/ftp/vars.new /var/lib/dpkg/methods/ftp/vars
	  chmod 0600 /var/lib/dpkg/methods/ftp/vars*
	  echo "done."
	  echo "If you have problems with the dpkg-ftp configuration, simply"
	  echo "relaunch the  Access  step in dselect."
	fi
      fi
  fi
fi

#DEBHELPER#

