zshrc: Move ipv6-tunnel to its own function file
authorFrank Terbeck <ft@bewatermyfriend.org>
Tue, 29 Nov 2011 13:42:10 +0000 (14:42 +0100)
committerMichael Prokop <mika@grml.org>
Tue, 6 Dec 2011 13:50:47 +0000 (14:50 +0100)
Signed-off-by: Frank Terbeck <ft@bewatermyfriend.org>
doc/grmlzshrc.t2t
etc/zsh/zshrc
usr_share_grml/zsh/functions/ipv6-tunnel [new file with mode: 0644]

index 8c186d6..860115c 100644 (file)
@@ -547,10 +547,6 @@ argument means last revision).
 : **hidiff()**
 Outputs highlighted diff; needs highstring(1).
 
-: **ipv6-tunnel()**
-Sets up an IPv6 tunnel on interface sit1. Needs one argument -
-either "start", "stop" or "status".
-
 : **is4()**
 Returns true, if zsh version is equal or greater than 4, else false.
 
index 15cfd54..0afb4d2 100644 (file)
@@ -2243,47 +2243,6 @@ uiae() {
     setxkbmap us && echo 'Done' || echo 'Failed'
 }
 
-# set up an ipv6 tunnel
-ipv6-tunnel() {
-    emulate -L zsh
-    case $1 in
-        start)
-            if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
-                print 'ipv6 tunnel already set up, nothing to be done.'
-                print 'execute: "ifconfig sit1 down ; ifconfig sit0 down" to remove ipv6-tunnel.' ; return 1
-            else
-                [[ -n "$PUBLIC_IP" ]] || \
-                    local PUBLIC_IP=$(ifconfig $(route -n | awk '/^0\.0\.0\.0/{print $8; exit}') | \
-                                      awk '/inet addr:/ {print $2}' | tr -d 'addr:')
-
-                [[ -n "$PUBLIC_IP" ]] || { print 'No $PUBLIC_IP set and could not determine default one.' ; return 1 }
-                local IPV6ADDR=$(printf "2002:%02x%02x:%02x%02x:1::1" $(print ${PUBLIC_IP//./ }))
-                print -n "Setting up ipv6 tunnel $IPV6ADDR via ${PUBLIC_IP}: "
-                ifconfig sit0 tunnel ::192.88.99.1 up
-                ifconfig sit1 add "$IPV6ADDR" && print done || print failed
-            fi
-            ;;
-        status)
-            if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
-                print 'ipv6 tunnel available' ; return 0
-            else
-                print 'ipv6 tunnel not available' ; return 1
-            fi
-            ;;
-        stop)
-            if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
-                print -n 'Stopping ipv6 tunnel (sit0 + sit1): '
-                ifconfig sit1 down ; ifconfig sit0 down && print done || print failed
-            else
-                print 'No ipv6 tunnel found, nothing to be done.' ; return 1
-            fi
-            ;;
-        *)
-            print "Usage: ipv6-tunnel [start|stop|status]">&2 ; return 1
-            ;;
-    esac
-}
-
 # spawn a minimally set up mksh - useful if you want to umount /usr/.
 minimal-shell() {
     emulate -L zsh
diff --git a/usr_share_grml/zsh/functions/ipv6-tunnel b/usr_share_grml/zsh/functions/ipv6-tunnel
new file mode 100644 (file)
index 0000000..b0fc2c6
--- /dev/null
@@ -0,0 +1,42 @@
+# set up an ipv6 tunnel
+emulate -L zsh
+
+case $1 in
+start)
+    if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
+        print 'ipv6 tunnel already set up, nothing to be done.'
+        print 'execute: "ifconfig sit1 down ; ifconfig sit0 down" to remove ipv6-tunnel.' ; return 1
+    else
+        [[ -n "$PUBLIC_IP" ]] || \
+            local PUBLIC_IP=$(ifconfig $(route -n | awk '/^0\.0\.0\.0/{print $8; exit}') | \
+            awk '/inet addr:/ {print $2}' | tr -d 'addr:')
+
+        [[ -n "$PUBLIC_IP" ]] || {
+            print 'No $PUBLIC_IP set and could not determine default one.'
+            return 1
+        }
+        local IPV6ADDR=$(printf "2002:%02x%02x:%02x%02x:1::1" $(print ${PUBLIC_IP//./ }))
+        print -n "Setting up ipv6 tunnel $IPV6ADDR via ${PUBLIC_IP}: "
+        ifconfig sit0 tunnel ::192.88.99.1 up
+        ifconfig sit1 add "$IPV6ADDR" && print done || print failed
+    fi
+    ;;
+status)
+    if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
+        print 'ipv6 tunnel available' ; return 0
+    else
+        print 'ipv6 tunnel not available' ; return 1
+    fi
+    ;;
+stop)
+    if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
+        print -n 'Stopping ipv6 tunnel (sit0 + sit1): '
+        ifconfig sit1 down ; ifconfig sit0 down && print done || print failed
+    else
+        print 'No ipv6 tunnel found, nothing to be done.' ; return 1
+    fi
+    ;;
+*)
+    print "Usage: ipv6-tunnel [start|stop|status]">&2 ; return 1
+    ;;
+esac