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