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 ################################################################################
23 Usage: "$PN_" [OPTIONS] <tun0> <tun1> ...
25 $PN_ creates persistent tun/tap devices with bridge handling
28 -d delete the given tun devices and remove them from the bridge if given
29 -u <user> this user should be able to use the tun device
30 -g <group> this group should be able to use the tun device
31 -b <bridge> if given, all tun/tap devices are added/removed from the bridge
32 -a enable auto mode, eg. create the bridge if not allready existing and
33 delete it when empty after removing given tun devices
38 function fromCmdline()
43 while (( $# != 0 )); do
55 if [[ $OPT_USER_ != '' ]]; then args_="$args_ -u $OPT_USER_"; fi
56 if [[ $OPT_GROUP_ != '' ]]; then args_="$args_ -u $OPT_GROUP_"; fi
58 if [[ $OPT_BRIDGE_ != '' ]]; then
59 brctl addif "$OPT_BRIDGE_" "$1"
65 if [[ $OPT_BRIDGE_ != '' ]]; then
66 brctl delif "$OPT_BRIDGE_" "$1"
81 while getopts "du:g:b:ah" opt; do
84 u) OPT_USER_="$OPTARG" ;;
85 g) OPT_GROUP_="$OPTARG" ;;
86 b) OPT_BRIDGE_="$OPTARG" ;;
87 a) OPT_AUTO_='true' ;;
88 h) printUsage; exit 0 ;;
89 ?) printUsage; exit 1 ;;
92 shift $(($OPTIND - 1))
94 if [[ $OPT_DEL_ == 'false' ]]; then
95 if [[ $OPT_BRIDGE_ != '' && $OPT_AUTO_ == 'true' ]]; then
96 brctl showmacs "$OPT_BRIDGE_" &>/dev/null || brctl addbr "$OPT_BRIDGE_"
98 fromCmdline "createTun" "$@"
100 fromCmdline "trashTun" "$@"
101 if [[ $OPT_BRIDGE_ != '' && $OPT_AUTO_ == 'true' ]]; then
102 tmp_="`brctl showmacs "$OPT_BRIDGE_" |wc -l`"
103 if (( $tmp_ == 1 )); then
104 brctl delbr "$OPT_BRIDGE_"
106 die "E: bridge $OPT_BRIDGE_ not empty, not removing"