#!/bin/sh
#
# This script is ran after the profile was selected.
# It can be regarded as a post-if-up script for the current profile
#
# Ite receives the following parameters:
# $1 = the root profile directory
# $2 = the selected profile (can be used if multiple profile have
#      the same after-select script)

PROFILE_DIR="${1}"
PROFILE="${2}"

LOGGER="/usr/bin/logger -p daemon.info -t laptop-net:${PROFILE}"


case ${PROFILE} in
	nastynet)
		# You might not like the default route given by DHCP
		${LOGGER} "Reconfiguring default route for profile \"${2}\""
		route del default
		route add default gw mytunnelgw
		;;
	airports)
		${LOGGER} "Configuring DNS tunnel for profile \"${PROFILE}\""
		GW=`/sbin/route -n | grep "UG" | awk '{print $2}'`
		route del default
		TUNNELDNS=`egrep "^[[:space:]]*NSTX_DOMAIN=" /etc/default/nstx | tail -n 1 | awk -F'=' '{print $2}'`
		TUNNELGW=`egrep "[[:space::]]*[^#]*tun|gateway" /etc/network/interfaces | grep tun -A1 | tail -n1 | awk '{print $2}'`
		route add $TUNNELDNS $GW
		route add default gw $TUNNELGW
		;;
	*)
		${LOGGER} "Unknown profile \"${PROFILE}\""
		;;
esac


