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 --debug-level) 62 DEBUG_LEVEL=$2 63 shift 64 shift 65 ;; 66 *) 67 shift 68 ;; 69 esac 70 done 71} 72 73function shutdown() 74{ 75 echo "Shutting down" 76 /app/script/server shutdown 77 exit 0 78} 79 80trap shutdown TERM INT 81 82parse_args "$@" 83 84[ -n "$RADIO_URL" ] || RADIO_URL="spinel+hdlc+uart:///dev/ttyUSB0" 85[ -n "$TREL_URL" ] || TREL_URL="" 86[ -n "$TUN_INTERFACE_NAME" ] || TUN_INTERFACE_NAME="wpan0" 87[ -n "$BACKBONE_INTERFACE" ] || BACKBONE_INTERFACE="eth0" 88[ -n "$NAT64_PREFIX" ] || NAT64_PREFIX="64:ff9b::/96" 89[ -n "$DEBUG_LEVEL" ] || DEBUG_LEVEL="7" 90 91echo "RADIO_URL:" $RADIO_URL 92echo "TREL_URL:" "$TREL_URL" 93echo "TUN_INTERFACE_NAME:" $TUN_INTERFACE_NAME 94echo "BACKBONE_INTERFACE: $BACKBONE_INTERFACE" 95echo "NAT64_PREFIX:" $NAT64_PREFIX 96echo "DEBUG_LEVEL:" $DEBUG_LEVEL 97 98NAT64_PREFIX=${NAT64_PREFIX/\//\\\/} 99TAYGA_CONF=/etc/tayga.conf 100BIND_CONF_OPTIONS=/etc/bind/named.conf.options 101 102! test -f $TAYGA_CONF || sed -i "s/^prefix.*$/prefix $NAT64_PREFIX/" $TAYGA_CONF 103! test -f $BIND_CONF_OPTIONS || sed -i "s/dns64.*$/dns64 $NAT64_PREFIX {};/" $BIND_CONF_OPTIONS 104sed -i "s/$INFRA_IF_NAME/$BACKBONE_INTERFACE/" /etc/sysctl.d/60-otbr-accept-ra.conf 105 106echo "OTBR_AGENT_OPTS=\"-I $TUN_INTERFACE_NAME -B $BACKBONE_INTERFACE -d${DEBUG_LEVEL} $RADIO_URL $TREL_URL\"" >/etc/default/otbr-agent 107echo "OTBR_WEB_OPTS=\"-I $TUN_INTERFACE_NAME -d${DEBUG_LEVEL} -p 80\"" >/etc/default/otbr-web 108 109/app/script/server 110 111while [[ ! -f /var/log/syslog ]]; do 112 sleep 1 113done 114 115tail -f /var/log/syslog & 116wait $! 117