shfmt tunsocks.sh
This commit is contained in:
parent
2b1095760f
commit
ba4bbfa18c
10
tunsocks.sh
10
tunsocks.sh
@ -8,19 +8,18 @@ nsname="$1"
|
|||||||
device="tun${nsname}"
|
device="tun${nsname}"
|
||||||
ns="${nsname}ns"
|
ns="${nsname}ns"
|
||||||
|
|
||||||
if [ "$2" = use_env ];then
|
if [ "$2" = use_env ]; then
|
||||||
proxy="$SOCKS_PROXY"
|
proxy="$SOCKS_PROXY"
|
||||||
shift
|
shift
|
||||||
else
|
else
|
||||||
proxy="socks5:///run/nnss-${nsname}/sock"
|
proxy="socks5:///run/nnss-${nsname}/sock"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setup()
|
setup() {
|
||||||
{
|
|
||||||
ip tuntap add mode tun dev "$device"
|
ip tuntap add mode tun dev "$device"
|
||||||
|
|
||||||
/usr/bin/tun2socks -device "$device" -proxy "$proxy" &
|
/usr/bin/tun2socks -device "$device" -proxy "$proxy" &
|
||||||
echo "$!" > "$pidfile"
|
echo "$!" >"$pidfile"
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
ip netns add "$ns"
|
ip netns add "$ns"
|
||||||
@ -34,8 +33,7 @@ setup()
|
|||||||
wait
|
wait
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup()
|
cleanup() {
|
||||||
{
|
|
||||||
ip tuntap del mode tun dev "$device" || true
|
ip tuntap del mode tun dev "$device" || true
|
||||||
kill "$(cat "$pidfile")"
|
kill "$(cat "$pidfile")"
|
||||||
ip -n "$ns" tuntap del mode tun dev "$device"
|
ip -n "$ns" tuntap del mode tun dev "$device"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user