3 source /var/onap/commons
4 source /var/onap/config/env-vars
5 source /var/onap/_composed_functions
6 source /var/onap/_onap_functions
8 export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' |sort -n | head -1)
9 export NIC=$(ip route get 8.8.8.8 | awk '{ print $5; exit }')
10 export IP_ADDRESS=$(ifconfig $NIC | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
12 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 # clone_repos() - Function that clones source repositories for a given project
71 function clone_repos {
73 local repo_name=${2:-$project}
75 for repo in ${repos[$project]}; do
76 clone_repo $repo ${src_folders[$project]}${repo#*$repo_name}
80 # _install_bind() - Install bind utils
81 function _install_bind {
82 install_packages bind9 bind9utils
85 # install_java() - Install java binaries
86 function install_java {
87 if is_package_installed openjdk-8-jdk; then
90 source /etc/os-release || source /usr/lib/os-release
95 install_package software-properties-common
96 add-apt-repository -y ppa:openjdk-r/ppa
104 uninstall_packages default-jre openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless
106 install_package openjdk-8-jdk
107 # ca-certificates-java is not a dependency in the Oracle JDK/JRE so this must be explicitly installed.
108 /var/lib/dpkg/info/ca-certificates-java.postinst configure
111 # install_maven() - Install maven binaries
112 function install_maven {
113 if is_package_installed maven3; then
117 source /etc/os-release || source /usr/lib/os-release
122 install_package software-properties-common
123 add-apt-repository -y ppa:andrei-pozolotin/maven3
129 install_package maven3
132 uninstall_package openjdk-7-jdk
137 # _configure_docker_settings() - Configures Docker settings
138 function _configure_docker_settings {
139 local docker_conf_backup=/tmp/docker.backup
140 local docker_conf=/etc/default/docker
141 local chameleonsocks_filename=chameleonsocks.sh
142 local max_concurrent_downloads=${1:-3}
144 cp ${docker_conf} ${docker_conf_backup}
145 if [ $http_proxy ]; then
146 echo "export http_proxy=$http_proxy" >> $docker_conf
148 if [ $https_proxy ]; then
149 echo "export https_proxy=$https_proxy" >> $docker_conf
150 #If you have a socks proxy, then use that to connect to the nexus repo
151 #via a redsocks container
152 if [ $socks_proxy ]; then
153 wget https://raw.githubusercontent.com/crops/chameleonsocks/master/$chameleonsocks_filename
154 chmod 755 $chameleonsocks_filename
155 socks=$(echo $socks_proxy | sed -e "s/^.*\///" | sed -e "s/:.*$//")
156 port=$(echo $socks_proxy | sed -e "s/^.*://")
157 PROXY=$socks PORT=$port ./$chameleonsocks_filename --install
158 rm $chameleonsocks_filename
159 cp ${docker_conf_backup} ${docker_conf}
162 rm ${docker_conf_backup}
164 echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --max-concurrent-downloads $max_concurrent_downloads \"" >> $docker_conf
165 usermod -aG docker $USER
167 source /etc/os-release || source /usr/lib/os-release
172 service docker restart
180 # install_nodejs() - Download and install NodeJS
181 function install_nodejs {
182 if is_package_installed nodejs; then
185 curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
186 install_package nodejs
188 # Update NPM to latest version
192 # install_python() - Install Python 2.7 and other tools necessary for development.
193 function install_python {
194 install_packages python2.7 python-dev
197 # _install_pip() - Install Python Package Manager
198 function _install_pip {
201 curl -sL https://bootstrap.pypa.io/get-pip.py | python
205 # install_python_package() - Install python modules
206 function install_python_package {
207 local python_packages=$@
210 pip install $python_packages
213 # install_python_requirements() - Install a list of python modules defined in requirement.txt file
214 function install_python_requirements {
215 local python_project_path=$1
218 pushd $python_project_path
219 pip install -r requirements.txt
223 # install_docker() - Download and install docker-engine
224 function install_docker {
225 if $(docker version &>/dev/null); then
228 source /etc/os-release || source /usr/lib/os-release
233 install_packages software-properties-common linux-image-extra-$(uname -r) linux-image-extra-virtual apt-transport-https ca-certificates curl
234 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
236 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
237 $(lsb_release -cs) stable"
244 install_package docker-ce
245 _configure_docker_settings
248 # pull_docker_image() - Pull Docker container image from the Public Docker Registry Hub
249 function pull_docker_image {
255 docker tag ${image} $tag
259 # run_docker_image() - Starts a Docker instance
260 function run_docker_image {
265 # install_docker_compose() - Download and install docker-engine
266 function install_docker_compose {
267 local docker_compose_version=${1:-1.12.0}
268 if [ ! -d /opt/docker ]; then
270 curl -L https://github.com/docker/compose/releases/download/$docker_compose_version/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
271 chmod +x /opt/docker/docker-compose
275 # _install_ODL() - Download and Install OpenDayLight SDN controller
276 function _install_ODL {
277 if [ ! -d /opt/opendaylight/current ]; then
278 mkdir -p /opt/opendaylight/
279 wget "https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/"$odl_version"/distribution-karaf-"$odl_version".tar.gz" -P /opt/
280 tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /tmp/
281 mv "/tmp/distribution-karaf-"$odl_version /opt/opendaylight/current
282 rm -rf "/opt/distribution-karaf-"$odl_version".tar.gz"
286 # start_ODL() - Start OpenDayLight SDN controller
289 if [ -d /opt/opendaylight ]; then
290 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
291 /opt/opendaylight/current/bin/start
293 /opt/opendaylight/current/bin/client feature:install odl-dlux-all
297 # compile_src() - Function that compiles the java source code thru maven
298 function compile_src {
301 local mvn_build='mvn clean install -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dadditionalparam=-Xdoclint:none'
302 if [[ "$debug" == "False" ]]; then
305 if [ -f pom.xml ]; then
307 echo "Compiling $src_folder folder..."
313 # compile_repos() - Function that compiles source repositories for a given project
314 function compile_repos {
317 for repo in ${repos[$project]}; do
318 compile_src ${src_folders[$project]}${repo#*$project}
322 # build_docker_image() - Build Docker container image from source code
323 function build_docker_image {
329 if [ -f pom.xml ]; then
331 # Cleanup external repo
332 sed -i 's|${docker.push.registry}/||g' pom.xml
333 local docker_build="mvn clean package docker:build -DskipTests=true -Dmaven.test.skip=true -Dmaven.javadoc.skip=true"
334 if [ $profile ]; then
335 docker_build+=" -P $profile"
337 if [ $http_proxy ]; then
338 if ! grep -ql "docker.buildArg.http_proxy" pom.xml ; then
339 docker_build+=" -Ddocker.buildArg.http_proxy=$http_proxy"
341 if ! grep -ql "docker.buildArg.HTTP_PROXY" pom.xml ; then
342 docker_build+=" -Ddocker.buildArg.HTTP_PROXY=$http_proxy"
345 if [ $https_proxy ]; then
346 if ! grep -ql "docker.buildArg.https_proxy" pom.xml ; then
347 docker_build+=" -Ddocker.buildArg.https_proxy=$https_proxy"
349 if ! grep -ql "docker.buildArg.HTTPS_PROXY" pom.xml ; then
350 docker_build+=" -Ddocker.buildArg.HTTPS_PROXY=$https_proxy"
353 elif [ -f Dockerfile ]; then
354 # NOTE: Workaround for dmmapbc images
355 sed -i '/LocalKey/d' Dockerfile
356 sed -i "s/nexus3.onap.org\:10003\///g" Dockerfile
357 local docker_build="docker build -t $profile -f ./Dockerfile ."
358 if [ $http_proxy ]; then
359 docker_build+=" --build-arg http_proxy=$http_proxy"
360 docker_build+=" --build-arg HTTP_PROXY=$http_proxy"
362 if [ $https_proxy ]; then
363 docker_build+=" --build-arg https_proxy=$https_proxy"
364 docker_build+=" --build-arg HTTPS_PROXY=$https_proxy"
372 # mount_external_partition() - Create partition and mount the external volume
373 function mount_external_partition {
374 local dev_name="/dev/$1"
377 sfdisk $dev_name << EOF
380 mkfs -t ext4 ${dev_name}1
382 mount ${dev_name}1 $mount_dir
383 echo "${dev_name}1 $mount_dir ext4 errors=remount-ro,noatime,barrier=0 0 1" >> /etc/fstab
386 # add no_proxy values to environment, used for internal IPs generated at deploy time
387 function add_no_proxy_value {
388 if [[ `grep "no_proxy" /etc/environment` ]]; then
389 sed -i.bak "s/^no_proxy.*$/&,$1/" /etc/environment
391 echo "no_proxy=$1" >> /etc/environment
393 if [[ `grep "NO_PROXY" /etc/environment` ]]; then
394 sed -i.bak "s/^NO_PROXY.*$/&,$1/" /etc/environment
396 echo "NO_PROXY=$1" >> /etc/environment