-
Notifications
You must be signed in to change notification settings - Fork 0
/
up_tun.sh
executable file
·62 lines (46 loc) · 1.25 KB
/
up_tun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
if [ $UID -ne 0 ]; then echo "restart as root"; sudo "$0" "$@"; exit; fi
cd "$(dirname "$0")"
trap 'kill $(jobs -p)' EXIT
# options may be followed by one colon to indicate they have a required argument
if ! options=$(getopt -o '' -l dev-type:,intn: -- "$@")
then
exit 1
fi
eval set -- "$options"
while [ $# -gt 0 ]
do
case $1 in
--dev-type) dev_type="$2"; shift ;;
--intn) intn="$2"; shift ;;
(--) shift; break;;
(*) echo "Incorrect parameter: $1"; exit 1;;
esac
shift
done
self6="fdcd::80:00" # 80:00:00
params="--self6=$self6"
[ "$dev_type" == "" ] && dev_type="tty"
params="$params --dev-type=$dev_type"
if [ "$dev_type" == "spi" ]; then
[ "$intn" == "" ] && intn="25"
params="$params --intn=$intn"
fi
echo "invoke: ./cdnet_tun $params"
./cdnet_tun $params &
sleep 0.1
echo "bring tun0 to up, and set ip to it"
ip link set tun0 up
rm_ip=$(ip -6 -br addr show dev tun0)
IFS=' ' read -r -a array <<< "$rm_ip"
rm_ip="${array[2]}"
[ "$rm_ip" != "" ] && ip addr del "$rm_ip" dev tun0
ip addr add "$self6/64" dev tun0
if [ "$router6" != "" ]; then
echo "add default gw: $router6"
route add default gw "$router6"
fi
echo "set ip6 done:"
ip -6 -br addr show dev tun0
# type ctrl-c to exit
sleep infinity