blob: 2b964b1c26df0978ab6bef406cd8e110a5d5dd68 [file] [log] [blame]
Instrumental4ad47632018-07-13 15:49:26 -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#
Instrumental9ec28952018-07-12 11:14:10 -050021# This script is run when starting aaf_config Container.
22# It needs to cover the cases where the initial data doesn't exist, and when it has already been configured (don't overwrite)
23#
24JAVA=/usr/bin/java
Instrumental9fe11532018-10-23 17:40:47 -050025
26OSAAF=/opt/app/osaaf
27LOCAL=$OSAAF/local
28DATA=$OSAAF/data
29PUBLIC=$OSAAF/public
Instrumentalbc299c02018-09-25 06:42:31 -050030CONFIG=/opt/app/aaf_config
Instrumental5451a502018-10-10 18:51:33 -050031
Instrumental9fe11532018-10-23 17:40:47 -050032JAVA_CADI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar org.onap.aaf.cadi.CmdLine"
33JAVA_AGENT="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.cadi.configure.Agent"
34JAVA_AAFCLI="$JAVA -cp $CONFIG/bin/aaf-auth-cmd-*-full.jar -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props org.onap.aaf.auth.cmd.AAFcli"
Instrumentale2fa0e62019-02-07 11:09:32 -060035JAVA_AAFBATCH="$JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.batch.props -jar $CONFIG/bin/aaf-auth-batch-*-full.jar"
Instrumental9fe11532018-10-23 17:40:47 -050036
Instrumental5451a502018-10-10 18:51:33 -050037# If doesn't exist... still create
Instrumental12414fe2019-01-22 10:27:32 -060038mkdir -p $OSAAF
Instrumental5451a502018-10-10 18:51:33 -050039
Instrumental3505a522019-01-31 14:49:24 -060040# If not created by separate PV, create
41mkdir -p /opt/app/aaf/status
42
Instrumentalbc299c02018-09-25 06:42:31 -050043# Temp use for clarity of code
44FILE=
Instrumental9ec28952018-07-12 11:14:10 -050045
Instrumental365638c2018-10-01 15:26:03 -050046# Setup Bash, first time only
Instrumentale2fa0e62019-02-07 11:09:32 -060047if [ ! -e "$HOME/.bashrc" ] || [ -z "$(grep cadi $HOME/.bashrc)" ]; then
48 echo "alias cadi='$JAVA_CADI \$*'" >>$HOME/.bashrc
49 echo "alias agent='$CONFIG/bin/agent.sh \$*'" >>$HOME/.bashrc
50 echo "alias aafcli='$JAVA_AAFCLI \$*'" >>$HOME/.bashrc
51 echo "alias batch='$JAVA_AAFBATCH \$*'" >>$HOME/.bashrc
Instrumental365638c2018-10-01 15:26:03 -050052 chmod a+x $CONFIG/bin/agent.sh
Instrumentale2fa0e62019-02-07 11:09:32 -060053 . $HOME/.bashrc
Instrumental365638c2018-10-01 15:26:03 -050054fi
55
Instrumental9ec28952018-07-12 11:14:10 -050056# Only load Identities once
Instrumentalbc299c02018-09-25 06:42:31 -050057# echo "Check Identities"
58FILE="$DATA/identities.dat"
59if [ ! -e $FILE ]; then
60 mkdir -p $DATA
61 cp $CONFIG/data/sample.identities.dat $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050062 echo "Set Identities"
63 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050064fi
65
66# Load up Cert/X509 Artifacts
67# echo "Check Signer Keyfile"
68FILE="$LOCAL/org.osaaf.aaf.signer.p12"
69if [ ! -e $FILE ]; then
70 mkdir -p $LOCAL
71 mkdir -p $PUBLIC
72 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
73 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050074 echo "Installed Signer P12"
75 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050076 else
77 echo "Decode"
78 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
79 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
80 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
81 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
Instrumental365638c2018-10-01 15:26:03 -050082 cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC
83 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumentalbc299c02018-09-25 06:42:31 -050084 echo "cadi_keystore_password=something easy" >> $CONFIG/local/aaf.props
Instrumental284ad0a2018-10-24 07:01:09 -050085 echo "Setup ONAP Test CAs and Signers"
86 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050087 fi
88fi
89
90# echo "Check keyfile"
91FILE="$LOCAL/org.osaaf.aaf.p12"
92if [ ! -e $FILE ]; then
93 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
94 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
Instrumental284ad0a2018-10-24 07:01:09 -050095 echo "Installed AAF P12"
96 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -050097 else
98 echo "Bootstrap Creation of Keystore from Signer"
99 cd $CONFIG/CA
100
101 # Remove this after Casablanca
102 CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
103 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
104 cp aaf.bootstrap.p12 $FILE
105 if [ -n "$CADI_X509_ISSUERS" ]; then
106 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
107 fi
108 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
109 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
110
111 I=${BOOT_ISSUER##CN=};I=${I%%,*}
112 CM_CA_PASS="something easy"
113 CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/org.osaaf.aaf.signer.p12;aaf_intermediate_9;enc:"
Instrumental365638c2018-10-01 15:26:03 -0500114 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumental284ad0a2018-10-24 07:01:09 -0500115 echo "Generated ONAP Test AAF certs"
116 INITIALIZED="true"
Instrumentalbc299c02018-09-25 06:42:31 -0500117 fi
Instrumental9ec28952018-07-12 11:14:10 -0500118fi
119
120# Only initialize once, automatically...
Instrumentalbc299c02018-09-25 06:42:31 -0500121if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
Instrumental12414fe2019-01-22 10:27:32 -0600122 cp $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -0500123 for D in public etc logs; do
Instrumental12414fe2019-01-22 10:27:32 -0600124 mkdir -p $OSAAF/$D
125 cp $CONFIG/$D/* $OSAAF/$D
Instrumental4ad47632018-07-13 15:49:26 -0500126 done
Instrumental9c8a8b02018-07-16 18:41:10 -0500127
128 TMP=$(mktemp)
129 echo aaf_env=${AAF_ENV} >> ${TMP}
Instrumental575c9822018-10-19 11:13:05 -0500130 echo aaf_release=${VERSION} >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500131 echo cadi_latitude=${LATITUDE} >> ${TMP}
132 echo cadi_longitude=${LONGITUDE} >> ${TMP}
Instrumentalbc299c02018-09-25 06:42:31 -0500133 echo cadi_x509_issuers=${CADI_X509_ISSUERS} >> ${TMP}
Instrumental12414fe2019-01-22 10:27:32 -0600134 AAF_LOCATE_URL=${aaf_locate_url:="https://${HOSTNAME}:8095"}
135 echo aaf_locate_url=${AAF_LOCATE_URL} >> ${TMP}
136 for P in `env`; do
137 if [[ "$P" == aaf_locator* ]]; then
138 echo "$P" >> ${TMP}
Instrumental12414fe2019-01-22 10:27:32 -0600139 fi
140 done
Instrumental9c8a8b02018-07-16 18:41:10 -0500141
Instrumentalbc299c02018-09-25 06:42:31 -0500142 cat $TMP
143
Instrumental9fe11532018-10-23 17:40:47 -0500144 $JAVA_AGENT config \
145 aaf@aaf.osaaf.org \
Instrumentalbc299c02018-09-25 06:42:31 -0500146 cadi_etc_dir=$LOCAL \
147 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500148 rm ${TMP}
Instrumental196000b2018-10-05 19:30:59 -0500149
150 # Cassandra Config stuff
151 # Default is expect a Cassandra on same Node
Instrumental12414fe2019-01-22 10:27:32 -0600152 CASS_HOST=${CASS_HOST:="aaf-cass"}
Instrumental9fe11532018-10-23 17:40:47 -0500153 CASS_PASS=$($JAVA_CADI digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental196000b2018-10-05 19:30:59 -0500154 CASS_NAME=${CASS_HOST/:*/}
Instrumental14f37072018-10-09 08:32:06 -0500155 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTERS:=$CASS_HOST}/" \
Instrumental196000b2018-10-05 19:30:59 -0500156 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
157 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
158 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
159 $LOCAL/org.osaaf.aaf.cassandra.props
Instrumentalbc299c02018-09-25 06:42:31 -0500160
161 if [ -n "$CM_CA_LOCAL" ]; then
162 if [ -n "$CM_CA_PASS" ]; then
Instrumental9fe11532018-10-23 17:40:47 -0500163 CM_CA_LOCAL=$CM_CA_LOCAL$($JAVA_CADI digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
Instrumentalbc299c02018-09-25 06:42:31 -0500164 fi
165 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
166 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
167 mv $FILE $FILE.backup
168 grep -v "cm_ca.local=" $FILE.backup > $FILE
169 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
Instrumental365638c2018-10-01 15:26:03 -0500170 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
Instrumentalbc299c02018-09-25 06:42:31 -0500171 fi
Instrumental284ad0a2018-10-24 07:01:09 -0500172 echo "Created AAF Initial Configurations"
173 INITIALIZED="true"
Instrumental4ad47632018-07-13 15:49:26 -0500174fi
Instrumental9ec28952018-07-12 11:14:10 -0500175
Instrumentalbc299c02018-09-25 06:42:31 -0500176
Instrumental4ad47632018-07-13 15:49:26 -0500177# Now run a command
Instrumental12414fe2019-01-22 10:27:32 -0600178CMD=$1
Instrumental9fe11532018-10-23 17:40:47 -0500179if [ -z "$CMD" ]; then
Instrumental284ad0a2018-10-24 07:01:09 -0500180 if [ -n "$INITIALIZED" ]; then
181 echo "Initialization Complete"
182 else
183 echo "No Additional Initialization required"
184 fi
Instrumental9fe11532018-10-23 17:40:47 -0500185else
Instrumental4ad47632018-07-13 15:49:26 -0500186 shift
Instrumental4ad47632018-07-13 15:49:26 -0500187 case "$CMD" in
188 ls)
189 echo ls requested
Instrumental12414fe2019-01-22 10:27:32 -0600190 find $OSAAF -depth
Instrumental4ad47632018-07-13 15:49:26 -0500191 ;;
192 cat)
193 if [ "$1" = "" ]; then
194 echo "usage: cat <file... ONLY files ending in .props>"
195 else
196 if [[ $1 == *.props ]]; then
197 echo
198 echo "## CONTENTS OF $3"
199 echo
200 cat "$1"
201 else
202 echo "### ERROR ####"
203 echo " \"cat\" may only be used with files ending with \".props\""
204 fi
205 fi
206 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500207 validate)
208 echo "## validate requested"
Instrumental9fe11532018-10-23 17:40:47 -0500209 $JAVA_AAFCLI perm list user aaf@aaf.osaaf.org
Instrumental4ad47632018-07-13 15:49:26 -0500210 ;;
Instrumentalbc299c02018-09-25 06:42:31 -0500211 onap)
Instrumental284ad0a2018-10-24 07:01:09 -0500212 #echo Initializing ONAP configurations.
Instrumentalbc299c02018-09-25 06:42:31 -0500213 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500214 bash)
Instrumental4ad47632018-07-13 15:49:26 -0500215 shift
Instrumentalbc299c02018-09-25 06:42:31 -0500216 cd $LOCAL || exit
Instrumental12414fe2019-01-22 10:27:32 -0600217 exec /bin/bash -c "$@"
Instrumental4ad47632018-07-13 15:49:26 -0500218 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500219 setProp)
Instrumentalbc299c02018-09-25 06:42:31 -0500220 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500221 FILES=$(grep -l "$1" ./*.props)
Instrumental9fe11532018-10-23 17:40:47 -0500222 if [ -z "$FILES" ]; then
223 if [ -z "$3" ]; then
224 FILES=org.osaaf.aaf.props
225 else
226 FILES="$3"
227 fi
Instrumental9c8a8b02018-07-16 18:41:10 -0500228 ADD=Y
229 fi
230 for F in $FILES; do
Instrumental9c8a8b02018-07-16 18:41:10 -0500231 if [ "$ADD" = "Y" ]; then
Instrumental12414fe2019-01-22 10:27:32 -0600232 echo "Changing $1 for $F"
Instrumentalaeb80c82018-08-21 10:24:08 -0500233 echo "$1=$2" >> $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500234 else
Instrumental9fe11532018-10-23 17:40:47 -0500235 echo "Changing $1 in $F"
Instrumental12414fe2019-01-22 10:27:32 -0600236 sed -i.backup -e "s/\\(${1}=\\).*/\\1${2}/" $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500237 fi
238 cat $F
239 done
240 ;;
241 encrypt)
Instrumentalbc299c02018-09-25 06:42:31 -0500242 cd $LOCAL || exit
Instrumental9c8a8b02018-07-16 18:41:10 -0500243 echo $1
244 FILES=$(grep -l "$1" ./*.props)
245 if [ "$FILES" = "" ]; then
Instrumentalbc299c02018-09-25 06:42:31 -0500246 FILES=$LOCAL/org.osaaf.aaf.cred.props
Instrumental9c8a8b02018-07-16 18:41:10 -0500247 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500248 fi
249 for F in $FILES; do
250 echo "Changing $1 in $F"
251 if [ "$2" = "" ]; then
252 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
253 echo " "
254 if [ "$ORIG_PW" = "" ]; then
255 echo canceling...
256 break
257 fi
258 else
259 ORIG_PW="$2"
260 fi
Instrumental9fe11532018-10-23 17:40:47 -0500261 PWD=$($JAVA_CADI digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental9c8a8b02018-07-16 18:41:10 -0500262 if [ "$ADD" = "Y" ]; then
263 echo "$1=enc:$PWD" >> $F
264 else
265 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
266 fi
Instrumental4ad47632018-07-13 15:49:26 -0500267 cat $F
268 done
269 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500270 taillog)
Instrumental12414fe2019-01-22 10:27:32 -0600271 sh $OSAAF/logs/taillog
Instrumental9c8a8b02018-07-16 18:41:10 -0500272 ;;
Instrumentalca788dc2018-11-03 14:38:21 -0500273 wait)
274 bash $CONFIG/bin/pod_wait.sh wait $1
275 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500276 --help | -?)
277 case "$1" in
278 "")
279 echo "--- Agent Container Comands ---"
280 echo " ls - Lists all files in Configuration"
281 echo " cat <file.props>> - Shows the contents (Prop files only)"
282 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500283 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500284 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
285 echo " bash - run bash in Container"
286 echo " Note: the following aliases are preset"
287 echo " cadi - CADI CmdLine tool"
288 echo " agent - Agent Java tool (see above help)"
289 echo ""
290 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
291 ;;
292 cadi)
293 echo "--- cadi Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500294 $JAVA_CADI
Instrumental4ad47632018-07-13 15:49:26 -0500295 ;;
296 agent)
297 echo "--- agent Tool Comands ---"
Instrumental9fe11532018-10-23 17:40:47 -0500298 $JAVA_AGENT
299 ;;
300 aafcli)
301 echo "--- aafcli Tool Comands ---"
302 $JAVA_AAFCLI
Instrumental4ad47632018-07-13 15:49:26 -0500303 ;;
304 esac
305 echo ""
306 ;;
307 *)
Instrumental9fe11532018-10-23 17:40:47 -0500308 $JAVA_AGENT "$CMD" "$@" cadi_prop_files=$LOCAL/org.osaaf.aaf.props
Instrumental4ad47632018-07-13 15:49:26 -0500309 ;;
310 esac
311fi