#!/bin/sh

if [ ! -e /etc/wvdial.conf ];then
 #echo "Running wvdialconfig..."

 xmessage -center -bg orange -title "Wvdial" -buttons "" "Wait, detecting modem..." &
 wvdialconf /etc/wvdial.conf
 RETVAL=$?
 killall xmessage

 if [ $RETVAL -eq 0 ];then
  gtk-shell --title "Wvdial: Edit file, click Save button to continue" --edit-file "/etc/wvdial.conf"
 else
  #modem not detected.
  xmessage -center -bg red -title "Wvdial: error" "Modem not detected. Press OK button to quit..."
  exit
 fi
fi

#xmessage -center -bg red -title "Wvdial" "Now dialing..."

#/etc/ppp/peers/wvdial clashes with Gkdial, so keep wvdial
#in /etc/ppp/ until needed.

cp -f /etc/ppp/wvdial /etc/ppp/peers/
[ -f /etc/ppp/wvdial-pipe ] && cp -f /etc/ppp/wvdial-pipe /etc/ppp/peers/ #for wvdial 1.5x

rxvt -geometry 80x5 -bg green -title "wvdial: close window to disconnect" -e wvdial

rm -f /etc/ppp/peers/wvdial
[ -f /etc/ppp/peers/wvdial-pipe ] && rm -f /etc/ppp/peers/wvdial-pipe

killall wvdial
killall pppd
