• 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
30readonly OTBR_TOP_BUILDDIR="${BUILD_DIR}/otbr"
31readonly OTBR_OPTIONS="${OTBR_OPTIONS:-}"
32readonly REFERENCE_DEVICE="${REFERENCE_DEVICE:-0}"
33
34otbr_uninstall()
35{
36    if have systemctl; then
37        sudo systemctl stop otbr-web || true
38        sudo systemctl stop otbr-agent || true
39        sudo systemctl disable otbr-web || true
40        sudo systemctl disable otbr-agent || true
41        ! sudo systemctl is-enabled otbr-web
42        ! sudo systemctl is-enabled otbr-agent
43    fi
44    sudo killall otbr-web otbr-agent || true
45
46    (
47        if cd "${OTBR_TOP_BUILDDIR}"; then
48            # shellcheck disable=SC2024
49            sudo xargs rm <install_manifests.txt || true
50        fi
51    )
52    if have systemctl; then
53        sudo systemctl daemon-reload
54    fi
55}
56
57otbr_install()
58{
59    local otbr_options=()
60
61    if [[ ${OTBR_OPTIONS} ]]; then
62        read -r -a otbr_options <<<"${OTBR_OPTIONS}"
63    fi
64
65    otbr_options=(
66        "-DBUILD_TESTING=OFF"
67        "-DCMAKE_INSTALL_PREFIX=/usr"
68        "-DOTBR_DBUS=ON"
69        "-DOTBR_DNSSD_DISCOVERY_PROXY=ON"
70        "-DOTBR_SRP_ADVERTISING_PROXY=ON"
71        "-DOTBR_INFRA_IF_NAME=${INFRA_IF_NAME}"
72        "-DOTBR_MDNS=${OTBR_MDNS:=mDNSResponder}"
73        "${otbr_options[@]}"
74    )
75
76    if with WEB_GUI; then
77        otbr_options+=("-DOTBR_WEB=ON")
78    fi
79
80    if with BORDER_ROUTING; then
81        otbr_options+=(
82            "-DOTBR_BORDER_ROUTING=ON"
83        )
84    fi
85
86    if with REST_API; then
87        otbr_options+=("-DOTBR_REST=ON")
88    fi
89
90    if with BACKBONE_ROUTER; then
91        otbr_options+=(
92            "-DOTBR_BACKBONE_ROUTER=ON"
93        )
94        if [[ ${REFERENCE_DEVICE} == "1" ]]; then
95            otbr_options+=(
96                "-DOTBR_DUA_ROUTING=ON"
97            )
98        fi
99    fi
100
101    if [[ ${REFERENCE_DEVICE} == "1" ]]; then
102        otbr_options+=(
103            "-DOTBR_NO_AUTO_ATTACH=1"
104            "-DOT_REFERENCE_DEVICE=ON"
105            "-DOT_DHCP6_CLIENT=ON"
106            "-DOT_DHCP6_SERVER=ON"
107        )
108    fi
109
110    (./script/cmake-build "${otbr_options[@]}" \
111        && cd "${OTBR_TOP_BUILDDIR}" \
112        && ninja \
113        && sudo ninja install)
114
115    if have systemctl; then
116        sudo systemctl reload dbus
117        sudo systemctl daemon-reload
118        without WEB_GUI || sudo systemctl enable otbr-web || true
119        sudo systemctl enable otbr-agent || true
120        sudo systemctl is-enabled otbr-agent || die 'Failed to enable otbr-agent!'
121        without WEB_GUI || sudo systemctl is-enabled otbr-web || die 'Failed to enable otbr-web!'
122
123        if [[ ${REFERENCE_DEVICE} == "1" ]]; then
124            sudo systemctl enable testharness-discovery || true
125            sudo systemctl is-enabled testharness-discovery || die 'Failed to enable otbr-agent!'
126        fi
127    else
128        echo >&2 ' *** WARNING: systemctl not found. otbr cannot start on boot.'
129    fi
130}
131
132otbr_update()
133{
134    otbr_install
135}
136