• 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#   Description:
30#       This script resolves all dependencies.
31#
32
33# shellcheck source=script/_initrc
34. "$(dirname "$0")"/_initrc
35
36NAT64_SERVICE="${NAT64_SERVICE:-tayga}"
37
38install_packages_apt()
39{
40    sudo apt-get update
41    sudo apt-get install --no-install-recommends -y \
42        wget \
43        iproute2 \
44        iputils-ping \
45        libreadline-dev \
46        libncurses-dev
47
48    sudo apt-get install --no-install-recommends -y build-essential ninja-build cmake
49
50    with RELEASE || sudo apt-get install --no-install-recommends -y libcpputest-dev
51
52    sudo apt-get install --no-install-recommends -y rsyslog
53
54    # For DBus server
55    sudo apt-get install --no-install-recommends -y libdbus-1-dev
56
57    # mDNS
58    sudo apt-get install --no-install-recommends -y libavahi-client3 libavahi-common-dev libavahi-client-dev avahi-daemon
59    (MDNS_RESPONDER_SOURCE_NAME=mDNSResponder-1310.80.1 \
60        && cd /tmp \
61        && wget -4 --no-check-certificate https://opensource.apple.com/tarballs/mDNSResponder/$MDNS_RESPONDER_SOURCE_NAME.tar.gz \
62        && tar xvf $MDNS_RESPONDER_SOURCE_NAME.tar.gz \
63        && cd /tmp/$MDNS_RESPONDER_SOURCE_NAME/Clients \
64        && sed -i '/#include <ctype.h>/a #include <stdarg.h>' dns-sd.c \
65        && sed -i '/#include <ctype.h>/a #include <sys/param.h>' dns-sd.c \
66        && cd /tmp/$MDNS_RESPONDER_SOURCE_NAME/mDNSPosix \
67        && make os=linux && sudo make install os=linux)
68
69    # Boost
70    sudo apt-get install --no-install-recommends -y libboost-dev libboost-filesystem-dev libboost-system-dev
71
72    # nat64
73    without NAT64 || {
74        "$NAT64_SERVICE" != "tayga" || sudo apt-get install --no-install-recommends -y tayga
75        sudo apt-get install --no-install-recommends -y iptables
76    }
77
78    # dns64
79    without DNS64 || {
80        if [ "$PLATFORM" = "beagleboneblack" ]; then
81            # dnsmasq needs to be stopped before bind9 is installed
82            sudo systemctl disable dnsmasq
83            sudo systemctl stop dnsmasq
84        fi
85        sudo apt-get install --no-install-recommends -y bind9
86        # Resolvconf cannot be installed inside docker environment
87        if without DOCKER; then
88            sudo apt-get install --no-install-recommends -y resolvconf
89        fi
90    }
91
92    # network-manager
93    without NETWORK_MANAGER || sudo apt-get install --no-install-recommends -y dnsmasq network-manager
94
95    # dhcpcd5
96    without DHCPV6_PD || sudo apt-get install --no-install-recommends -y dhcpcd5
97
98    # libjsoncpp
99    sudo apt-get install --no-install-recommends -y libjsoncpp-dev
100
101    # reference device
102    without REFERENCE_DEVICE || sudo apt-get install --no-install-recommends -y radvd dnsutils
103
104    # backbone-router
105    without BACKBONE_ROUTER || sudo apt-get install --no-install-recommends -y libnetfilter-queue1 libnetfilter-queue-dev
106
107    # web dependencies
108    without WEB_GUI || command -v npm || sudo apt-get install --no-install-recommends -y nodejs npm
109
110    # firewall
111    sudo apt-get install -y iptables ipset
112}
113
114install_packages_opkg()
115{
116    die 'opkg not supported currently'
117}
118
119install_packages_rpm()
120{
121    if have dnf; then
122        PM=dnf
123    else
124        PM=yum
125    fi
126    sudo $PM install -y gcc gcc-c++
127    with RELEASE || sudo $PM install -y cmake ninja-build
128    sudo $PM install -y dbus-devel
129    sudo $PM install -y avahi avahi-devel
130    sudo $PM install -y boost-devel boost-filesystem boost-system
131    "$NAT64_SERVICE" != "tayga" || sudo $PM install -y tayga
132    sudo $PM install -y iptables
133    sudo $PM install -y jsoncpp-devel
134    sudo $PM install -y wget
135}
136
137install_packages_brew()
138{
139    brew install boost cmake cpputest dbus jsoncpp ninja
140}
141
142install_packages_source()
143{
144    die 'source not supported currently'
145}
146
147install_packages()
148{
149    if have apt-get; then
150        install_packages_apt
151    elif have rpm; then
152        install_packages_rpm
153    elif have opkg; then
154        install_packages_opkg
155    elif have brew; then
156        install_packages_brew
157    else
158        install_packages_source
159    fi
160}
161
162main()
163{
164    . "$BEFORE_HOOK"
165    # TODO remove `|| true` after docker hub builder gets its git upgraded
166    git submodule update --init --recursive --depth 1 || true
167    install_packages
168    . "$AFTER_HOOK"
169}
170
171main
172