1*4a64e381SAndroid Build Coastguard Worker#!/bin/bash 2*4a64e381SAndroid Build Coastguard Worker# 3*4a64e381SAndroid Build Coastguard Worker# Copyright (c) 2018, 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 30*4a64e381SAndroid Build Coastguard Workerset -e 31*4a64e381SAndroid Build Coastguard Workerset -x 32*4a64e381SAndroid Build Coastguard Worker 33*4a64e381SAndroid Build Coastguard WorkerTOOLS_HOME=$HOME/.cache/tools 34*4a64e381SAndroid Build Coastguard Worker 35*4a64e381SAndroid Build Coastguard Workermain() 36*4a64e381SAndroid Build Coastguard Worker{ 37*4a64e381SAndroid Build Coastguard Worker IMAGE_NAME=$(basename "${IMAGE_URL}" .zip) 38*4a64e381SAndroid Build Coastguard Worker STAGE_DIR=/tmp/raspbian 39*4a64e381SAndroid Build Coastguard Worker IMAGE_DIR=/media/rpi 40*4a64e381SAndroid Build Coastguard Worker IMAGE_FILE="$TOOLS_HOME"/images/"$IMAGE_NAME".img 41*4a64e381SAndroid Build Coastguard Worker 42*4a64e381SAndroid Build Coastguard Worker [ -d "$STAGE_DIR" ] || mkdir -p "$STAGE_DIR" 43*4a64e381SAndroid Build Coastguard Worker cp -v "$IMAGE_FILE" "$STAGE_DIR"/raspbian.img 44*4a64e381SAndroid Build Coastguard Worker 45*4a64e381SAndroid Build Coastguard Worker python3 -m git_archive_all "$STAGE_DIR"/repo.tar.gz 46*4a64e381SAndroid Build Coastguard Worker 47*4a64e381SAndroid Build Coastguard Worker cat >"$STAGE_DIR"/check.sh <<EOF 48*4a64e381SAndroid Build Coastguard Workerset -ex 49*4a64e381SAndroid Build Coastguard Worker 50*4a64e381SAndroid Build Coastguard Workerexport LC_ALL=C 51*4a64e381SAndroid Build Coastguard Workerexport DEBIAN_FRONTEND=noninteractive 52*4a64e381SAndroid Build Coastguard Worker 53*4a64e381SAndroid Build Coastguard Workerecho "127.0.0.1 \$(hostname)" >> /etc/hosts 54*4a64e381SAndroid Build Coastguard Workerchown -R pi:pi /home/pi/repo 55*4a64e381SAndroid Build Coastguard Workercd /home/pi/repo 56*4a64e381SAndroid Build Coastguard Workerecho 1 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6 57*4a64e381SAndroid Build Coastguard Workerapt-get update --allow-releaseinfo-change 58*4a64e381SAndroid Build Coastguard Workerapt-get install -y --no-install-recommends git python3-pip 59*4a64e381SAndroid Build Coastguard Workersu -c 'RELEASE=1 script/bootstrap' pi 60*4a64e381SAndroid Build Coastguard Worker 61*4a64e381SAndroid Build Coastguard Worker# Pin CMake version to 3.10.3 for issue https://github.com/openthread/ot-br-posix/issues/728. 62*4a64e381SAndroid Build Coastguard Worker# For more background, see https://gitlab.kitware.com/cmake/cmake/-/issues/20568. 63*4a64e381SAndroid Build Coastguard Workerapt-get purge -y cmake 64*4a64e381SAndroid Build Coastguard Workerpip3 install scikit-build 65*4a64e381SAndroid Build Coastguard Workerpip3 install cmake==3.10.3 66*4a64e381SAndroid Build Coastguard Workercmake --version 67*4a64e381SAndroid Build Coastguard Worker 68*4a64e381SAndroid Build Coastguard Workersu -c 'RELEASE=1 NETWORK_MANAGER=0 script/setup' pi 69*4a64e381SAndroid Build Coastguard WorkerEOF 70*4a64e381SAndroid Build Coastguard Worker 71*4a64e381SAndroid Build Coastguard Worker ( 72*4a64e381SAndroid Build Coastguard Worker cd docker-rpi-emu/scripts \ 73*4a64e381SAndroid Build Coastguard Worker && sudo mkdir -p "$IMAGE_DIR" \ 74*4a64e381SAndroid Build Coastguard Worker && sudo ./mount.sh "$STAGE_DIR"/raspbian.img "$IMAGE_DIR" \ 75*4a64e381SAndroid Build Coastguard Worker && sudo mount --bind /dev/pts "$IMAGE_DIR"/dev/pts \ 76*4a64e381SAndroid Build Coastguard Worker && sudo mkdir -p "$IMAGE_DIR"/home/pi/repo \ 77*4a64e381SAndroid Build Coastguard Worker && sudo tar xzf "$STAGE_DIR"/repo.tar.gz --strip-components 1 -C "$IMAGE_DIR"/home/pi/repo \ 78*4a64e381SAndroid Build Coastguard Worker && sudo cp -v "$STAGE_DIR"/check.sh "$IMAGE_DIR"/home/pi/check.sh \ 79*4a64e381SAndroid Build Coastguard Worker && sudo ./qemu-setup.sh "$IMAGE_DIR" \ 80*4a64e381SAndroid Build Coastguard Worker && sudo chroot "$IMAGE_DIR" /bin/bash /home/pi/check.sh 81*4a64e381SAndroid Build Coastguard Worker sudo umount -lf "$IMAGE_DIR"/dev/pts || true 82*4a64e381SAndroid Build Coastguard Worker sudo ./qemu-cleanup.sh "$IMAGE_DIR" || true 83*4a64e381SAndroid Build Coastguard Worker sudo umount -lf "$IMAGE_DIR"/dev || true 84*4a64e381SAndroid Build Coastguard Worker sudo ./unmount.sh "$IMAGE_DIR" 85*4a64e381SAndroid Build Coastguard Worker ) 86*4a64e381SAndroid Build Coastguard Worker} 87*4a64e381SAndroid Build Coastguard Worker 88*4a64e381SAndroid Build Coastguard Workermain "$@" 89