blob: b810f0c5cc2106180143219bd43c71adfae7ae17 [file] [log] [blame]
Instrumental4ad47632018-07-13 15:49:26 -05001#!/bin/bash
Instrumental9ec28952018-07-12 11:14:10 -05002# This script is run when starting aaf_config Container.
3# It needs to cover the cases where the initial data doesn't exist, and when it has already been configured (don't overwrite)
4#
5JAVA=/usr/bin/java
Instrumentalbc299c02018-09-25 06:42:31 -05006LOCAL=/opt/app/osaaf/local
7DATA=/opt/app/osaaf/data
8PUBLIC=/opt/app/osaaf/public
9CONFIG=/opt/app/aaf_config
Instrumental5451a502018-10-10 18:51:33 -050010
11# If doesn't exist... still create
12mkdir -p /opt/app/osaaf
13
Instrumentalbc299c02018-09-25 06:42:31 -050014# Temp use for clarity of code
15FILE=
Instrumental9ec28952018-07-12 11:14:10 -050016
Instrumental365638c2018-10-01 15:26:03 -050017# Setup Bash, first time only
18if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep aaf_config $HOME/.bash_aliases)" ]; then
19 echo "alias cadi='$CONFIG/bin/agent.sh EMPTY cadi \$*'" >>$HOME/.bash_aliases
20 echo "alias agent='$CONFIG/bin/agent.sh EMPTY \$*'" >>$HOME/.bash_aliases
21 chmod a+x $CONFIG/bin/agent.sh
22 . $HOME/.bash_aliases
23fi
24
Instrumental9ec28952018-07-12 11:14:10 -050025# Only load Identities once
Instrumentalbc299c02018-09-25 06:42:31 -050026# echo "Check Identities"
27FILE="$DATA/identities.dat"
28if [ ! -e $FILE ]; then
29 mkdir -p $DATA
30 cp $CONFIG/data/sample.identities.dat $FILE
31fi
32
33# Load up Cert/X509 Artifacts
34# echo "Check Signer Keyfile"
35FILE="$LOCAL/org.osaaf.aaf.signer.p12"
36if [ ! -e $FILE ]; then
37 mkdir -p $LOCAL
38 mkdir -p $PUBLIC
39 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
40 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
41 else
42 echo "Decode"
43 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
44 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
45 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
46 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
Instrumental365638c2018-10-01 15:26:03 -050047 cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC
48 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumentalbc299c02018-09-25 06:42:31 -050049 echo "cadi_keystore_password=something easy" >> $CONFIG/local/aaf.props
50 fi
51fi
52
53# echo "Check keyfile"
54FILE="$LOCAL/org.osaaf.aaf.p12"
55if [ ! -e $FILE ]; then
56 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
57 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
58 else
59 echo "Bootstrap Creation of Keystore from Signer"
60 cd $CONFIG/CA
61
62 # Remove this after Casablanca
63 CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
64 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
65 cp aaf.bootstrap.p12 $FILE
66 if [ -n "$CADI_X509_ISSUERS" ]; then
67 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
68 fi
69 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
70 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
71
72 I=${BOOT_ISSUER##CN=};I=${I%%,*}
73 CM_CA_PASS="something easy"
74 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 -050075 CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer"
Instrumentalbc299c02018-09-25 06:42:31 -050076 fi
Instrumental9ec28952018-07-12 11:14:10 -050077fi
78
79# Only initialize once, automatically...
Instrumentalbc299c02018-09-25 06:42:31 -050080if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
81 rsync -avzh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -050082 for D in public etc logs; do
Instrumentalbc299c02018-09-25 06:42:31 -050083 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental4ad47632018-07-13 15:49:26 -050084 done
Instrumental9c8a8b02018-07-16 18:41:10 -050085
86 TMP=$(mktemp)
87 echo aaf_env=${AAF_ENV} >> ${TMP}
Instrumental575c9822018-10-19 11:13:05 -050088 echo aaf_release=${VERSION} >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -050089 echo cadi_latitude=${LATITUDE} >> ${TMP}
90 echo cadi_longitude=${LONGITUDE} >> ${TMP}
Instrumentalbc299c02018-09-25 06:42:31 -050091 echo cadi_x509_issuers=${CADI_X509_ISSUERS} >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -050092 echo aaf_register_as=${AAF_REGISTER_AS} >> ${TMP}
Instrumental93871ff2018-10-15 07:37:28 -050093 AAF_LOCATOR_AS=${AAF_LOCATOR_AS:=$AAF_REGISTER_AS}
Instrumental5451a502018-10-10 18:51:33 -050094 echo aaf_locate_url=https://${AAF_LOCATOR_AS}:8095 >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -050095
Instrumentalbc299c02018-09-25 06:42:31 -050096 cat $TMP
97
98 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config aaf@aaf.osaaf.org \
99 cadi_etc_dir=$LOCAL \
100 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -0500101 rm ${TMP}
Instrumental196000b2018-10-05 19:30:59 -0500102
103 # Cassandra Config stuff
104 # Default is expect a Cassandra on same Node
Instrumental93871ff2018-10-15 07:37:28 -0500105 CASS_HOST=${CASS_HOST:="aaf_cass"}
Instrumental196000b2018-10-05 19:30:59 -0500106 CASS_PASS=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile)
107 CASS_NAME=${CASS_HOST/:*/}
Instrumental14f37072018-10-09 08:32:06 -0500108 sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTERS:=$CASS_HOST}/" \
Instrumental196000b2018-10-05 19:30:59 -0500109 -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \
110 -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \
111 -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \
112 $LOCAL/org.osaaf.aaf.cassandra.props
Instrumentalbc299c02018-09-25 06:42:31 -0500113
114 if [ -n "$CM_CA_LOCAL" ]; then
115 if [ -n "$CM_CA_PASS" ]; then
116 CM_CA_LOCAL=$CM_CA_LOCAL$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile)
117 fi
118 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
119 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
120 mv $FILE $FILE.backup
121 grep -v "cm_ca.local=" $FILE.backup > $FILE
122 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
Instrumental365638c2018-10-01 15:26:03 -0500123 echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE
Instrumentalbc299c02018-09-25 06:42:31 -0500124 fi
Instrumental4ad47632018-07-13 15:49:26 -0500125fi
Instrumental9ec28952018-07-12 11:14:10 -0500126
Instrumentalbc299c02018-09-25 06:42:31 -0500127
Instrumental4ad47632018-07-13 15:49:26 -0500128# Now run a command
129CMD=$2
130if [ ! "$CMD" = "" ]; then
131 shift
132 shift
133 case "$CMD" in
134 ls)
135 echo ls requested
136 find /opt/app/osaaf -depth
137 ;;
138 cat)
139 if [ "$1" = "" ]; then
140 echo "usage: cat <file... ONLY files ending in .props>"
141 else
142 if [[ $1 == *.props ]]; then
143 echo
144 echo "## CONTENTS OF $3"
145 echo
146 cat "$1"
147 else
148 echo "### ERROR ####"
149 echo " \"cat\" may only be used with files ending with \".props\""
150 fi
151 fi
152 ;;
153 update)
Instrumentalbc299c02018-09-25 06:42:31 -0500154 rsync -uh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -0500155 for D in public data etc logs; do
Instrumentalbc299c02018-09-25 06:42:31 -0500156 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental4ad47632018-07-13 15:49:26 -0500157 done
158 ;;
159 validate)
160 echo "## validate requested"
Instrumentalbc299c02018-09-25 06:42:31 -0500161 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate cadi_prop_files=$LOCAL/org.osaaf.aaf.props
Instrumental4ad47632018-07-13 15:49:26 -0500162 ;;
Instrumentalbc299c02018-09-25 06:42:31 -0500163 onap)
164 echo Initializing ONAP configurations.
165 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500166 bash)
Instrumental4ad47632018-07-13 15:49:26 -0500167 shift
Instrumentalbc299c02018-09-25 06:42:31 -0500168 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500169 /bin/bash "$@"
170 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500171 setProp)
Instrumentalbc299c02018-09-25 06:42:31 -0500172 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500173 FILES=$(grep -l "$1" ./*.props)
Instrumental9c8a8b02018-07-16 18:41:10 -0500174 if [ "$FILES" = "" ]; then
175 FILES="$3"
176 ADD=Y
177 fi
178 for F in $FILES; do
179 echo "Changing $1 in $F"
180 if [ "$ADD" = "Y" ]; then
Instrumentalaeb80c82018-08-21 10:24:08 -0500181 echo "$1=$2" >> $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500182 else
Instrumentalaeb80c82018-08-21 10:24:08 -0500183 VALUE=${2//\//\\\/}
Instrumental6095e292018-09-06 13:27:15 -0500184 sed -i.backup -e "s/\(${1}=\).*/\1${VALUE}/" $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500185 fi
186 cat $F
187 done
188 ;;
189 encrypt)
Instrumentalbc299c02018-09-25 06:42:31 -0500190 cd $LOCAL || exit
Instrumental9c8a8b02018-07-16 18:41:10 -0500191 echo $1
192 FILES=$(grep -l "$1" ./*.props)
193 if [ "$FILES" = "" ]; then
Instrumentalbc299c02018-09-25 06:42:31 -0500194 FILES=$LOCAL/org.osaaf.aaf.cred.props
Instrumental9c8a8b02018-07-16 18:41:10 -0500195 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500196 fi
197 for F in $FILES; do
198 echo "Changing $1 in $F"
199 if [ "$2" = "" ]; then
200 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
201 echo " "
202 if [ "$ORIG_PW" = "" ]; then
203 echo canceling...
204 break
205 fi
206 else
207 ORIG_PW="$2"
208 fi
Instrumentalbc299c02018-09-25 06:42:31 -0500209 PWD=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile)
Instrumental9c8a8b02018-07-16 18:41:10 -0500210 if [ "$ADD" = "Y" ]; then
211 echo "$1=enc:$PWD" >> $F
212 else
213 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
214 fi
Instrumental4ad47632018-07-13 15:49:26 -0500215 cat $F
216 done
217 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500218 taillog)
219 sh /opt/app/osaaf/logs/taillog
220 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500221 --help | -?)
222 case "$1" in
223 "")
224 echo "--- Agent Container Comands ---"
225 echo " ls - Lists all files in Configuration"
226 echo " cat <file.props>> - Shows the contents (Prop files only)"
227 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500228 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500229 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
230 echo " bash - run bash in Container"
231 echo " Note: the following aliases are preset"
232 echo " cadi - CADI CmdLine tool"
233 echo " agent - Agent Java tool (see above help)"
234 echo ""
235 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
236 ;;
237 cadi)
238 echo "--- cadi Tool Comands ---"
Instrumentalbc299c02018-09-25 06:42:31 -0500239 $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi | tail -n +6
Instrumental4ad47632018-07-13 15:49:26 -0500240 ;;
241 agent)
242 echo "--- agent Tool Comands ---"
Instrumentalbc299c02018-09-25 06:42:31 -0500243 $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar
Instrumental4ad47632018-07-13 15:49:26 -0500244 ;;
245 esac
246 echo ""
247 ;;
248 *)
Instrumentalbc299c02018-09-25 06:42:31 -0500249 $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
Instrumental4ad47632018-07-13 15:49:26 -0500250 ;;
251 esac
252fi