• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3#  Copyright (c) 2017, 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
30OTBR_TOP_BUILDDIR="${BUILD_DIR}/otbr"
31readonly OTBR_TOP_BUILDDIR
32
33OTBR_OPTIONS="${OTBR_OPTIONS-}"
34readonly OTBR_OPTIONS
35
36REFERENCE_DEVICE="${REFERENCE_DEVICE:-0}"
37readonly REFERENCE_DEVICE
38
39otbr_uninstall()
40{
41    if have systemctl; then
42        sudo systemctl stop otbr-web || true
43        sudo systemctl stop otbr-agent || true
44        sudo systemctl disable otbr-web || true
45        sudo systemctl disable otbr-agent || true
46        ! sudo systemctl is-enabled otbr-web
47        ! sudo systemctl is-enabled otbr-agent
48    fi
49    sudo killall otbr-web otbr-agent || true
50
51    (
52        if cd "${OTBR_TOP_BUILDDIR}"; then
53            # shellcheck disable=SC2024
54            sudo xargs rm <install_manifests.txt || true
55        fi
56    )
57    if have systemctl; then
58        sudo systemctl daemon-reload
59    fi
60}
61
62otbr_install()
63{
64    local otbr_options=()
65
66    if [[ ${OTBR_OPTIONS} ]]; then
67        read -r -a otbr_options <<<"${OTBR_OPTIONS}"
68    fi
69
70    otbr_options=(
71        "-DBUILD_TESTING=OFF"
72        "-DCMAKE_INSTALL_PREFIX=/usr"
73        "-DOTBR_DBUS=ON"
74        "-DOTBR_DNSSD_DISCOVERY_PROXY=ON"
75        "-DOTBR_INFRA_IF_NAME=${INFRA_IF_NAME}"
76        "-DOTBR_MDNS=${OTBR_MDNS:=mDNSResponder}"
77        # Force re-evaluation of version strings
78        "-DOTBR_VERSION="
79        "-DOT_PACKAGE_VERSION="
80        "${otbr_options[@]}"
81    )
82
83    if with DNSSD_PLAT; then
84        otbr_options+=(
85            "-DOTBR_DNSSD_PLAT=ON"
86        )
87    else
88        otbr_options+=(
89            "-DOTBR_SRP_ADVERTISING_PROXY=ON"
90        )
91    fi
92
93    if with WEB_GUI; then
94        otbr_options+=("-DOTBR_WEB=ON")
95    fi
96
97    if with BORDER_ROUTING; then
98        otbr_options+=(
99            "-DOTBR_BORDER_ROUTING=ON"
100        )
101    fi
102
103    if with DHCPV6_PD_REF; then
104        otbr_options+=(
105            "-DOTBR_DHCP6_PD=ON"
106        )
107    fi
108
109    if with REST_API; then
110        otbr_options+=("-DOTBR_REST=ON")
111    fi
112
113    if with BACKBONE_ROUTER; then
114        otbr_options+=(
115            "-DOTBR_BACKBONE_ROUTER=ON"
116        )
117        if [[ ${REFERENCE_DEVICE} == "1" ]]; then
118            otbr_options+=(
119                "-DOTBR_DUA_ROUTING=ON"
120            )
121        fi
122    fi
123
124    if [[ ${REFERENCE_DEVICE} == "1" ]]; then
125        otbr_options+=(
126            "-DOTBR_NO_AUTO_ATTACH=1"
127            "-DOT_REFERENCE_DEVICE=ON"
128            "-DOT_DHCP6_CLIENT=ON"
129            "-DOT_DHCP6_SERVER=ON"
130        )
131    fi
132
133    if with NAT64 && [[ ${NAT64_SERVICE-} == "openthread" ]]; then
134        otbr_options+=(
135            "-DOTBR_NAT64=ON"
136            "-DOT_POSIX_NAT64_CIDR=${NAT64_DYNAMIC_POOL:-192.168.255.0/24}"
137        )
138    fi
139
140    if with NAT64; then
141        otbr_options+=(
142            "-DOTBR_DNS_UPSTREAM_QUERY=ON"
143        )
144    fi
145
146    if with FIREWALL; then
147        otbr_options+=(
148            "-DOT_FIREWALL=ON"
149        )
150    else
151        otbr_options+=(
152            "-DOT_FIREWALL=OFF"
153        )
154    fi
155
156    (./script/cmake-build "${otbr_options[@]}" \
157        && cd "${OTBR_TOP_BUILDDIR}" \
158        && ninja \
159        && sudo ninja install)
160
161    if have systemctl; then
162        sudo systemctl reload dbus
163        sudo systemctl daemon-reload
164        without WEB_GUI || sudo systemctl enable otbr-web || true
165        sudo systemctl enable otbr-agent || true
166        sudo systemctl is-enabled otbr-agent || die 'Failed to enable otbr-agent!'
167        without WEB_GUI || sudo systemctl is-enabled otbr-web || die 'Failed to enable otbr-web!'
168
169        if [[ ${REFERENCE_DEVICE} == "1" ]]; then
170            sudo systemctl enable testharness-discovery || true
171            sudo systemctl is-enabled testharness-discovery || die 'Failed to enable otbr-agent!'
172        fi
173    else
174        echo >&2 ' *** WARNING: systemctl not found. otbr cannot start on boot.'
175    fi
176}
177
178otbr_update()
179{
180    otbr_install
181}
182