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# Description: 30*4a64e381SAndroid Build Coastguard Worker# This script resolves all dependencies. 31*4a64e381SAndroid Build Coastguard Worker# 32*4a64e381SAndroid Build Coastguard Worker 33*4a64e381SAndroid Build Coastguard Worker# shellcheck source=script/_initrc 34*4a64e381SAndroid Build Coastguard Worker. "$(dirname "$0")"/_initrc 35*4a64e381SAndroid Build Coastguard Worker 36*4a64e381SAndroid Build Coastguard WorkerNAT64_SERVICE="${NAT64_SERVICE:-openthread}" 37*4a64e381SAndroid Build Coastguard Worker 38*4a64e381SAndroid Build Coastguard WorkerFIREWALL="${FIREWALL:-1}" 39*4a64e381SAndroid Build Coastguard Worker 40*4a64e381SAndroid Build Coastguard WorkerOTBR_MDNS="${OTBR_MDNS:-mDNSResponder}" 41*4a64e381SAndroid Build Coastguard WorkerOT_BACKBONE_CI="${OT_BACKBONE_CI:-0}" 42*4a64e381SAndroid Build Coastguard WorkerREFERENCE_DEVICE="${REFERENCE_DEVICE:-0}" 43*4a64e381SAndroid Build Coastguard Worker 44*4a64e381SAndroid Build Coastguard Workerinstall_packages_apt() 45*4a64e381SAndroid Build Coastguard Worker{ 46*4a64e381SAndroid Build Coastguard Worker sudo apt-get update 47*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y \ 48*4a64e381SAndroid Build Coastguard Worker wget \ 49*4a64e381SAndroid Build Coastguard Worker iproute2 \ 50*4a64e381SAndroid Build Coastguard Worker iputils-ping \ 51*4a64e381SAndroid Build Coastguard Worker libreadline-dev \ 52*4a64e381SAndroid Build Coastguard Worker libncurses-dev 53*4a64e381SAndroid Build Coastguard Worker 54*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y build-essential ninja-build cmake 55*4a64e381SAndroid Build Coastguard Worker 56*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y rsyslog 57*4a64e381SAndroid Build Coastguard Worker 58*4a64e381SAndroid Build Coastguard Worker # For DBus server 59*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y dbus libdbus-1-dev 60*4a64e381SAndroid Build Coastguard Worker 61*4a64e381SAndroid Build Coastguard Worker # mDNS 62*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y libavahi-client3 libavahi-common-dev libavahi-client-dev 63*4a64e381SAndroid Build Coastguard Worker 64*4a64e381SAndroid Build Coastguard Worker # Thread Certification tests require Avahi to publish records for tests. Since the 65*4a64e381SAndroid Build Coastguard Worker # same image is used for all tests this needs to be installed here. Additionally 66*4a64e381SAndroid Build Coastguard Worker # Avahi should be included for reference device builds. 67*4a64e381SAndroid Build Coastguard Worker if [[ ${OTBR_MDNS} == "avahi" || ${OT_BACKBONE_CI} == 1 || ${REFERENCE_DEVICE} == 1 ]]; then 68*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y avahi-daemon 69*4a64e381SAndroid Build Coastguard Worker fi 70*4a64e381SAndroid Build Coastguard Worker 71*4a64e381SAndroid Build Coastguard Worker (MDNS_RESPONDER_SOURCE_NAME=mDNSResponder-1790.80.10 \ 72*4a64e381SAndroid Build Coastguard Worker && MDNS_RESPONDER_PATCH_PATH=$(realpath "$(dirname "$0")"/../third_party/mDNSResponder) \ 73*4a64e381SAndroid Build Coastguard Worker && cd /tmp \ 74*4a64e381SAndroid Build Coastguard Worker && wget --no-check-certificate https://github.com/apple-oss-distributions/mDNSResponder/archive/refs/tags/$MDNS_RESPONDER_SOURCE_NAME.tar.gz \ 75*4a64e381SAndroid Build Coastguard Worker && mkdir -p $MDNS_RESPONDER_SOURCE_NAME \ 76*4a64e381SAndroid Build Coastguard Worker && tar xvf $MDNS_RESPONDER_SOURCE_NAME.tar.gz -C $MDNS_RESPONDER_SOURCE_NAME --strip-components=1 \ 77*4a64e381SAndroid Build Coastguard Worker && cd /tmp/"$MDNS_RESPONDER_SOURCE_NAME" \ 78*4a64e381SAndroid Build Coastguard Worker && ( 79*4a64e381SAndroid Build Coastguard Worker for patch in "$MDNS_RESPONDER_PATCH_PATH"/*.patch; do 80*4a64e381SAndroid Build Coastguard Worker patch -p1 <"$patch" 81*4a64e381SAndroid Build Coastguard Worker done 82*4a64e381SAndroid Build Coastguard Worker ) \ 83*4a64e381SAndroid Build Coastguard Worker && cd mDNSPosix \ 84*4a64e381SAndroid Build Coastguard Worker && make os=linux tls=no && sudo make install os=linux tls=no) 85*4a64e381SAndroid Build Coastguard Worker 86*4a64e381SAndroid Build Coastguard Worker # Boost 87*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y libboost-dev libboost-filesystem-dev libboost-system-dev 88*4a64e381SAndroid Build Coastguard Worker 89*4a64e381SAndroid Build Coastguard Worker # nat64 90*4a64e381SAndroid Build Coastguard Worker without NAT64 || { 91*4a64e381SAndroid Build Coastguard Worker [ "$NAT64_SERVICE" != "tayga" ] || sudo apt-get install --no-install-recommends -y tayga 92*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y iptables 93*4a64e381SAndroid Build Coastguard Worker } 94*4a64e381SAndroid Build Coastguard Worker 95*4a64e381SAndroid Build Coastguard Worker # dns64 96*4a64e381SAndroid Build Coastguard Worker without DNS64 || { 97*4a64e381SAndroid Build Coastguard Worker if [ "$PLATFORM" = "beagleboneblack" ]; then 98*4a64e381SAndroid Build Coastguard Worker # dnsmasq needs to be stopped before bind9 is installed 99*4a64e381SAndroid Build Coastguard Worker sudo systemctl disable dnsmasq 100*4a64e381SAndroid Build Coastguard Worker sudo systemctl stop dnsmasq 101*4a64e381SAndroid Build Coastguard Worker fi 102*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y bind9 103*4a64e381SAndroid Build Coastguard Worker # Resolvconf cannot be installed inside docker environment 104*4a64e381SAndroid Build Coastguard Worker if without DOCKER; then 105*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y resolvconf 106*4a64e381SAndroid Build Coastguard Worker fi 107*4a64e381SAndroid Build Coastguard Worker } 108*4a64e381SAndroid Build Coastguard Worker 109*4a64e381SAndroid Build Coastguard Worker # network-manager 110*4a64e381SAndroid Build Coastguard Worker without NETWORK_MANAGER || sudo apt-get install --no-install-recommends -y dnsmasq network-manager 111*4a64e381SAndroid Build Coastguard Worker 112*4a64e381SAndroid Build Coastguard Worker # dhcpcd5 113*4a64e381SAndroid Build Coastguard Worker without DHCPV6_PD || sudo apt-get install --no-install-recommends -y dhcpcd5 114*4a64e381SAndroid Build Coastguard Worker 115*4a64e381SAndroid Build Coastguard Worker # libjsoncpp 116*4a64e381SAndroid Build Coastguard Worker sudo apt-get install --no-install-recommends -y libjsoncpp-dev 117*4a64e381SAndroid Build Coastguard Worker 118*4a64e381SAndroid Build Coastguard Worker # reference device 119*4a64e381SAndroid Build Coastguard Worker without REFERENCE_DEVICE || sudo apt-get install --no-install-recommends -y radvd dnsutils avahi-utils 120*4a64e381SAndroid Build Coastguard Worker 121*4a64e381SAndroid Build Coastguard Worker # backbone-router 122*4a64e381SAndroid Build Coastguard Worker without BACKBONE_ROUTER || sudo apt-get install --no-install-recommends -y libnetfilter-queue1 libnetfilter-queue-dev 123*4a64e381SAndroid Build Coastguard Worker 124*4a64e381SAndroid Build Coastguard Worker # web dependencies 125*4a64e381SAndroid Build Coastguard Worker without WEB_GUI || command -v npm || sudo apt-get install --no-install-recommends -y nodejs npm 126*4a64e381SAndroid Build Coastguard Worker 127*4a64e381SAndroid Build Coastguard Worker # firewall 128*4a64e381SAndroid Build Coastguard Worker sudo apt-get install -y iptables ipset 129*4a64e381SAndroid Build Coastguard Worker 130*4a64e381SAndroid Build Coastguard Worker # protobuf compiler 131*4a64e381SAndroid Build Coastguard Worker sudo apt-get install -y libprotobuf-dev protobuf-compiler 132*4a64e381SAndroid Build Coastguard Worker} 133*4a64e381SAndroid Build Coastguard Worker 134*4a64e381SAndroid Build Coastguard Workerinstall_packages_opkg() 135*4a64e381SAndroid Build Coastguard Worker{ 136*4a64e381SAndroid Build Coastguard Worker die 'opkg not supported currently' 137*4a64e381SAndroid Build Coastguard Worker} 138*4a64e381SAndroid Build Coastguard Worker 139*4a64e381SAndroid Build Coastguard Workerinstall_packages_rpm() 140*4a64e381SAndroid Build Coastguard Worker{ 141*4a64e381SAndroid Build Coastguard Worker if have dnf; then 142*4a64e381SAndroid Build Coastguard Worker PM=dnf 143*4a64e381SAndroid Build Coastguard Worker else 144*4a64e381SAndroid Build Coastguard Worker PM=yum 145*4a64e381SAndroid Build Coastguard Worker fi 146*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y gcc gcc-c++ 147*4a64e381SAndroid Build Coastguard Worker with RELEASE || sudo $PM install -y cmake ninja-build 148*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y dbus-devel 149*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y avahi avahi-devel 150*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y boost-devel boost-filesystem boost-system 151*4a64e381SAndroid Build Coastguard Worker [ "$NAT64_SERVICE" != "tayga" ] || sudo $PM install -y tayga 152*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y iptables 153*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y jsoncpp-devel 154*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y wget 155*4a64e381SAndroid Build Coastguard Worker sudo $PM install -y protobuf protobuf-devel 156*4a64e381SAndroid Build Coastguard Worker} 157*4a64e381SAndroid Build Coastguard Worker 158*4a64e381SAndroid Build Coastguard Workerinstall_packages_brew() 159*4a64e381SAndroid Build Coastguard Worker{ 160*4a64e381SAndroid Build Coastguard Worker brew install boost cmake dbus jsoncpp ninja 161*4a64e381SAndroid Build Coastguard Worker} 162*4a64e381SAndroid Build Coastguard Worker 163*4a64e381SAndroid Build Coastguard Workerinstall_packages_source() 164*4a64e381SAndroid Build Coastguard Worker{ 165*4a64e381SAndroid Build Coastguard Worker die 'source not supported currently' 166*4a64e381SAndroid Build Coastguard Worker} 167*4a64e381SAndroid Build Coastguard Worker 168*4a64e381SAndroid Build Coastguard Workerinstall_packages() 169*4a64e381SAndroid Build Coastguard Worker{ 170*4a64e381SAndroid Build Coastguard Worker if have apt-get; then 171*4a64e381SAndroid Build Coastguard Worker install_packages_apt 172*4a64e381SAndroid Build Coastguard Worker elif have rpm; then 173*4a64e381SAndroid Build Coastguard Worker install_packages_rpm 174*4a64e381SAndroid Build Coastguard Worker elif have opkg; then 175*4a64e381SAndroid Build Coastguard Worker install_packages_opkg 176*4a64e381SAndroid Build Coastguard Worker elif have brew; then 177*4a64e381SAndroid Build Coastguard Worker install_packages_brew 178*4a64e381SAndroid Build Coastguard Worker else 179*4a64e381SAndroid Build Coastguard Worker install_packages_source 180*4a64e381SAndroid Build Coastguard Worker fi 181*4a64e381SAndroid Build Coastguard Worker} 182*4a64e381SAndroid Build Coastguard Worker 183*4a64e381SAndroid Build Coastguard Workermain() 184*4a64e381SAndroid Build Coastguard Worker{ 185*4a64e381SAndroid Build Coastguard Worker . "$BEFORE_HOOK" 186*4a64e381SAndroid Build Coastguard Worker # TODO remove `|| true` after docker hub builder gets its git upgraded 187*4a64e381SAndroid Build Coastguard Worker git submodule update --init --recursive --depth 1 || true 188*4a64e381SAndroid Build Coastguard Worker install_packages 189*4a64e381SAndroid Build Coastguard Worker . "$AFTER_HOOK" 190*4a64e381SAndroid Build Coastguard Worker} 191*4a64e381SAndroid Build Coastguard Worker 192*4a64e381SAndroid Build Coastguard Workermain 193