#!/bin/sh
set -e

action="$1"

# fixup after ppp-connect removed (unless this is an abort-* action) 
expr "${action}" : abort- >/dev/null || {
  if [ -f /etc/ppp/ppp-connect ] ; then
    echo
    echo "The file /etc/ppp/ppp-connect is no longer part of the ppp"
    echo -n "package, do you want to remove it [y/n]: "
    read answer
    if [ "$answer" = y ] ; then
      rm /etc/ppp/ppp-connect
    fi
  fi
}

# fixup after old update-rc.d
if [ -f /etc/rc2.d/K20ppp ] ; then
  echo Fixing up start/stop scripts
  rm -f /etc/rc2.d/K20ppp
  rm -f /etc/rc3.d/K20ppp
  rm -f /etc/rc4.d/K20ppp
  rm -f /etc/rc5.d/K20ppp
fi

# get rid of old /etc/cron.daily/ppp
test -f /etc/cron.daily/ppp && rm -f /etc/cron.daily/ppp

# setup /etc/ppp/pap-secrets /etc/ppp/options.ttyXX if necessary
HOST="`hostname`"
for i in /etc/ppp/pap-secrets /etc/ppp/options.ttyXX; do
  if grep -q hostname $i; then
    tmp=$i.tmp-$$
    cp $i $tmp
    sed -e "s/hostname/$HOST/g" <$tmp  >$i
    rm $tmp
  fi
done

# add an entry to make syslogging of pppd distinct
if ! grep -q ^local2 /etc/syslog.conf; then
  echo "local2.*		-/var/log/ppp.log" >>/etc/syslog.conf
  kill -HUP `cat /var/run/syslogd.pid`
fi

if [ -f /etc/ppp.options_out -a -f /etc/ppp.chatscript ]; then
  echo "Converting old dialup setup to new setup"
  mv /etc/ppp.chatscript /etc/chatscripts/provider
  X=`cat /etc/ppp.options_out`
  cat >/etc/ppp/peers/provider <<-!EOF!
	# The chatscript (be sure to edit that file too)
	connect "/usr/sbin/chat -v -f /etc/chatscripts/provider"
	$X
!EOF!
  rm /etc/ppp.options_out
  chmod 640 /etc/chatscripts/provider /etc/ppp/peers/provider
  chgrp dip /etc/chatscripts/provider /etc/ppp/peers/provider
fi
# Permission processing inserted by debmake on Sun, 21 Jun 1998 16:31:31 -0400
if [ -x /usr/sbin/suidregister ]; then
	suidregister -s ppp /usr/sbin/pppd root dip 4754
else
	chown root.dip /usr/sbin/pppd
	chmod 4754 /usr/sbin/pppd
fi
# Automatically inserted by debstd on Sun, 21 Jun 1998 16:31:31 -0400
update-rc.d ppp start 20 2 3 4 5 . stop 20 0 1 6 . >/dev/null
