• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3#  Copyright (c) 2018, The OpenThread Authors.
4#  All rights reserved.
5#
6#  Redistribution and use in source and binary forms, with or without
7#  modification, are permitted provided that the following conditions are met:
8#  1. Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10#  2. Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#  3. Neither the name of the copyright holder nor the
14#     names of its contributors may be used to endorse or promote products
15#     derived from this software without specific prior written permission.
16#
17#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27#  POSSIBILITY OF SUCH DAMAGE.
28#
29
30export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
31
32function parse_args()
33{
34    while [ $# -gt 0 ]; do
35        case $1 in
36            --radio-url)
37                RADIO_URL="$2"
38                shift
39                shift
40                ;;
41            --trel-url)
42                TREL_URL="$2"
43                shift
44                shift
45                ;;
46            --interface | -I)
47                TUN_INTERFACE_NAME=$2
48                shift
49                shift
50                ;;
51            --backbone-interface | -B)
52                BACKBONE_INTERFACE=$2
53                shift
54                shift
55                ;;
56            --nat64-prefix)
57                NAT64_PREFIX=$2
58                shift
59                shift
60                ;;
61            *)
62                shift
63                ;;
64        esac
65    done
66}
67
68function shutdown()
69{
70    echo "Shutting down"
71    /app/script/server shutdown
72    exit 0
73}
74
75trap shutdown TERM INT
76
77parse_args "$@"
78
79[ -n "$RADIO_URL" ] || RADIO_URL="spinel+hdlc+uart:///dev/ttyUSB0"
80[ -n "$TREL_URL" ] || TREL_URL=""
81[ -n "$TUN_INTERFACE_NAME" ] || TUN_INTERFACE_NAME="wpan0"
82[ -n "$BACKBONE_INTERFACE" ] || BACKBONE_INTERFACE="eth0"
83[ -n "$NAT64_PREFIX" ] || NAT64_PREFIX="64:ff9b::/96"
84
85echo "RADIO_URL:" $RADIO_URL
86echo "TREL_URL:" "$TREL_URL"
87echo "TUN_INTERFACE_NAME:" $TUN_INTERFACE_NAME
88echo "BACKBONE_INTERFACE: $BACKBONE_INTERFACE"
89echo "NAT64_PREFIX:" $NAT64_PREFIX
90
91NAT64_PREFIX=${NAT64_PREFIX/\//\\\/}
92TAYGA_CONF=/etc/tayga.conf
93BIND_CONF_OPTIONS=/etc/bind/named.conf.options
94
95! test -f $TAYGA_CONF || sed -i "s/^prefix.*$/prefix $NAT64_PREFIX/" $TAYGA_CONF
96! test -f $BIND_CONF_OPTIONS || sed -i "s/dns64.*$/dns64 $NAT64_PREFIX {};/" $BIND_CONF_OPTIONS
97sed -i "s/$INFRA_IF_NAME/$BACKBONE_INTERFACE/" /etc/sysctl.d/60-otbr-accept-ra.conf
98
99echo "OTBR_AGENT_OPTS=\"-I $TUN_INTERFACE_NAME -B $BACKBONE_INTERFACE -d7 $RADIO_URL $TREL_URL\"" >/etc/default/otbr-agent
100echo "OTBR_WEB_OPTS=\"-I $TUN_INTERFACE_NAME -d7 -p 80\"" >/etc/default/otbr-web
101
102/app/script/server
103
104while [[ ! -f /var/log/syslog ]]; do
105    sleep 1
106done
107
108tail -f /var/log/syslog &
109wait $!
110