jazz/10-01-25: config-tun.sh

File config-tun.sh, 910 bytes (added by jazz, 14 years ago)
Line 
1#!/bin/bash
2# Orig by Ceasar Sun. Modified by Steven Shiau.
3
4WHOAMI="$SUDO_USER"
5VBOX_GROUP="vboxusers"
6TAP_NETWORK="192.168.125"
7TAP_DEV_NUM=0
8DESC="TAP config"
9
10do_start() {
11  if [ ! -x /usr/sbin/tunctl ]; then
12    echo "/usr/sbin/tunctl was NOT found!"
13    exit 1
14  fi
15  tunctl -t tap$TAP_DEV_NUM -u $WHOAMI
16  chown :$VBOX_GROUP /dev/net/tun
17  ifconfig tap$TAP_DEV_NUM &>/dev/null
18  ifconfig tap$TAP_DEV_NUM ${TAP_NETWORK}.254  netmask 255.255.255.0  broadcast ${TAP_NETWORK}.255 promisc
19  ifconfig tap$TAP_DEV_NUM
20}
21
22do_stop() {
23  ifconfig tap$TAP_DEV_NUM down
24}
25do_restart() {
26  do_stop
27  do_start
28}
29check_status() {
30  ifconfig tap$TAP_DEV_NUM 
31}
32
33case $1 in
34  start)    do_start;;
35  stop)     do_stop;;
36  restart)  do_restart;;
37  status)
38            echo "Status of $DESC: "
39            check_status
40            exit "$?"
41            ;;
42  *)
43  echo "Usage: $0 {start|stop|restart|status}"
44  exit 1 
45esac