blob: 7340d30d9abab4cb975f61f2c2fe18f59834d0ab [file] [log] [blame]
Instrumental9ec28952018-07-12 11:14:10 -05001#!/bin/bash
Instrumental7a1817b2018-11-05 11:11:15 -06002#########
3# ============LICENSE_START====================================================
4# org.onap.aaf
5# ===========================================================================
6# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7# ===========================================================================
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19# ============LICENSE_END====================================================
20#
Instrumental21872892018-12-12 17:16:30 -060021
22
Instrumental32cdd552018-07-19 13:29:32 -050023# Fill out "aaf.props" if not filled out already
24if [ ! -e aaf.props ]; then
25 > ./aaf.props
26fi
Instrumental5b373752018-07-23 10:49:55 -050027
28. ./aaf.props
29
Instrumental21872892018-12-12 17:16:30 -060030DOCKER=${DOCKER:=docker}
Instrumental12414fe2019-01-22 10:27:32 -060031CADI_VERSION=${CADI_VERSION:=2.1.10-SNAPSHOT}
Instrumentalca323312018-08-15 04:57:04 -050032
Instrumental2b46f762019-02-20 11:14:41 -060033for V in VERSION DOCKER_REPOSITORY HOSTNAME CONTAINER_NS AAF_FQDN AAF_FQDN_IP DEPLOY_FQI APP_FQDN APP_FQI VOLUME DRIVER LATITUDE LONGITUDE; do
Instrumental32cdd552018-07-19 13:29:32 -050034 if [ "$(grep $V ./aaf.props)" = "" ]; then
35 unset DEF
36 case $V in
Instrumentalca323312018-08-15 04:57:04 -050037 DOCKER_REPOSITORY)
Instrumental21872892018-12-12 17:16:30 -060038 PROMPT="Docker Repo"
Instrumental7f1e2c02019-02-18 10:06:21 -060039 DEF="nexus3.onap.org:10003"
Instrumental21872892018-12-12 17:16:30 -060040 ;;
Instrumental12414fe2019-01-22 10:27:32 -060041 HOSTNAME)
42 PROMPT="HOSTNAME (blank for Default)"
43 DEF=""
44 ;;
Instrumental21872892018-12-12 17:16:30 -060045 AAF_FQDN) PROMPT="AAF's FQDN";;
46 DEPLOY_FQI) PROMPT="Deployer's FQI";;
Instrumental5b373752018-07-23 10:49:55 -050047 AAF_FQDN_IP)
Instrumental21872892018-12-12 17:16:30 -060048 # Need AAF_FQDN's IP, because not might not be available in mini-container
49 PROMPT="AAF FQDN IP"
Instrumental7f1e2c02019-02-18 10:06:21 -060050 LOOKUP=$(host "${AAF_FQDN}" | grep "has address")
Instrumentalbf3d3072019-02-18 14:01:07 -060051 if [ -n "${LOOKUP}" ]; then
Instrumental7f1e2c02019-02-18 10:06:21 -060052 DEF=$(echo ${LOOKUP} | tail -1 | cut -f 4 -d ' ')
53 fi
Instrumental21872892018-12-12 17:16:30 -060054 ;;
Instrumentalbf3d3072019-02-18 14:01:07 -060055 APP_FQDN) PROMPT="App's Root FQDN";;
56 APP_FQI) PROMPT="App's FQI"
57 if [[ "${APP_FQDN}" != *"."* ]]; then
58 DEF="${APP_FQDN}@${APP_FQDN}.onap.org"
59 fi
60 ;;
61 VOLUME) PROMPT="APP's AAF Configuration Volume"
62 if [[ "${APP_FQDN}" != *"."* ]]; then
63 DEF="${APP_FQDN}_config"
64 fi
65 ;;
Instrumental32cdd552018-07-19 13:29:32 -050066 DRIVER) PROMPT=$V;DEF=local;;
Instrumental2b46f762019-02-20 11:14:41 -060067 CONTAINER_NS)
68 PROMPT=$V;DEF=onap;;
Instrumental21872892018-12-12 17:16:30 -060069 VERSION) PROMPT="CADI Version";DEF=$CADI_VERSION;;
Instrumental32cdd552018-07-19 13:29:32 -050070 LATITUDE|LONGITUDE) PROMPT="$V of Node";;
71 *) PROMPT=$V;;
72 esac
73 if [ "$DEF" = "" ]; then
74 PROMPT="$PROMPT: "
75 else
76 PROMPT="$PROMPT ($DEF): "
77 fi
78 read -p "$PROMPT" VAR
79 if [ "$VAR" = "" ]; then
80 if [ "$DEF" = "" ]; then
Instrumental12414fe2019-01-22 10:27:32 -060081 if [ "$V" != "HOSTNAME" ]; then
82 echo "agent.sh needs each value queried. Please start again."
83 exit
84 fi
Instrumental32cdd552018-07-19 13:29:32 -050085 else
86 VAR=$DEF
87 fi
88 fi
89 echo "$V=$VAR" >> ./aaf.props
Instrumental7f1e2c02019-02-18 10:06:21 -060090 declare "$V"="$VAR"
Instrumental32cdd552018-07-19 13:29:32 -050091 fi
92done
93. ./aaf.props
94
Instrumental21872892018-12-12 17:16:30 -060095# Make sure Container Volume exists
96if [ "$($DOCKER volume ls | grep ${VOLUME})" = "" ]; then
97 echo -n "Creating Volume: "
98 $DOCKER volume create -d ${DRIVER} ${VOLUME}
99fi
100
Instrumental365638c2018-10-01 15:26:03 -0500101if [ -n "$DOCKER_REPOSITORY" ]; then
102 PREFIX="$DOCKER_REPOSITORY/"
103else
104 PREFIX=""
105fi
106
Instrumental628b7102019-02-15 19:40:04 -0600107function run_it() {
Instrumental628b7102019-02-15 19:40:04 -0600108 if [ -n "${DUSER}" ]; then
109 USER_LINE="--user ${DUSER}"
110 fi
111 $DOCKER run -it --rm \
112 ${USER_LINE} \
Instrumental94053612018-10-08 11:27:18 -0500113 -v "${VOLUME}:/opt/app/osaaf" \
Instrumentalc23f2cd2018-07-20 20:27:49 -0500114 --add-host="$AAF_FQDN:$AAF_FQDN_IP" \
Instrumental32cdd552018-07-19 13:29:32 -0500115 --env AAF_FQDN=${AAF_FQDN} \
116 --env DEPLOY_FQI=${DEPLOY_FQI} \
117 --env DEPLOY_PASSWORD=${DEPLOY_PASSWORD} \
118 --env APP_FQI=${APP_FQI} \
119 --env APP_FQDN=${APP_FQDN} \
Instrumental9c8a8b02018-07-16 18:41:10 -0500120 --env LATITUDE=${LATITUDE} \
121 --env LONGITUDE=${LONGITUDE} \
Instrumental2b46f762019-02-20 11:14:41 -0600122 --env aaf_locator_container_ns=${CONTAINER_NS} \
Instrumental628b7102019-02-15 19:40:04 -0600123 --name aaf-agent-$USER \
Instrumental365638c2018-10-01 15:26:03 -0500124 "$PREFIX"onap/aaf/aaf_agent:$VERSION \
Instrumental628b7102019-02-15 19:40:04 -0600125 bash -c "bash /opt/app/aaf_config/bin/agent.sh $PARAMS"
126}
127
128PARAMS=$@
129case "$1" in
130 bash)
131 PARAMS="&& cd /opt/app/osaaf/local && exec bash"
132 run_it -it --rm
133 ;;
Instrumental7f1e2c02019-02-18 10:06:21 -0600134 taillog)
135 run_it -it --rm
136 ;;
Instrumental628b7102019-02-15 19:40:04 -0600137 *)
138 run_it --rm
139 ;;
140esac
141