#!/bin/bash
#
#    eee-bpw /usr/sbin/bpwconfig configure settings script
#    Copyright (C) 2008  James Cameron (quozl@laptop.org)
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

# default values, edit /etc/bpw.conf not this file
APN="telstra.bigpond"
USERNAME=""
PASSWORD=""
UDEV_TRIGGERS_PPPD=no

# current customisation
. /etc/bpw.conf

cat <<EOF
Eee PC BigPond Wireless - Configuration Program
Copyright (C) 2008  James Cameron (quozl@laptop.org)

This program comes with ABSOLUTELY NO WARRANTY; for details see source.
This is free software, and you are welcome to redistribute it under certain
conditions; see source for details.

     Access Point Name : ${APN}
              Username : ${USERNAME}
              Password : * (not shown here)
    Automatic dialling : ${UDEV_TRIGGERS_PPPD}

Note: the modem must have been previously registered by the BigPond
Connection Manager on a Mac OS X or Microsoft Windows.  Registration
records your username and password on the modem itself, and binds the
modem to the network in some way.  Maxon and Telstra have not released
technical details to allow the Linux software to perform the
registration steps.  2008-08-05.

EOF

# apn

cat <<EOF
Enter the access point name for the packet data protocol context.
Normally this is telstra.bigpond, if you are are using the BigPond
Wireless Broadband service.  Other values used might include:

	telstra.pcpack
	telstra.datapack
	telstra.internet

EOF

read -p "Access Point Name [${APN}] ? " -e VALUE
if test -z "${VALUE}"; then
    VALUE=${APN}
fi
APN=${VALUE}
echo ""

# username

cat <<EOF
Enter your username for modem authentication,
for BigPond service with APN telstra.bigpond use username@bigpond.com,
for Telstra service with APN telstra.internet use anything.

EOF

read -p "Username [${USERNAME}] ? " -e VALUE
if test -z "${VALUE}"; then
    VALUE=${USERNAME}
fi
USERNAME=${VALUE}
echo ""

# password

cat <<EOF
Enter your password for modem authentication,
for BigPond service use your BigPond password,
for Telstra service use anything, it is ignored.

EOF

if test -n "${PASSWORD}"; then
    echo "(Just press Enter to use the password you entered before)."
fi

read -p "Password ? " -e -s VALUE
echo ""
if test -z "${VALUE}"; then
    VALUE=${PASSWORD}
    echo "Using existing password."
else
    read -p "Confirm password ? " -e -s CONFIRM
    echo ""
    if test "${VALUE}" != "${CONFIRM}"; then
	echo "Passwords do not match, giving up."
	exit 1
    else
	echo "Both passwords are the same, continuing ..."
    fi
fi
PASSWORD=${VALUE}
echo ""

# auto
cat <<EOF
The connection can be automatically started at the time the modem is
plugged in to the computer.  This is the default.  With this feature
turned off, the connection has to be started manually using the bpw
command.  (You might turn this off for debugging).

EOF

read -p "Automatic dialling (yes/no) [${UDEV_TRIGGERS_PPPD}] ? " -e VALUE
if test -z "${VALUE}"; then
    VALUE=${UDEV_TRIGGERS_PPPD}
fi
UDEV_TRIGGERS_PPPD=${VALUE}
echo ""

# commit
cp /etc/bpw.conf /etc/bpw.conf.orig
cat > /etc/bpw.conf <<EOF
#
#    eee-bpw /etc/bpw.conf configuration settings template
#    Copyright (C) 2008  James Cameron (quozl@laptop.org)
#    written by bpwconfig on `date`
#

#
#    Packet data protocol (PDP) context access point name (APN)
#    for BigPond service, use "telstra.bigpond"
#    for Telstra service, use what you have been told to use.
#
APN="${APN}"
# APN="telstra.pcpack"
# APN="telstra.datapack"
# APN="telstra.internet"

#
#    Username for modem authentication
#    for BigPond service with APN telstra.bigpond use username@bigpond.com
#    for Telstra service with APN telstra.internet use anything
#
USERNAME="${USERNAME}"

#
#    Password for modem authentication
#    for BigPond service use your BigPond password
#    for Telstra service use anything, it is ignored
#
PASSWORD="${PASSWORD}"

#
#    Automatically establish connection when modem is inserted,
#    that is, udev device add triggers internet connection attempt.
#    (Default is yes if not specified here).
#
UDEV_TRIGGERS_PPPD=${UDEV_TRIGGERS_PPPD}
EOF

cat <<EOF
Configuration complete.

The /etc/bpw.conf file has been changed by bpwconfig.
The /etc/bpw.conf.orig file contains the old configuration.

EOF
