2 # Filename: grml-addtun
3 # Purpose: Program to create tun/tap devices and add them to a bridge
4 # Authors: Michael Gebetsroither <gebi@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
22 Usage: "$PN_" [OPTIONS] <tun0> <tun1> ...
24 $PN_ creates persistent tun/tap devices with bridge handling
27 -d delete the given tun devices and remove them from the bridge if given
28 -u <user> this user should be able to use the tun device
29 -g <group> this group should be able to use the tun device
30 -b <bridge> if given, all tun/tap devices are added/removed from the bridge
31 bridge is created if not allready existent
36 function fromCmdline()
41 while (( $# != 0 )); do
53 if [[ $OPT_USER_ != '' ]]; then args_="$args_ -u $OPT_USER_"; fi
54 if [[ $OPT_GROUP_ != '' ]]; then args_="$args_ -u $OPT_GROUP_"; fi
56 if [[ $OPT_BRIDGE_ != '' ]]; then
57 brctl addif "$OPT_BRIDGE_" "$1"
63 if [[ $OPT_BRIDGE_ != '' ]]; then
64 brctl delif "$OPT_BRIDGE_" "$1"
79 while getopts "du:g:b:h" opt; do
82 u) OPT_USER_="$OPTARG" ;;
83 g) OPT_GROUP_="$OPTARG" ;;
84 b) OPT_BRIDGE_="$OPTARG" ;;
85 h) printUsage; exit 0 ;;
86 ?) printUsage; exit 1 ;;
89 shift $(($OPTIND - 1))
91 if [[ $OPT_DEL_ == 'false' ]]; then
92 if [[ $OPT_BRIDGE_ != '' ]]; then
93 brctl showmacs "$OPT_BRIDGE_" &>/dev/null || brctl addbr "$OPT_BRIDGE_"
95 fromCmdline "createTun" "$@"
97 fromCmdline "trashTun" "$@"
98 if [[ $OPT_BRIDGE_ != '' ]]; then
99 tmp_="`brctl showmacs "$OPT_BRIDGE_" |wc -l`"
100 if (( $tmp_ == 1 )); then
101 brctl delbr "$OPT_BRIDGE_"
103 die "E: bridge $OPT_BRIDGE_ not empty, not removing"