xref: /aosp_15_r20/external/ot-br-posix/script/_otbr (revision 4a64e381480ef79f0532b2421e44e6ee336b8e0d)
1*4a64e381SAndroid Build Coastguard Worker#!/bin/bash
2*4a64e381SAndroid Build Coastguard Worker#
3*4a64e381SAndroid Build Coastguard Worker#  Copyright (c) 2017, The OpenThread Authors.
4*4a64e381SAndroid Build Coastguard Worker#  All rights reserved.
5*4a64e381SAndroid Build Coastguard Worker#
6*4a64e381SAndroid Build Coastguard Worker#  Redistribution and use in source and binary forms, with or without
7*4a64e381SAndroid Build Coastguard Worker#  modification, are permitted provided that the following conditions are met:
8*4a64e381SAndroid Build Coastguard Worker#  1. Redistributions of source code must retain the above copyright
9*4a64e381SAndroid Build Coastguard Worker#     notice, this list of conditions and the following disclaimer.
10*4a64e381SAndroid Build Coastguard Worker#  2. Redistributions in binary form must reproduce the above copyright
11*4a64e381SAndroid Build Coastguard Worker#     notice, this list of conditions and the following disclaimer in the
12*4a64e381SAndroid Build Coastguard Worker#     documentation and/or other materials provided with the distribution.
13*4a64e381SAndroid Build Coastguard Worker#  3. Neither the name of the copyright holder nor the
14*4a64e381SAndroid Build Coastguard Worker#     names of its contributors may be used to endorse or promote products
15*4a64e381SAndroid Build Coastguard Worker#     derived from this software without specific prior written permission.
16*4a64e381SAndroid Build Coastguard Worker#
17*4a64e381SAndroid Build Coastguard Worker#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*4a64e381SAndroid Build Coastguard Worker#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*4a64e381SAndroid Build Coastguard Worker#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*4a64e381SAndroid Build Coastguard Worker#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21*4a64e381SAndroid Build Coastguard Worker#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*4a64e381SAndroid Build Coastguard Worker#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*4a64e381SAndroid Build Coastguard Worker#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*4a64e381SAndroid Build Coastguard Worker#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*4a64e381SAndroid Build Coastguard Worker#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*4a64e381SAndroid Build Coastguard Worker#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*4a64e381SAndroid Build Coastguard Worker#  POSSIBILITY OF SUCH DAMAGE.
28*4a64e381SAndroid Build Coastguard Worker#
29*4a64e381SAndroid Build Coastguard Worker
30*4a64e381SAndroid Build Coastguard WorkerOTBR_TOP_BUILDDIR="${BUILD_DIR}/otbr"
31*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_TOP_BUILDDIR
32*4a64e381SAndroid Build Coastguard Worker
33*4a64e381SAndroid Build Coastguard WorkerOTBR_OPTIONS="${OTBR_OPTIONS-}"
34*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_OPTIONS
35*4a64e381SAndroid Build Coastguard Worker
36*4a64e381SAndroid Build Coastguard WorkerREFERENCE_DEVICE="${REFERENCE_DEVICE:-0}"
37*4a64e381SAndroid Build Coastguard Workerreadonly REFERENCE_DEVICE
38*4a64e381SAndroid Build Coastguard Worker
39*4a64e381SAndroid Build Coastguard Workerotbr_uninstall()
40*4a64e381SAndroid Build Coastguard Worker{
41*4a64e381SAndroid Build Coastguard Worker    if have systemctl; then
42*4a64e381SAndroid Build Coastguard Worker        sudo systemctl stop otbr-web || true
43*4a64e381SAndroid Build Coastguard Worker        sudo systemctl stop otbr-agent || true
44*4a64e381SAndroid Build Coastguard Worker        sudo systemctl disable otbr-web || true
45*4a64e381SAndroid Build Coastguard Worker        sudo systemctl disable otbr-agent || true
46*4a64e381SAndroid Build Coastguard Worker        ! sudo systemctl is-enabled otbr-web
47*4a64e381SAndroid Build Coastguard Worker        ! sudo systemctl is-enabled otbr-agent
48*4a64e381SAndroid Build Coastguard Worker    fi
49*4a64e381SAndroid Build Coastguard Worker    sudo killall otbr-web otbr-agent || true
50*4a64e381SAndroid Build Coastguard Worker
51*4a64e381SAndroid Build Coastguard Worker    (
52*4a64e381SAndroid Build Coastguard Worker        if cd "${OTBR_TOP_BUILDDIR}"; then
53*4a64e381SAndroid Build Coastguard Worker            # shellcheck disable=SC2024
54*4a64e381SAndroid Build Coastguard Worker            sudo xargs rm <install_manifests.txt || true
55*4a64e381SAndroid Build Coastguard Worker        fi
56*4a64e381SAndroid Build Coastguard Worker    )
57*4a64e381SAndroid Build Coastguard Worker    if have systemctl; then
58*4a64e381SAndroid Build Coastguard Worker        sudo systemctl daemon-reload
59*4a64e381SAndroid Build Coastguard Worker    fi
60*4a64e381SAndroid Build Coastguard Worker}
61*4a64e381SAndroid Build Coastguard Worker
62*4a64e381SAndroid Build Coastguard Workerotbr_install()
63*4a64e381SAndroid Build Coastguard Worker{
64*4a64e381SAndroid Build Coastguard Worker    local otbr_options=()
65*4a64e381SAndroid Build Coastguard Worker
66*4a64e381SAndroid Build Coastguard Worker    if [[ ${OTBR_OPTIONS} ]]; then
67*4a64e381SAndroid Build Coastguard Worker        read -r -a otbr_options <<<"${OTBR_OPTIONS}"
68*4a64e381SAndroid Build Coastguard Worker    fi
69*4a64e381SAndroid Build Coastguard Worker
70*4a64e381SAndroid Build Coastguard Worker    otbr_options=(
71*4a64e381SAndroid Build Coastguard Worker        "-DBUILD_TESTING=OFF"
72*4a64e381SAndroid Build Coastguard Worker        "-DCMAKE_INSTALL_PREFIX=/usr"
73*4a64e381SAndroid Build Coastguard Worker        "-DOTBR_DBUS=ON"
74*4a64e381SAndroid Build Coastguard Worker        "-DOTBR_DNSSD_DISCOVERY_PROXY=ON"
75*4a64e381SAndroid Build Coastguard Worker        "-DOTBR_SRP_ADVERTISING_PROXY=ON"
76*4a64e381SAndroid Build Coastguard Worker        "-DOTBR_INFRA_IF_NAME=${INFRA_IF_NAME}"
77*4a64e381SAndroid Build Coastguard Worker        "-DOTBR_MDNS=${OTBR_MDNS:=mDNSResponder}"
78*4a64e381SAndroid Build Coastguard Worker        # Force re-evaluation of version strings
79*4a64e381SAndroid Build Coastguard Worker        "-DOTBR_VERSION="
80*4a64e381SAndroid Build Coastguard Worker        "-DOT_PACKAGE_VERSION="
81*4a64e381SAndroid Build Coastguard Worker        "${otbr_options[@]}"
82*4a64e381SAndroid Build Coastguard Worker    )
83*4a64e381SAndroid Build Coastguard Worker
84*4a64e381SAndroid Build Coastguard Worker    if with WEB_GUI; then
85*4a64e381SAndroid Build Coastguard Worker        otbr_options+=("-DOTBR_WEB=ON")
86*4a64e381SAndroid Build Coastguard Worker    fi
87*4a64e381SAndroid Build Coastguard Worker
88*4a64e381SAndroid Build Coastguard Worker    if with BORDER_ROUTING; then
89*4a64e381SAndroid Build Coastguard Worker        otbr_options+=(
90*4a64e381SAndroid Build Coastguard Worker            "-DOTBR_BORDER_ROUTING=ON"
91*4a64e381SAndroid Build Coastguard Worker        )
92*4a64e381SAndroid Build Coastguard Worker    fi
93*4a64e381SAndroid Build Coastguard Worker
94*4a64e381SAndroid Build Coastguard Worker    if with REST_API; then
95*4a64e381SAndroid Build Coastguard Worker        otbr_options+=("-DOTBR_REST=ON")
96*4a64e381SAndroid Build Coastguard Worker    fi
97*4a64e381SAndroid Build Coastguard Worker
98*4a64e381SAndroid Build Coastguard Worker    if with BACKBONE_ROUTER; then
99*4a64e381SAndroid Build Coastguard Worker        otbr_options+=(
100*4a64e381SAndroid Build Coastguard Worker            "-DOTBR_BACKBONE_ROUTER=ON"
101*4a64e381SAndroid Build Coastguard Worker        )
102*4a64e381SAndroid Build Coastguard Worker        if [[ ${REFERENCE_DEVICE} == "1" ]]; then
103*4a64e381SAndroid Build Coastguard Worker            otbr_options+=(
104*4a64e381SAndroid Build Coastguard Worker                "-DOTBR_DUA_ROUTING=ON"
105*4a64e381SAndroid Build Coastguard Worker            )
106*4a64e381SAndroid Build Coastguard Worker        fi
107*4a64e381SAndroid Build Coastguard Worker    fi
108*4a64e381SAndroid Build Coastguard Worker
109*4a64e381SAndroid Build Coastguard Worker    if [[ ${REFERENCE_DEVICE} == "1" ]]; then
110*4a64e381SAndroid Build Coastguard Worker        otbr_options+=(
111*4a64e381SAndroid Build Coastguard Worker            "-DOTBR_NO_AUTO_ATTACH=1"
112*4a64e381SAndroid Build Coastguard Worker            "-DOT_REFERENCE_DEVICE=ON"
113*4a64e381SAndroid Build Coastguard Worker            "-DOT_DHCP6_CLIENT=ON"
114*4a64e381SAndroid Build Coastguard Worker            "-DOT_DHCP6_SERVER=ON"
115*4a64e381SAndroid Build Coastguard Worker        )
116*4a64e381SAndroid Build Coastguard Worker    fi
117*4a64e381SAndroid Build Coastguard Worker
118*4a64e381SAndroid Build Coastguard Worker    if with NAT64 && [[ ${NAT64_SERVICE-} == "openthread" ]]; then
119*4a64e381SAndroid Build Coastguard Worker        otbr_options+=(
120*4a64e381SAndroid Build Coastguard Worker            "-DOTBR_NAT64=ON"
121*4a64e381SAndroid Build Coastguard Worker            "-DOT_POSIX_NAT64_CIDR=${NAT64_DYNAMIC_POOL:-192.168.255.0/24}"
122*4a64e381SAndroid Build Coastguard Worker        )
123*4a64e381SAndroid Build Coastguard Worker    fi
124*4a64e381SAndroid Build Coastguard Worker
125*4a64e381SAndroid Build Coastguard Worker    if with NAT64; then
126*4a64e381SAndroid Build Coastguard Worker        otbr_options+=(
127*4a64e381SAndroid Build Coastguard Worker            "-DOTBR_DNS_UPSTREAM_QUERY=ON"
128*4a64e381SAndroid Build Coastguard Worker        )
129*4a64e381SAndroid Build Coastguard Worker    fi
130*4a64e381SAndroid Build Coastguard Worker
131*4a64e381SAndroid Build Coastguard Worker    if with FIREWALL; then
132*4a64e381SAndroid Build Coastguard Worker        otbr_options+=(
133*4a64e381SAndroid Build Coastguard Worker            "-DOT_FIREWALL=ON"
134*4a64e381SAndroid Build Coastguard Worker        )
135*4a64e381SAndroid Build Coastguard Worker    else
136*4a64e381SAndroid Build Coastguard Worker        otbr_options+=(
137*4a64e381SAndroid Build Coastguard Worker            "-DOT_FIREWALL=OFF"
138*4a64e381SAndroid Build Coastguard Worker        )
139*4a64e381SAndroid Build Coastguard Worker    fi
140*4a64e381SAndroid Build Coastguard Worker
141*4a64e381SAndroid Build Coastguard Worker    (./script/cmake-build "${otbr_options[@]}" \
142*4a64e381SAndroid Build Coastguard Worker        && cd "${OTBR_TOP_BUILDDIR}" \
143*4a64e381SAndroid Build Coastguard Worker        && ninja \
144*4a64e381SAndroid Build Coastguard Worker        && sudo ninja install)
145*4a64e381SAndroid Build Coastguard Worker
146*4a64e381SAndroid Build Coastguard Worker    if have systemctl; then
147*4a64e381SAndroid Build Coastguard Worker        sudo systemctl reload dbus
148*4a64e381SAndroid Build Coastguard Worker        sudo systemctl daemon-reload
149*4a64e381SAndroid Build Coastguard Worker        without WEB_GUI || sudo systemctl enable otbr-web || true
150*4a64e381SAndroid Build Coastguard Worker        sudo systemctl enable otbr-agent || true
151*4a64e381SAndroid Build Coastguard Worker        sudo systemctl is-enabled otbr-agent || die 'Failed to enable otbr-agent!'
152*4a64e381SAndroid Build Coastguard Worker        without WEB_GUI || sudo systemctl is-enabled otbr-web || die 'Failed to enable otbr-web!'
153*4a64e381SAndroid Build Coastguard Worker
154*4a64e381SAndroid Build Coastguard Worker        if [[ ${REFERENCE_DEVICE} == "1" ]]; then
155*4a64e381SAndroid Build Coastguard Worker            sudo systemctl enable testharness-discovery || true
156*4a64e381SAndroid Build Coastguard Worker            sudo systemctl is-enabled testharness-discovery || die 'Failed to enable otbr-agent!'
157*4a64e381SAndroid Build Coastguard Worker        fi
158*4a64e381SAndroid Build Coastguard Worker    else
159*4a64e381SAndroid Build Coastguard Worker        echo >&2 ' *** WARNING: systemctl not found. otbr cannot start on boot.'
160*4a64e381SAndroid Build Coastguard Worker    fi
161*4a64e381SAndroid Build Coastguard Worker}
162*4a64e381SAndroid Build Coastguard Worker
163*4a64e381SAndroid Build Coastguard Workerotbr_update()
164*4a64e381SAndroid Build Coastguard Worker{
165*4a64e381SAndroid Build Coastguard Worker    otbr_install
166*4a64e381SAndroid Build Coastguard Worker}
167