Merge "JUnits for Mapper_2_0"
[aaf/authz.git] / auth / docker / agent.sh
1 #!/bin/bash
2
3 CADI_VERSION=2.1.2-SNAPSHOT
4
5 # Fill out "aaf.props" if not filled out already
6 if [ ! -e aaf.props ]; then
7   > ./aaf.props
8 fi
9  
10 . ./aaf.props
11
12
13 for V in VERSION DOCKER_REPOSITORY AAF_FQDN AAF_FQDN_IP DEPLOY_FQI APP_FQDN APP_FQI VOLUME DRIVER LATITUDE LONGITUDE; do
14    if [ "$(grep $V ./aaf.props)" = "" ]; then
15       unset DEF
16       case $V in
17          DOCKER_REPOSITORY) 
18                 PROMPT="Docker Repo"
19                 DEF=""
20                 ;;
21          AAF_FQDN)   PROMPT="AAF's FQDN";;
22          DEPLOY_FQI) PROMPT="Deployer's FQI";;
23          AAF_FQDN_IP)
24                 # Need AAF_FQDN's IP, because not might not be available in mini-container
25                 PROMPT="AAF FQDN IP"
26                 DEF=$(host $AAF_FQDN | grep "has address" | tail -1 | cut -f 4 -d ' ')
27                 ;;
28          APP_FQI)    PROMPT="App's FQI";; 
29          APP_FQDN)   PROMPT="App's Root FQDN";; 
30          VOLUME)     PROMPT="APP's AAF Configuration Volume";;
31          DRIVER)     PROMPT=$V;DEF=local;;
32          VERSION)    PROMPT="CADI Version";DEF=$CADI_VERSION;;
33          LATITUDE|LONGITUDE) PROMPT="$V of Node";;
34          *)          PROMPT=$V;;
35       esac
36       if [ "$DEF" = "" ]; then
37            PROMPT="$PROMPT: "
38       else 
39            PROMPT="$PROMPT ($DEF): "
40       fi
41       read -p "$PROMPT" VAR 
42       if [ "$VAR" = "" ]; then
43          if [ "$DEF" = "" ]; then
44             echo "agent.sh needs each value queried.  Please start again."
45             exit
46          else
47             VAR=$DEF
48          fi
49       fi
50       echo "$V=$VAR" >> ./aaf.props
51    fi
52 done
53 . ./aaf.props
54
55 # Make sure Container Volume exists
56 if [ "$(docker volume ls | grep ${VOLUME})" = "" ]; then
57   echo -n "Creating Volume: " 
58   docker volume create -d ${DRIVER} ${VOLUME}
59 fi
60
61 if [ -n "$DOCKER_REPOSITORY" ]; then
62   PREFIX="$DOCKER_REPOSITORY/"
63 else
64   PREFIX=""
65 fi 
66
67 docker run \
68     -it \
69     --rm \
70     --mount 'type=volume,src='${VOLUME}',dst=/opt/app/osaaf,volume-driver='${DRIVER} \
71     --add-host="$AAF_FQDN:$AAF_FQDN_IP" \
72     --env AAF_FQDN=${AAF_FQDN} \
73     --env DEPLOY_FQI=${DEPLOY_FQI} \
74     --env DEPLOY_PASSWORD=${DEPLOY_PASSWORD} \
75     --env APP_FQI=${APP_FQI} \
76     --env APP_FQDN=${APP_FQDN} \
77     --env LATITUDE=${LATITUDE} \
78     --env LONGITUDE=${LONGITUDE} \
79     --name aaf_agent_$USER \
80     "$PREFIX"onap/aaf/aaf_agent:$VERSION \
81     /bin/bash "$@"