#!/bin/bash
# client.up.osx.sh - SCRIPT Set name resolution options using the DHCP-delivered# configuration coming over the openvpn tunnel
# Copyright (c) 2005 by OpenVPN Solutions LLC
# Licensed under the GPL version 2
# First version by Jesse Adelman
# someone at boldandbusted dink com
# http://www.boldandbusted.com/
# Modified for OS X by Dylan Muir <dylan@xxxxxxxxxxxxxxxx>
# 17th June, 2005
# Fixes by Angelo Laub <al@rechenknecht.net>, 8th December, 2005
# Rewritten to utilize the OS X SCF by
# Stephan Zalewski <stephan.zalewski@web.de>, 30th January, 2006
# This script is for OS X 10.4 (Tiger) or later only.
# only do something when the server really is pushing somethingn
INTERFACE=$1
IDENTIFYER="org.openvpn.${INTERFACE}"
if [ "$foreign_option_1" != "" ]; then
echo 'foreign option detected'
nOptionIndex=1
nNameServerIndex=1
unset vForOptions
unset vDNS
unset vOptions
while vForOptions=foreign_option_$nOptionIndex; [ -n "${!vForOptions}" ]; do
{
vOptions[nOptionIndex-1]=${!vForOptions}
case ${vOptions[nOptionIndex-1]} in
*DOMAIN* )
domain=${vOptions[nOptionIndex-1]//dhcp-option DOMAIN /}
;;
*DNS* )
vDNS[nNameServerIndex-1]=${vOptions[nOptionIndex-1]//dhcp-option DNS /}
let nNameServerIndex++
;;
esac
let nOptionIndex++
}
done
echo "d.init
d.add ServerAddresses * ${vDNS[*]}
d.add SupplementalMatchDomains * ${domain}
set State:/Network/Service/${IDENTIFYER}/DNS" | scutil
#if [ "${route_vpn_gateway}" != "" ]; then
# echo "d.init
#d.add OverridePrimary # 1
#d.add Router ${route_vpn_gateway}
#d.add InterfaceName ${INTERFACE}
#d.add Addresses * ${ifconfig_local}
#d.add SubnetMasks * ${ifconfig_netmask}
#set State:/Network/Service/${IDENTIFYER}/IPv4" | scutil
#else
echo "d.init
d.add InterfaceName ${INTERFACE}
d.add Addresses * ${ifconfig_local}
d.add SubnetMasks * ${ifconfig_netmask}
set State:/Network/Service/${IDENTIFYER}/IPv4" | scutil
fi
#fi
exit 0