Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # create_configuration_files() - Store credentials in files |
| 4 | function create_configuration_files { |
| 5 | mkdir -p /opt/config |
| 6 | echo $nexus_docker_repo > /opt/config/nexus_docker_repo.txt |
| 7 | echo $nexus_username > /opt/config/nexus_username.txt |
| 8 | echo $nexus_password > /opt/config/nexus_password.txt |
| 9 | echo $openstack_username > /opt/config/openstack_username.txt |
| 10 | echo $openstack_tenant_id > /opt/config/tenant_id.txt |
| 11 | echo $dmaap_topic > /opt/config/dmaap_topic.txt |
| 12 | echo $docker_version > /opt/config/docker_version.txt |
| 13 | } |
| 14 | |
| 15 | # TODO(electrocucaracha): Determine how to use this behind a proxy |
| 16 | # docker_openecomp_login() - Login to OpenECOMP Docker Hub |
| 17 | function docker_openecomp_login { |
| 18 | install_docker |
| 19 | docker login -u $nexus_username -p $nexus_password $nexus_docker_repo |
| 20 | } |
| 21 | |
| 22 | # pull_openecomp_image() - Pull Docker container image from a Docker Registry Hub |
| 23 | function pull_openecomp_image { |
| 24 | local image=$1 |
| 25 | local tag=$2 |
| 26 | docker_openecomp_login |
| 27 | pull_docker_image $nexus_docker_repo/openecomp/${image}:$docker_version $tag |
| 28 | docker logout |
| 29 | } |
| 30 | |
| 31 | # configure_bind()- Configure bind utils |
| 32 | function configure_bind { |
| 33 | _install_bind |
| 34 | mkdir /etc/bind/zones |
| 35 | |
| 36 | curl -k $nexus_repo/org.openecomp.demo/boot/$artifacts_version/db_simpledemo_openecomp_org -o /etc/bind/zones/db.simpledemo.openecomp.org |
| 37 | curl -k $nexus_repo/org.openecomp.demo/boot/$artifacts_version/named.conf.options -o /etc/bind/named.conf.options |
| 38 | curl -k $nexus_repo/org.openecomp.demo/boot/$artifacts_version/named.conf.local -o /etc/bind/named.conf.local |
| 39 | |
| 40 | modprobe ip_gre |
| 41 | sed -i "s/OPTIONS=.*/OPTIONS=\"-4 -u bind\"/g" /etc/default/bind9 |
| 42 | service bind9 restart |
| 43 | } |
| 44 | |
| 45 | # _configure_maven() - This function creates a maven configuration file in case that doesn't exist |
| 46 | function _configure_maven { |
| 47 | local proxies_start=" <!--" |
| 48 | local proxies=" \|" |
| 49 | local proxies_end=" \|-->" |
| 50 | local mvn_http="" |
| 51 | local mvn_https="" |
| 52 | |
| 53 | if [ $http_proxy ] | [ $https_proxy ]; then |
Victor Morales | 2016306 | 2017-08-09 10:50:44 -0500 | [diff] [blame] | 54 | proxies_start=" <proxies>" |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 55 | proxies=" " |
Victor Morales | 2016306 | 2017-08-09 10:50:44 -0500 | [diff] [blame] | 56 | proxies_end=" <\/proxies>" |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 57 | if [ $http_proxy ]; then |
| 58 | proxy_domain=`echo $http_proxy | awk -F/ '{print $3}' | awk -F: '{print $1}'` |
| 59 | proxy_port=`echo $http_proxy | awk -F/ '{print $3}' | awk -F: '{print $2}'` |
| 60 | mvn_http="<proxy>\n <id>http</id>\n <active>true</active>\n <protocol>http</protocol>\n <host>$proxy_domain</host>\n <port>$proxy_port</port>\n <nonProxyHosts>${no_proxy}</nonProxyHosts>\n </proxy>" |
| 61 | fi |
| 62 | if [ $https_proxy ]; then |
| 63 | proxy_domain=`echo $https_proxy | awk -F/ '{print $3}' | awk -F: '{print $1}'` |
| 64 | proxy_port=`echo $https_proxy | awk -F/ '{print $3}' | awk -F: '{print $2}'` |
| 65 | mvn_https="<proxy>\n <id>https</id>\n <active>true</active>\n <protocol>https</protocol>\n <host>$proxy_domain</host>\n <port>$proxy_port</port>\n <nonProxyHosts>${no_proxy}</nonProxyHosts>\n </proxy>" |
| 66 | fi |
| 67 | fi |
| 68 | |
| 69 | if [ ! -f $mvn_conf_file ]; then |
Victor Morales | 2909e2e | 2017-08-08 15:51:52 -0500 | [diff] [blame] | 70 | if [[ "$enable_oparent" == "True" ]]; then |
| 71 | clone_repo oparent |
| 72 | cp $git_src_folder/oparent/settings.xml $mvn_conf_file |
Victor Morales | 2016306 | 2017-08-09 10:50:44 -0500 | [diff] [blame] | 73 | sed -i "s|<\/profiles>|<\/profiles>\n%PROXIES_START%\n%PROXIES% %HTTP_PROXY%\n%PROXIES% %HTTPS_PROXY%\n%PROXIES_END%|g" $mvn_conf_file |
Victor Morales | 2909e2e | 2017-08-08 15:51:52 -0500 | [diff] [blame] | 74 | else |
| 75 | cp /var/onap/files/settings.xml $mvn_conf_file |
| 76 | fi |
| 77 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 78 | sed -e " |
| 79 | s|%PROXIES_START%|$proxies_start|g; |
| 80 | s|%PROXIES%|$proxies|g; |
| 81 | s|%HTTP_PROXY%|$mvn_http|g; |
| 82 | s|%HTTPS_PROXY%|$mvn_https|g; |
| 83 | s|%PROXIES_END%|$proxies_end|g |
| 84 | " -i $mvn_conf_file |
| 85 | fi |
| 86 | } |
| 87 | |
| 88 | # configure_service() - Download and configure a specific service in upstart |
| 89 | function configure_service { |
| 90 | local service_script=$1 |
| 91 | curl -k $nexus_repo/org.openecomp.demo/boot/$artifacts_version/$service_script -o /etc/init.d/$service_script |
| 92 | chmod +x /etc/init.d/$service_script |
| 93 | update-rc.d $service_script defaults |
| 94 | } |