Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Instrumental | 7a1817b | 2018-11-05 11:11:15 -0600 | [diff] [blame] | 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 | # |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 21 | |
| 22 | |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 23 | # Fill out "aaf.props" if not filled out already |
| 24 | if [ ! -e aaf.props ]; then |
| 25 | > ./aaf.props |
| 26 | fi |
Instrumental | 5b37375 | 2018-07-23 10:49:55 -0500 | [diff] [blame] | 27 | |
| 28 | . ./aaf.props |
| 29 | |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 30 | DOCKER=${DOCKER:=docker} |
Instrumental | 4d0a045 | 2019-11-14 12:14:16 -0600 | [diff] [blame] | 31 | VERSION=${VERSION} |
| 32 | CADI_VERSION=${CADI_VERSION:=${VERSION}} |
Instrumental | ca32331 | 2018-08-15 04:57:04 -0500 | [diff] [blame] | 33 | |
Instrumental | 2b46f76 | 2019-02-20 11:14:41 -0600 | [diff] [blame] | 34 | for V in VERSION DOCKER_REPOSITORY HOSTNAME CONTAINER_NS AAF_FQDN AAF_FQDN_IP DEPLOY_FQI APP_FQDN APP_FQI VOLUME DRIVER LATITUDE LONGITUDE; do |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 35 | if [ "$(grep $V ./aaf.props)" = "" ]; then |
| 36 | unset DEF |
| 37 | case $V in |
Instrumental | ca32331 | 2018-08-15 04:57:04 -0500 | [diff] [blame] | 38 | DOCKER_REPOSITORY) |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 39 | PROMPT="Docker Repo" |
Instrumental | 7f1e2c0 | 2019-02-18 10:06:21 -0600 | [diff] [blame] | 40 | DEF="nexus3.onap.org:10003" |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 41 | ;; |
Instrumental | 12414fe | 2019-01-22 10:27:32 -0600 | [diff] [blame] | 42 | HOSTNAME) |
| 43 | PROMPT="HOSTNAME (blank for Default)" |
| 44 | DEF="" |
| 45 | ;; |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 46 | AAF_FQDN) PROMPT="AAF's FQDN";; |
| 47 | DEPLOY_FQI) PROMPT="Deployer's FQI";; |
Instrumental | 5b37375 | 2018-07-23 10:49:55 -0500 | [diff] [blame] | 48 | AAF_FQDN_IP) |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 49 | # Need AAF_FQDN's IP, because not might not be available in mini-container |
| 50 | PROMPT="AAF FQDN IP" |
Instrumental | 7f1e2c0 | 2019-02-18 10:06:21 -0600 | [diff] [blame] | 51 | LOOKUP=$(host "${AAF_FQDN}" | grep "has address") |
Instrumental | bf3d307 | 2019-02-18 14:01:07 -0600 | [diff] [blame] | 52 | if [ -n "${LOOKUP}" ]; then |
Instrumental | 7f1e2c0 | 2019-02-18 10:06:21 -0600 | [diff] [blame] | 53 | DEF=$(echo ${LOOKUP} | tail -1 | cut -f 4 -d ' ') |
| 54 | fi |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 55 | ;; |
Instrumental | bf3d307 | 2019-02-18 14:01:07 -0600 | [diff] [blame] | 56 | APP_FQDN) PROMPT="App's Root FQDN";; |
| 57 | APP_FQI) PROMPT="App's FQI" |
| 58 | if [[ "${APP_FQDN}" != *"."* ]]; then |
| 59 | DEF="${APP_FQDN}@${APP_FQDN}.onap.org" |
| 60 | fi |
| 61 | ;; |
| 62 | VOLUME) PROMPT="APP's AAF Configuration Volume" |
| 63 | if [[ "${APP_FQDN}" != *"."* ]]; then |
| 64 | DEF="${APP_FQDN}_config" |
| 65 | fi |
| 66 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 67 | DRIVER) PROMPT=$V;DEF=local;; |
Instrumental | 2b46f76 | 2019-02-20 11:14:41 -0600 | [diff] [blame] | 68 | CONTAINER_NS) |
| 69 | PROMPT=$V;DEF=onap;; |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 70 | VERSION) PROMPT="CADI Version";DEF=$CADI_VERSION;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 71 | LATITUDE|LONGITUDE) PROMPT="$V of Node";; |
| 72 | *) PROMPT=$V;; |
| 73 | esac |
| 74 | if [ "$DEF" = "" ]; then |
| 75 | PROMPT="$PROMPT: " |
| 76 | else |
| 77 | PROMPT="$PROMPT ($DEF): " |
| 78 | fi |
| 79 | read -p "$PROMPT" VAR |
| 80 | if [ "$VAR" = "" ]; then |
| 81 | if [ "$DEF" = "" ]; then |
Instrumental | 12414fe | 2019-01-22 10:27:32 -0600 | [diff] [blame] | 82 | if [ "$V" != "HOSTNAME" ]; then |
| 83 | echo "agent.sh needs each value queried. Please start again." |
| 84 | exit |
| 85 | fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 86 | else |
| 87 | VAR=$DEF |
| 88 | fi |
| 89 | fi |
| 90 | echo "$V=$VAR" >> ./aaf.props |
Instrumental | 7f1e2c0 | 2019-02-18 10:06:21 -0600 | [diff] [blame] | 91 | declare "$V"="$VAR" |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 92 | fi |
| 93 | done |
| 94 | . ./aaf.props |
| 95 | |
Instrumental | 2187289 | 2018-12-12 17:16:30 -0600 | [diff] [blame] | 96 | # Make sure Container Volume exists |
| 97 | if [ "$($DOCKER volume ls | grep ${VOLUME})" = "" ]; then |
| 98 | echo -n "Creating Volume: " |
| 99 | $DOCKER volume create -d ${DRIVER} ${VOLUME} |
| 100 | fi |
| 101 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 102 | if [ -n "$DOCKER_REPOSITORY" ]; then |
| 103 | PREFIX="$DOCKER_REPOSITORY/" |
| 104 | else |
| 105 | PREFIX="" |
| 106 | fi |
| 107 | |
Instrumental | 628b710 | 2019-02-15 19:40:04 -0600 | [diff] [blame] | 108 | function run_it() { |
Instrumental | 628b710 | 2019-02-15 19:40:04 -0600 | [diff] [blame] | 109 | if [ -n "${DUSER}" ]; then |
| 110 | USER_LINE="--user ${DUSER}" |
| 111 | fi |
| 112 | $DOCKER run -it --rm \ |
| 113 | ${USER_LINE} \ |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 114 | -v "${VOLUME}:/opt/app/osaaf" \ |
Instrumental | c23f2cd | 2018-07-20 20:27:49 -0500 | [diff] [blame] | 115 | --add-host="$AAF_FQDN:$AAF_FQDN_IP" \ |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 116 | --env AAF_FQDN=${AAF_FQDN} \ |
| 117 | --env DEPLOY_FQI=${DEPLOY_FQI} \ |
| 118 | --env DEPLOY_PASSWORD=${DEPLOY_PASSWORD} \ |
| 119 | --env APP_FQI=${APP_FQI} \ |
| 120 | --env APP_FQDN=${APP_FQDN} \ |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 121 | --env LATITUDE=${LATITUDE} \ |
| 122 | --env LONGITUDE=${LONGITUDE} \ |
Instrumental | 2b46f76 | 2019-02-20 11:14:41 -0600 | [diff] [blame] | 123 | --env aaf_locator_container_ns=${CONTAINER_NS} \ |
Instrumental | be7e0d1 | 2019-04-04 21:42:19 -0500 | [diff] [blame] | 124 | --env aaf_locator_container=docker \ |
Instrumental | b3a6814 | 2019-07-24 14:42:22 -0500 | [diff] [blame] | 125 | --link aaf-service --link aaf-locate --link aaf-oauth --link aaf-cm \ |
Instrumental | 628b710 | 2019-02-15 19:40:04 -0600 | [diff] [blame] | 126 | --name aaf-agent-$USER \ |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 127 | "$PREFIX"onap/aaf/aaf_agent:$VERSION \ |
Instrumental | 628b710 | 2019-02-15 19:40:04 -0600 | [diff] [blame] | 128 | bash -c "bash /opt/app/aaf_config/bin/agent.sh $PARAMS" |
| 129 | } |
| 130 | |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 131 | function sso { |
| 132 | if [ -n "$2" ]; then |
Instrumental | f54a4aa | 2019-02-22 01:18:51 -0600 | [diff] [blame] | 133 | echo "$1=$2" >> $HOME/.aaf/sso.props |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 134 | fi |
| 135 | } |
| 136 | |
| 137 | function reset_sso { |
| 138 | mkdir -p ~/.aaf |
Instrumental | f54a4aa | 2019-02-22 01:18:51 -0600 | [diff] [blame] | 139 | > $HOME/.aaf/sso.props |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 140 | sso aaf_locate_url "https://$AAF_FQDN:8095" |
| 141 | sso cadi_latitude "$LATITUDE" |
| 142 | sso cadi_longitude "$LONGITUDE" |
| 143 | sso cadi_loglevel "DEBUG" |
| 144 | TRUSTSTORE="$(ls truststore*.jks | tail -1)" |
| 145 | if [ -z "$TRUSTSTORE" ]; then |
| 146 | echo "Place a truststore*.jar which has YOUR CA in it here" |
| 147 | exit |
| 148 | fi |
| 149 | sso cadi_truststore "${PWD}/${TRUSTSTORE}" |
| 150 | sso cadi_truststore_password changeit |
| 151 | } |
| 152 | |
Instrumental | 628b710 | 2019-02-15 19:40:04 -0600 | [diff] [blame] | 153 | PARAMS=$@ |
| 154 | case "$1" in |
| 155 | bash) |
| 156 | PARAMS="&& cd /opt/app/osaaf/local && exec bash" |
| 157 | run_it -it --rm |
| 158 | ;; |
Instrumental | 7f1e2c0 | 2019-02-18 10:06:21 -0600 | [diff] [blame] | 159 | taillog) |
| 160 | run_it -it --rm |
| 161 | ;; |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 162 | aafcli) |
| 163 | shift |
| 164 | reset_sso |
Instrumental | aae5c07 | 2019-03-29 15:42:37 -0500 | [diff] [blame] | 165 | if [ -f aaf-cadi-aaf-$VERSION-full.jar ]; then |
| 166 | java -Dcadi_prop_files="$HOME/.aaf/sso.props" -jar aaf-cadi-aaf-$VERSION-full.jar $@ |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 167 | else |
Instrumental | aae5c07 | 2019-03-29 15:42:37 -0500 | [diff] [blame] | 168 | echo "For local use, you need to have 'aaf-cadi-aaf-$VERSION-full.jar' (or newer)" |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 169 | fi |
| 170 | ;; |
| 171 | local) |
| 172 | shift |
| 173 | CMD="$1" |
| 174 | if [ -z "$2" ]; then |
| 175 | CMD="$CMD $APP_FQI $APP_FQDN" |
| 176 | else |
| 177 | if [ "-" = "$2" ]; then |
| 178 | CMD="$CMD $APP_FQI" |
| 179 | else |
| 180 | CMD="$CMD $2" |
| 181 | fi |
| 182 | if [ "-" = "$3" ]; then |
| 183 | CMD="$CMD $APP_FQDN" |
| 184 | else |
| 185 | CMD="$CMD $3" |
| 186 | fi |
| 187 | fi |
| 188 | reset_sso |
| 189 | sso aaf_id "$DEPLOY_FQI" |
| 190 | sso aaf_password "$DEPLOY_PASSWORD" |
Instrumental | aae5c07 | 2019-03-29 15:42:37 -0500 | [diff] [blame] | 191 | if [ -f aaf-cadi-aaf-$VERSION-full.jar ]; then |
| 192 | java -Dcadi_prop_files="$HOME/.aaf/sso.props" -cp aaf-cadi-aaf-$VERSION-full.jar org.onap.aaf.cadi.configure.Agent $CMD |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 193 | else |
Instrumental | aae5c07 | 2019-03-29 15:42:37 -0500 | [diff] [blame] | 194 | echo "For local use, you need to have 'aaf-cadi-aaf-$VERSION-full.jar' (or newer)" |
Instrumental | ce76c7d | 2019-02-21 07:18:51 -0600 | [diff] [blame] | 195 | fi |
| 196 | ;; |
Instrumental | 628b710 | 2019-02-15 19:40:04 -0600 | [diff] [blame] | 197 | *) |
| 198 | run_it --rm |
| 199 | ;; |
| 200 | esac |
| 201 | |