Batch work and client
[aaf/authz.git] / auth / docker / agent.sh
1 #!/bin/bash
2 #########
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 #
21
22
23 # Fill out "aaf.props" if not filled out already
24 if [ ! -e aaf.props ]; then
25   > ./aaf.props
26 fi
27  
28 . ./aaf.props
29
30 DOCKER=${DOCKER:=docker}
31 CADI_VERSION=${CADI_VERSION:=2.1.10-SNAPSHOT}
32
33 for V in VERSION DOCKER_REPOSITORY HOSTNAME AAF_FQDN AAF_FQDN_IP DEPLOY_FQI APP_FQDN APP_FQI VOLUME DRIVER LATITUDE LONGITUDE; do
34    if [ "$(grep $V ./aaf.props)" = "" ]; then
35       unset DEF
36       case $V in
37          DOCKER_REPOSITORY) 
38                 PROMPT="Docker Repo"
39                 DEF=""
40                 ;;
41          HOSTNAME) 
42                 PROMPT="HOSTNAME (blank for Default)"
43                 DEF=""
44                 ;;
45          AAF_FQDN)   PROMPT="AAF's FQDN";;
46          DEPLOY_FQI) PROMPT="Deployer's FQI";;
47          AAF_FQDN_IP)
48                 # Need AAF_FQDN's IP, because not might not be available in mini-container
49                 PROMPT="AAF FQDN IP"
50                 DEF=$(host $AAF_FQDN | grep "has address" | tail -1 | cut -f 4 -d ' ')
51                 ;;
52          APP_FQI)    PROMPT="App's FQI";; 
53          APP_FQDN)   PROMPT="App's Root FQDN";; 
54          VOLUME)     PROMPT="APP's AAF Configuration Volume";;
55          DRIVER)     PROMPT=$V;DEF=local;;
56          VERSION)    PROMPT="CADI Version";DEF=$CADI_VERSION;;
57          LATITUDE|LONGITUDE) PROMPT="$V of Node";;
58          *)          PROMPT=$V;;
59       esac
60       if [ "$DEF" = "" ]; then
61            PROMPT="$PROMPT: "
62       else 
63            PROMPT="$PROMPT ($DEF): "
64       fi
65       read -p "$PROMPT" VAR 
66       if [ "$VAR" = "" ]; then
67          if [ "$DEF" = "" ]; then
68             if [ "$V" != "HOSTNAME" ]; then
69               echo "agent.sh needs each value queried.  Please start again."
70               exit
71             fi
72          else
73             VAR=$DEF
74          fi
75       fi
76       echo "$V=$VAR" >> ./aaf.props
77    fi
78 done
79 . ./aaf.props
80
81 # Make sure Container Volume exists
82 if [ "$($DOCKER volume ls | grep ${VOLUME})" = "" ]; then
83   echo -n "Creating Volume: " 
84   $DOCKER volume create -d ${DRIVER} ${VOLUME}
85 fi
86
87 if [ -n "$DOCKER_REPOSITORY" ]; then
88   PREFIX="$DOCKER_REPOSITORY/"
89 else
90   PREFIX=""
91 fi 
92
93 function run_it() {
94   LINKS="--link aaf-locate"
95   if [ -n "${DUSER}" ]; then
96     USER_LINE="--user ${DUSER}"
97   fi
98   $DOCKER run  -it  --rm \
99     ${USER_LINE} \
100     -v "${VOLUME}:/opt/app/osaaf" \
101     --add-host="$AAF_FQDN:$AAF_FQDN_IP" \
102     $LINKS \
103     --env AAF_FQDN=${AAF_FQDN} \
104     --env DEPLOY_FQI=${DEPLOY_FQI} \
105     --env DEPLOY_PASSWORD=${DEPLOY_PASSWORD} \
106     --env APP_FQI=${APP_FQI} \
107     --env APP_FQDN=${APP_FQDN} \
108     --env LATITUDE=${LATITUDE} \
109     --env LONGITUDE=${LONGITUDE} \
110     --name aaf-agent-$USER \
111     "$PREFIX"onap/aaf/aaf_agent:$VERSION \
112     bash -c "bash /opt/app/aaf_config/bin/agent.sh $PARAMS"
113 }
114
115 PARAMS=$@
116 case "$1" in 
117   bash)
118     PARAMS="&& cd /opt/app/osaaf/local && exec bash"
119     run_it -it --rm  
120     ;;
121   *)
122     run_it --rm 
123     ;;
124 esac
125