• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
32cd "$(dirname "$0")/.."
33
34die()
35{
36    echo >&2 " *** ERROR:  $*"
37    exit 1
38}
39
40have()
41{
42    # This function checks if a tool is available
43    #
44
45    command -v "$1" >/dev/null 2>/dev/null
46}
47
48have_or_die()
49{
50    # This function verifies a tool is available and dies with proper
51    # information if not available.
52    #
53
54    have "$1" || die "$1 not available!"
55}
56
57with()
58{
59    # This function verifies a flag is on.
60    #
61    # NOTE environment settings takes higher priority than default files.
62    #
63
64    local value
65    value=$(printenv "$1")
66    if [[ -z $value ]]; then
67        if [[ -f examples/platforms/$PLATFORM/default ]]; then
68            # shellcheck source=examples/platforms/raspbian/default
69            value="$(. "examples/platforms/$PLATFORM/default" && eval echo "\${$1-}")"
70        fi
71    fi
72
73    [[ $value == 1 ]]
74}
75
76without()
77{
78    # This function verifies a flag is off.
79    #
80    # NOTE environment settings takes higher priority than default files.
81    #
82
83    ! with "$1"
84}
85
86# Platform information is needed to load hooks and default settings.
87
88if [[ ! ${PLATFORM+x} ]]; then
89    # BeagleBone Black debian distribution does not support "lsb_release"
90    if grep -s "BeagleBone Black" /sys/firmware/devicetree/base/model; then
91        # Note: 'model' is a binary file with no newline
92        PLATFORM=beagleboneblack
93    else
94        case "${OSTYPE}" in
95            darwin*)
96                PLATFORM=macOS
97                ;;
98            *)
99                have_or_die lsb_release
100                PLATFORM=$(lsb_release -i | cut -c17- | tr '[:upper:]' '[:lower:]')
101                ;;
102        esac
103    fi
104fi
105echo "Current platform is $PLATFORM"
106
107# The DHCPV6_PD feature requires IPv6 features in dhcpcd but RIO
108# is not supported within dhcpcd.
109with BORDER_ROUTING && with DHCPV6_PD && die "BORDER_ROUTING and DHCPV6_PD cannot coexist!"
110
111# OTBR cannot receive RS messages when NETWORK_MANAGER is enabled.
112with BORDER_ROUTING && with NETWORK_MANAGER && die "BORDER_ROUTING and NETWORK_MANAGER cannot coexist!"
113
114STAGE_DIR=$PWD/stage
115BUILD_DIR=$PWD/build
116
117[[ -d $STAGE_DIR ]] || mkdir -v -p "$STAGE_DIR"
118[[ -d $BUILD_DIR ]] || mkdir -v -p "$BUILD_DIR"
119
120export PATH=$STAGE_DIR/usr/bin:$STAGE_DIR/usr/sbin:$PATH
121
122TASKNAME=$(basename "$0")
123BEFORE_HOOK=examples/platforms/$PLATFORM/before_$TASKNAME
124AFTER_HOOK=examples/platforms/$PLATFORM/after_$TASKNAME
125if [[ ! -f $BEFORE_HOOK ]]; then
126    BEFORE_HOOK=/dev/null
127fi
128if [[ ! -f $AFTER_HOOK ]]; then
129    AFTER_HOOK=/dev/null
130fi
131