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