From: Frank Terbeck Date: Tue, 29 Nov 2011 13:42:10 +0000 (+0100) Subject: zshrc: Move ipv6-tunnel to its own function file X-Git-Tag: v0.5.0~37 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=270ae2f9adf848f4a4244ed460deb3c6b74ab16a zshrc: Move ipv6-tunnel to its own function file Signed-off-by: Frank Terbeck --- diff --git a/doc/grmlzshrc.t2t b/doc/grmlzshrc.t2t index 8c186d6..860115c 100644 --- a/doc/grmlzshrc.t2t +++ b/doc/grmlzshrc.t2t @@ -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. diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 15cfd54..0afb4d2 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -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 index 0000000..b0fc2c6 --- /dev/null +++ b/usr_share_grml/zsh/functions/ipv6-tunnel @@ -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