5 source /var/onap/commons
6 source /var/onap/_composed_functions
7 source /var/onap/_onap_functions
9 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1)
10 export IP_ADDRESS=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
12 mvn_conf_file=/root/.m2/settings.xml
15 # configure_dns() - DNS/GW IP address configuration
16 function configure_dns {
17 echo "nameserver 10.0.0.1" >> /etc/resolvconf/resolv.conf.d/head
21 # _git_timed() - git can sometimes get itself infinitely stuck with transient network
22 # errors or other issues with the remote end. This wraps git in a
23 # timeout/retry loop and is intended to watch over non-local git
24 # processes that might hang.
30 until timeout -s SIGINT ${timeout} git "$@"; do
31 # 124 is timeout(1)'s special return code when it reached the
32 # timeout; otherwise assume fatal failure
33 if [[ $? -ne 124 ]]; then
38 if [ $count -eq 3 ]; then
45 # clone_repo() - Clone Git repository into specific folder
47 local repo_url=https://git.onap.org/
49 local dest_folder=${2:-$git_src_folder/$repo}
50 if [ ! -d $dest_folder ]; then
51 _git_timed clone ${repo_url}${repo} $dest_folder
59 # install_dev_tools() - Install basic dependencies
60 function install_dev_tools {
61 install_packages apt-transport-https ca-certificates curl
64 # _install_bind() - Install bind utils
65 function _install_bind {
66 install_packages bind9 bind9utils
69 # install_java() - Install java binaries
70 function install_java {
71 if is_package_installed openjdk-8-jdk; then
74 install_package software-properties-common
75 add-apt-repository -y ppa:openjdk-r/ppa
78 uninstall_packages default-jre openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless
80 install_package openjdk-8-jdk
81 # ca-certificates-java is not a dependency in the Oracle JDK/JRE so this must be explicitly installed.
82 /var/lib/dpkg/info/ca-certificates-java.postinst configure
85 # install_maven() - Install maven binaries
86 function install_maven {
87 if is_package_installed maven3; then
91 install_package software-properties-common
92 add-apt-repository -y ppa:andrei-pozolotin/maven3
93 install_package maven3
96 uninstall_package openjdk-7-jdk
101 # _configure_docker_settings() - Configures Docker settings
102 function _configure_docker_settings {
103 if [ $http_proxy ]; then
104 echo "export http_proxy=$http_proxy" >> /etc/default/docker
106 if [ $https_proxy ]; then
107 echo "export https_proxy=$https_proxy" >> /etc/default/docker
108 #If you have a socks proxy, then use that to connect to the nexus repo
109 #via a redsocks container
110 if [ $socks_proxy ]; then
111 wget https://raw.githubusercontent.com/crops/chameleonsocks/master/chameleonsocks.sh
112 chmod 755 chameleonsocks.sh
113 socks=$(echo $socks_proxy | sed -e "s/^.*\///" | sed -e "s/:.*$//")
114 port=$(echo $socks_proxy | sed -e "s/^.*://")
115 PROXY=$socks PORT=$port ./chameleonsocks.sh --install
119 echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock\"" >> /etc/default/docker
120 usermod -a -G docker vagrant
123 # install_nodejs() - Download and install NodeJS
124 function install_nodejs {
125 if is_package_installed nodejs; then
128 curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
129 install_package nodejs
131 # Update NPM to latest version
135 # install_python() - Install Python 2.7 and other tools necessary for development.
136 function install_python {
137 install_packages python2.7 python-dev
140 # _install_pip() - Install Python Package Manager
141 function _install_pip {
143 if [ ! -f /usr/local/bin/pip ]; then
144 curl -sL https://bootstrap.pypa.io/get-pip.py | python
148 # install_python_package() - Install a python module
149 function install_python_package {
150 local python_package=$1
153 pip install $python_package
156 # install_docker() - Download and install docker-engine
157 function install_docker {
158 if is_package_installed docker-ce; then
161 install_package software-properties-common
162 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
164 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
167 install_package docker-ce
168 _configure_docker_settings
169 service docker restart
173 # pull_docker_image() - Pull Docker container image from the Public Docker Registry Hub
174 function pull_docker_image {
180 docker tag ${image} $tag
184 # install_docker_compose() - Download and install docker-engine
185 function install_docker_compose {
186 local docker_compose_version=${1:-1.12.0}
187 if [ ! -d /opt/docker ]; then
189 curl -L https://github.com/docker/compose/releases/download/$docker_compose_version/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
190 chmod +x /opt/docker/docker-compose
194 # _install_ODL() - Download and Install OpenDayLight SDN controller
195 function _install_ODL {
196 if [ ! -d /opt/opendaylight/current ]; then
197 mkdir -p /opt/opendaylight/
198 wget "https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/"$odl_version"/distribution-karaf-"$odl_version".tar.gz" -P /opt/
199 tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /opt/
200 mv "/opt/distribution-karaf-"$odl_version /opt/opendaylight/current
201 rm -rf "/opt/distribution-karaf-"$odl_version".tar.gz"
205 # start_ODL() - Start OpenDayLight SDN controller
208 if [ -d /opt/opendaylight ]; then
209 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
210 /opt/opendaylight/current/bin/start
212 /opt/opendaylight/current/bin/client feature:install odl-dlux-all
216 # compile_src() - Function that compiles the java source code thru maven
217 function compile_src {
220 if [ -f pom.xml ]; then
222 mvn clean install -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dadditionalparam=-Xdoclint:none
227 # build_docker_image() - Build Docker container image from source code
228 function build_docker_image {
235 # Cleanup external repo
236 sed -i 's|${docker.push.registry}/||g' pom.xml
237 local mvn_docker="mvn clean package docker:build"
238 if [ $profile ]; then
239 mvn_docker+=" -P $profile"
241 if [ $http_proxy ]; then
242 if ! grep -ql "docker.buildArg.http_proxy" pom.xml ; then
243 mvn_docker+=" -Ddocker.buildArg.http_proxy=$http_proxy"
245 if ! grep -ql "docker.buildArg.HTTP_PROXY" pom.xml ; then
246 mvn_docker+=" -Ddocker.buildArg.HTTP_PROXY=$http_proxy"
249 if [ $https_proxy ]; then
250 if ! grep -ql "docker.buildArg.https_proxy" pom.xml ; then
251 mvn_docker+=" -Ddocker.buildArg.https_proxy=$https_proxy"
253 if ! grep -ql "docker.buildArg.HTTPS_PROXY" pom.xml ; then
254 mvn_docker+=" -Ddocker.buildArg.HTTPS_PROXY=$https_proxy"