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 fi 70 71 (MDNS_RESPONDER_SOURCE_NAME=mDNSResponder-1790.80.10 \ 72 && MDNS_RESPONDER_PATCH_PATH=$(realpath "$(dirname "$0")"/../third_party/mDNSResponder) \ 73 && cd /tmp \ 74 && wget --no-check-certificate https://github.com/apple-oss-distributions/mDNSResponder/archive/refs/tags/$MDNS_RESPONDER_SOURCE_NAME.tar.gz \ 75 && mkdir -p $MDNS_RESPONDER_SOURCE_NAME \ 76 && tar xvf $MDNS_RESPONDER_SOURCE_NAME.tar.gz -C $MDNS_RESPONDER_SOURCE_NAME --strip-components=1 \ 77 && cd /tmp/"$MDNS_RESPONDER_SOURCE_NAME" \ 78 && ( 79 for patch in "$MDNS_RESPONDER_PATCH_PATH"/*.patch; do 80 patch -p1 <"$patch" 81 done 82 ) \ 83 && cd mDNSPosix \ 84 && make os=linux tls=no && sudo make install os=linux tls=no) 85 86 # Boost 87 sudo apt-get install --no-install-recommends -y libboost-dev libboost-filesystem-dev libboost-system-dev 88 89 # nat64 90 without NAT64 || { 91 [ "$NAT64_SERVICE" != "tayga" ] || sudo apt-get install --no-install-recommends -y tayga 92 sudo apt-get install --no-install-recommends -y iptables 93 } 94 95 # dns64 96 without DNS64 || { 97 if [ "$PLATFORM" = "beagleboneblack" ]; then 98 # dnsmasq needs to be stopped before bind9 is installed 99 sudo systemctl disable dnsmasq 100 sudo systemctl stop dnsmasq 101 fi 102 sudo apt-get install --no-install-recommends -y bind9 103 # Resolvconf cannot be installed inside docker environment 104 if without DOCKER; then 105 sudo apt-get install --no-install-recommends -y resolvconf 106 fi 107 } 108 109 # network-manager 110 without NETWORK_MANAGER || sudo apt-get install --no-install-recommends -y dnsmasq network-manager 111 112 # dhcpcd5 113 without DHCPV6_PD || sudo apt-get install --no-install-recommends -y dhcpcd5 114 115 # libjsoncpp 116 sudo apt-get install --no-install-recommends -y libjsoncpp-dev 117 118 # reference device 119 without REFERENCE_DEVICE || sudo apt-get install --no-install-recommends -y radvd dnsutils avahi-utils 120 121 # backbone-router 122 without BACKBONE_ROUTER || sudo apt-get install --no-install-recommends -y libnetfilter-queue1 libnetfilter-queue-dev 123 124 # web dependencies 125 without WEB_GUI || command -v npm || sudo apt-get install --no-install-recommends -y nodejs npm 126 127 # firewall 128 sudo apt-get install -y iptables ipset 129 130 # protobuf compiler 131 sudo apt-get install -y libprotobuf-dev protobuf-compiler 132} 133 134install_packages_opkg() 135{ 136 die 'opkg not supported currently' 137} 138 139install_packages_rpm() 140{ 141 if have dnf; then 142 PM=dnf 143 else 144 PM=yum 145 fi 146 sudo $PM install -y gcc gcc-c++ 147 with RELEASE || sudo $PM install -y cmake ninja-build 148 sudo $PM install -y dbus-devel 149 sudo $PM install -y avahi avahi-devel 150 sudo $PM install -y boost-devel boost-filesystem boost-system 151 [ "$NAT64_SERVICE" != "tayga" ] || sudo $PM install -y tayga 152 sudo $PM install -y iptables 153 sudo $PM install -y jsoncpp-devel 154 sudo $PM install -y wget 155 sudo $PM install -y protobuf protobuf-devel 156} 157 158install_packages_brew() 159{ 160 brew install boost cmake dbus jsoncpp ninja 161} 162 163install_packages_source() 164{ 165 die 'source not supported currently' 166} 167 168install_packages() 169{ 170 if have apt-get; then 171 install_packages_apt 172 elif have rpm; then 173 install_packages_rpm 174 elif have opkg; then 175 install_packages_opkg 176 elif have brew; then 177 install_packages_brew 178 else 179 install_packages_source 180 fi 181} 182 183main() 184{ 185 . "$BEFORE_HOOK" 186 # TODO remove `|| true` after docker hub builder gets its git upgraded 187 git submodule update --init --recursive --depth 1 || true 188 install_packages 189 . "$AFTER_HOOK" 190} 191 192main 193