Installation manual
6. 2. Network Profile Management 59
/usr/local/packages/bin/vpn-select:
#!/bin/sh
PROFILE_DIR="/etc/network/profiles"
PROFILE_STATE_FILE="/var/run/network/profile"
VPN_STATE_FILE="/var/run/network/vpn"
#Load current profile
PROFILE_CUR=‘cat $PROFILE_STATE_FILE | awk ’{print $3}’‘
PROFILE_NEW="offline"
#Select new profile
ADDRESS=‘vpnclient stat tunnel | grep "Client address" | awk ’{print $3}’‘
for PROFILE in $(cd $PROFILE_DIR; ls −d [a−z0−9]* 2> /dev/null); do
PATTERNS="$PROFILE_DIR/$PROFILE/patterns"
if [ −r "$PATTERNS" ]; then
for PATTERN in $(cat $PATTERNS); do
case $ADDRESS in
($PATTERN)
PROFILE_NEW=$PROFILE
break 2
;;
esac
done
fi
done
echo "PROFILE: " $PROFILE_NEW
#Ifthe new and current profiles are the same, exit here
["$PROFILE_NEW" != "$PROFILE_CUR" ] || exit 0
#Run the Stop−Scripts for the current profile
cd $PROFILE_DIR/$PROFILE_CUR/rc.d
for SCRIPT in $(echo "K[0−9][0−9]*"); do
if [ −n "$SCRIPT" ]; then
case "$SCRIPT" in
(*.sh)
/bin/sh ./$SCRIPT stop
;;
(*)
./$SCRIPT stop
;;
esac
fi
done
#Copy all profile specific files for the new profile
cd $PROFILE_DIR/$PROFILE_NEW/files.d
tar cf − . | (cd /; tar xf −)
#Run Start−Scripts for the new profile
cd $PROFILE_DIR/$PROFILE_NEW/rc.d
for SCRIPT in $(echo "S[0−9][0−9]*"); do
if [ −n "$SCRIPT" ]; then
case "$SCRIPT" in
(*.sh)
/bin/sh ./$SCRIPT start
;;
(*)
./$SCRIPT start
;;
esac
fi
done
#Save new profile
echo $PROFILE_CUR" −−> "$PROFILE_NEW > $VPN_STATE_FILE
/usr/local/packages/bin/vpn-deselect:
#!/bin/sh
PROFILE_DIR="/etc/network/profiles"
PROFILE_STATE_FILE="/var/run/network/profile"
VPN_STATE_FILE="/var/run/network/vpn"