3 source /var/onap/commons
4 source /var/onap/_composed_functions
5 source /var/onap/_onap_functions
7 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1)
8 export NIC=$(ip route get 8.8.8.8 | awk '{ print $5; exit }')
9 export IP_ADDRESS=$(ifconfig $NIC | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
11 mvn_conf_file=/root/.m2/settings.xml
14 # configure_dns() - DNS/GW IP address configuration
15 function configure_dns {
16 echo "nameserver 10.0.0.1" >> /etc/resolvconf/resolv.conf.d/head
20 # get_next_ip() - Function that provides the next ip
21 function get_next_ip {
22 local ip=${1:-$IP_ADDRESS}
23 ip_hex=$(printf '%.2X%.2X%.2X%.2X\n' `echo $ip | sed -e 's/\./ /g'`)
24 next_ip_hex=$(printf %.8X `echo $(( 0x$ip_hex + 1 ))`)
25 echo $(printf '%d.%d.%d.%d\n' `echo $next_ip_hex | sed -r 's/(..)/0x\1 /g'`)
28 # _git_timed() - git can sometimes get itself infinitely stuck with transient network
29 # errors or other issues with the remote end. This wraps git in a
30 # timeout/retry loop and is intended to watch over non-local git
31 # processes that might hang.
37 until timeout -s SIGINT ${timeout} git "$@"; do
38 # 124 is timeout(1)'s special return code when it reached the
39 # timeout; otherwise assume fatal failure
40 if [[ $? -ne 124 ]]; then
45 if [ $count -eq 3 ]; then
52 # clone_repo() - Clone Git repository into specific folder
54 local repo_url=${3:-"https://git.onap.org/"}
56 local dest_folder=${2:-$git_src_folder/$repo}
57 if [ ! -d $dest_folder ]; then
58 if [[ "$debug" == "False" ]]; then
59 _git_timed clone --quiet ${repo_url}${repo} $dest_folder
61 _git_timed clone ${repo_url}${repo} $dest_folder
70 # _install_bind() - Install bind utils
71 function _install_bind {
72 install_packages bind9 bind9utils
75 # install_java() - Install java binaries
76 function install_java {
77 if is_package_installed openjdk-8-jdk; then
80 source /etc/os-release || source /usr/lib/os-release
85 install_package software-properties-common
86 add-apt-repository -y ppa:openjdk-r/ppa
94 uninstall_packages default-jre openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless
96 install_package openjdk-8-jdk
97 # ca-certificates-java is not a dependency in the Oracle JDK/JRE so this must be explicitly installed.
98 /var/lib/dpkg/info/ca-certificates-java.postinst configure
101 # install_maven() - Install maven binaries
102 function install_maven {
103 if is_package_installed maven3; then
107 source /etc/os-release || source /usr/lib/os-release
112 install_package software-properties-common
113 add-apt-repository -y ppa:andrei-pozolotin/maven3
119 install_package maven3
122 uninstall_package openjdk-7-jdk
127 # _configure_docker_settings() - Configures Docker settings
128 function _configure_docker_settings {
129 local docker_conf_backup=/tmp/docker.backup
130 local docker_conf=/etc/default/docker
131 local chameleonsocks_filename=chameleonsocks.sh
133 cp $docker_conf $docker_conf_backup
134 if [ $http_proxy ]; then
135 echo "export http_proxy=$http_proxy" >> $docker_conf
137 if [ $https_proxy ]; then
138 echo "export https_proxy=$https_proxy" >> $docker_conf
139 #If you have a socks proxy, then use that to connect to the nexus repo
140 #via a redsocks container
141 if [ $socks_proxy ]; then
142 wget https://raw.githubusercontent.com/crops/chameleonsocks/master/$chameleonsocks_filename
143 chmod 755 $chameleonsocks_filename
144 socks=$(echo $socks_proxy | sed -e "s/^.*\///" | sed -e "s/:.*$//")
145 port=$(echo $socks_proxy | sed -e "s/^.*://")
146 PROXY=$socks PORT=$port ./$chameleonsocks_filename --install
147 rm $chameleonsocks_filename
148 cp $docker_conf_backup $docker_conf
151 rm $docker_conf_backup
153 echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock\"" >> $docker_conf
156 # install_nodejs() - Download and install NodeJS
157 function install_nodejs {
158 if is_package_installed nodejs; then
161 curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
162 install_package nodejs
164 # Update NPM to latest version
168 # install_python() - Install Python 2.7 and other tools necessary for development.
169 function install_python {
170 install_packages python2.7 python-dev
173 # _install_pip() - Install Python Package Manager
174 function _install_pip {
177 curl -sL https://bootstrap.pypa.io/get-pip.py | python
181 # install_python_package() - Install a python module
182 function install_python_package {
183 local python_packages=$@
186 pip install $python_packages
189 # install_docker() - Download and install docker-engine
190 function install_docker {
191 if is_package_installed docker-ce; then
194 source /etc/os-release || source /usr/lib/os-release
199 install_packages software-properties-common linux-image-extra-$(uname -r) linux-image-extra-virtual apt-transport-https ca-certificates curl
200 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
202 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
203 $(lsb_release -cs) stable"
210 install_package docker-ce
211 _configure_docker_settings
212 service docker restart
216 # pull_docker_image() - Pull Docker container image from the Public Docker Registry Hub
217 function pull_docker_image {
223 docker tag ${image} $tag
227 # install_docker_compose() - Download and install docker-engine
228 function install_docker_compose {
229 local docker_compose_version=${1:-1.12.0}
230 if [ ! -d /opt/docker ]; then
232 curl -L https://github.com/docker/compose/releases/download/$docker_compose_version/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
233 chmod +x /opt/docker/docker-compose
237 # _install_ODL() - Download and Install OpenDayLight SDN controller
238 function _install_ODL {
239 if [ ! -d /opt/opendaylight/current ]; then
240 mkdir -p /opt/opendaylight/
241 wget "https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/"$odl_version"/distribution-karaf-"$odl_version".tar.gz" -P /opt/
242 tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /opt/
243 mv "/opt/distribution-karaf-"$odl_version /opt/opendaylight/current
244 rm -rf "/opt/distribution-karaf-"$odl_version".tar.gz"
248 # start_ODL() - Start OpenDayLight SDN controller
251 if [ -d /opt/opendaylight ]; then
252 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
253 /opt/opendaylight/current/bin/start
255 /opt/opendaylight/current/bin/client feature:install odl-dlux-all
259 # compile_src() - Function that compiles the java source code thru maven
260 function compile_src {
263 local mvn_build='mvn clean install -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dadditionalparam=-Xdoclint:none'
264 if [[ "$debug" == "False" ]]; then
267 if [ -f pom.xml ]; then
269 echo "Compiling $src_folder folder..."
275 # build_docker_image() - Build Docker container image from source code
276 function build_docker_image {
283 # Cleanup external repo
284 sed -i 's|${docker.push.registry}/||g' pom.xml
285 local mvn_docker="mvn clean package docker:build"
286 if [ $profile ]; then
287 mvn_docker+=" -P $profile"
289 if [ $http_proxy ]; then
290 if ! grep -ql "docker.buildArg.http_proxy" pom.xml ; then
291 mvn_docker+=" -Ddocker.buildArg.http_proxy=$http_proxy"
293 if ! grep -ql "docker.buildArg.HTTP_PROXY" pom.xml ; then
294 mvn_docker+=" -Ddocker.buildArg.HTTP_PROXY=$http_proxy"
297 if [ $https_proxy ]; then
298 if ! grep -ql "docker.buildArg.https_proxy" pom.xml ; then
299 mvn_docker+=" -Ddocker.buildArg.https_proxy=$https_proxy"
301 if ! grep -ql "docker.buildArg.HTTPS_PROXY" pom.xml ; then
302 mvn_docker+=" -Ddocker.buildArg.HTTPS_PROXY=$https_proxy"