#!/bin/sh
#
# Description:
#       Script to initiate xdialppp with associated ISP
#       selected from a list of available configuration files
#
# Author:
#       Andy Wallace (awallace@isintegration.co.uk)
#
# Requires:
#       xdialppp by D. Rodrigo (d.rodrigo@computer.org)
#
# Instructions:
#       Edit the variables that apply to your installation:
#       BINDIR, DISPLAY
#
########################################################
echo

# Set directory locations

# Modify BINDIR if xdialppp binary is in different location
BINDIR=/usr/local/bin

# *LIBDIR should not be changed*
LIBDIR=/usr/local/lib/xdialppp

if [ ! -f $BINDIR/xdialppp ]
then
        echo Error: xdialppp not in $BINDIR
        exit
fi

# Set local display variable
# You may have to execute xhost <hostname> too
export DISPLAY=:0.0

if [ -z "$1" ]
then
        echo 'Error: Please supply an ISP to dial'
        echo 'Usage: connect <ISP>'
        exit
fi

ISP=$1
ISPFILES=`cd $LIBDIR; ls *.xppprc`
NUMISPS=`echo $ISPFILES | wc -w`

if [ ! -e $LIBDIR/$1.xppprc ]
then
        echo "Error: No configuration for ISP '$1'"
        echo 'ISP configurations available:'
        for PROVIDER in `echo $ISPFILES`
        do
                echo $PROVIDER | awk -F"." '{printf("\t%s\n",$1)}'
        done
        exit
else
        echo "$LIBDIR/$1.xppprc" > $LIBDIR/xppprc
        echo Starting xdialppp...
        $BINDIR/xdialppp&
fi
