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 30set -euxo pipefail 31 32TOOLS_HOME="$HOME"/.cache/tools 33[[ -d $TOOLS_HOME ]] || mkdir -p "$TOOLS_HOME" 34 35MDNSRESPONDER_PATCH_PATH=$(realpath "$(dirname "$0")"/../../third_party/mDNSResponder) 36 37disable_install_recommends() 38{ 39 OTBR_APT_CONF_FILE=/etc/apt/apt.conf 40 41 if [[ -f ${OTBR_APT_CONF_FILE} ]] && grep Install-Recommends "${OTBR_APT_CONF_FILE}"; then 42 return 0 43 fi 44 45 sudo tee -a /etc/apt/apt.conf <<EOF 46APT::Get::Install-Recommends "false"; 47APT::Get::Install-Suggests "false"; 48EOF 49} 50 51install_common_dependencies() 52{ 53 # Common dependencies 54 sudo apt-get install --no-install-recommends -y \ 55 libdbus-1-dev \ 56 ninja-build \ 57 doxygen \ 58 expect \ 59 net-tools \ 60 libavahi-common-dev \ 61 libavahi-client-dev \ 62 libreadline-dev \ 63 libncurses-dev \ 64 libjsoncpp-dev \ 65 coreutils \ 66 git \ 67 libprotobuf-dev \ 68 protobuf-compiler 69} 70 71install_openthread_binraries() 72{ 73 pip3 install -U pip 74 pip3 install -U cmake 75 cd third_party/openthread/repo 76 mkdir -p build && cd build 77 78 cmake .. -GNinja -DOT_PLATFORM=simulation -DOT_FULL_LOGS=1 -DOT_COMMISSIONER=ON -DOT_JOINER=ON 79 ninja 80 sudo ninja install 81} 82 83configure_network() 84{ 85 echo 0 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6 86 echo 1 | sudo tee /proc/sys/net/ipv6/conf/all/forwarding 87 echo 1 | sudo tee /proc/sys/net/ipv4/conf/all/forwarding 88} 89 90case "$(uname)" in 91 "Linux") 92 disable_install_recommends 93 sudo apt-get update 94 install_common_dependencies 95 96 if [ "$BUILD_TARGET" == script-check ] || [ "$BUILD_TARGET" == docker-check ]; then 97 sudo bash third_party/openthread/repo/script/install_socat 98 install_openthread_binraries 99 configure_network 100 exit 0 101 fi 102 103 if [ "$BUILD_TARGET" == check ] || [ "$BUILD_TARGET" == meshcop ]; then 104 sudo bash third_party/openthread/repo/script/install_socat 105 install_openthread_binraries 106 sudo apt-get install --no-install-recommends -y avahi-daemon avahi-utils 107 configure_network 108 fi 109 110 if [ "$BUILD_TARGET" == ncp_mode ]; then 111 sudo bash third_party/openthread/repo/script/install_socat 112 sudo apt-get install --no-install-recommends -y avahi-daemon avahi-utils 113 fi 114 115 if [ "$BUILD_TARGET" == scan-build ]; then 116 pip3 install -U cmake 117 sudo apt-get install --no-install-recommends -y clang clang-tools 118 fi 119 120 if [ "$BUILD_TARGET" == pretty-check ]; then 121 sudo apt-get install -y clang-format-14 shellcheck 122 sudo snap install shfmt 123 fi 124 125 if [ "${OTBR_MDNS-}" == 'mDNSResponder' ]; then 126 SOURCE_NAME=mDNSResponder-1790.80.10 127 wget https://github.com/apple-oss-distributions/mDNSResponder/archive/refs/tags/$SOURCE_NAME.tar.gz \ 128 && mkdir -p $SOURCE_NAME \ 129 && tar xvf $SOURCE_NAME.tar.gz -C $SOURCE_NAME --strip-components=1 \ 130 && cd "$SOURCE_NAME" \ 131 && ( 132 for patch in "$MDNSRESPONDER_PATCH_PATH"/*.patch; do 133 patch -p1 <"$patch" 134 done 135 ) \ 136 && cd mDNSPosix \ 137 && make os=linux tls=no && sudo make install os=linux tls=no 138 fi 139 140 # Enable IPv6 141 if [ "$BUILD_TARGET" == check ]; then 142 echo 0 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6 143 fi 144 145 # Allow access syslog file for unit test 146 if [ "$BUILD_TARGET" == check ]; then 147 sudo chmod a+r /var/log/syslog 148 fi 149 150 # Prepare Raspbian image 151 if [ "$BUILD_TARGET" == raspbian-gcc ]; then 152 sudo apt-get install --no-install-recommends --allow-unauthenticated -y qemu qemu-user-static binfmt-support parted 153 154 (mkdir -p docker-rpi-emu \ 155 && cd docker-rpi-emu \ 156 && (git --git-dir=.git rev-parse --is-inside-work-tree || git --git-dir=.git init .) \ 157 && git fetch --depth 1 https://github.com/ryankurte/docker-rpi-emu.git master \ 158 && git checkout FETCH_HEAD) 159 160 pip3 install git-archive-all 161 162 IMAGE_NAME=$(basename "${IMAGE_URL}" .zip) 163 IMAGE_FILE="$IMAGE_NAME".img 164 [ -f "$TOOLS_HOME"/images/"$IMAGE_FILE" ] || { 165 # unit MB 166 EXPAND_SIZE=1024 167 168 [ -d "$TOOLS_HOME"/images ] || mkdir -p "$TOOLS_HOME"/images 169 170 [[ -f "$IMAGE_NAME".zip ]] || curl -LO "$IMAGE_URL" 171 172 unzip "$IMAGE_NAME".zip -d /tmp 173 174 (cd /tmp \ 175 && dd if=/dev/zero bs=1048576 count="$EXPAND_SIZE" >>"$IMAGE_FILE" \ 176 && mv "$IMAGE_FILE" "$TOOLS_HOME"/images/"$IMAGE_FILE") 177 178 (cd docker-rpi-emu/scripts \ 179 && sudo ./expand.sh "$TOOLS_HOME"/images/"$IMAGE_FILE" "$EXPAND_SIZE") 180 } 181 fi 182 ;; 183 184 "Darwin") 185 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 186 ;; 187 188 *) 189 echo "Unknown os type" 190 exit 1 191 ;; 192esac 193