blob: 43ef403fc8541479be3312962e5ede255d9b168a [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
10# Temp use for clarity of code
11FILE=
Instrumental9ec28952018-07-12 11:14:10 -050012
13# Only load Identities once
Instrumentalbc299c02018-09-25 06:42:31 -050014# echo "Check Identities"
15FILE="$DATA/identities.dat"
16if [ ! -e $FILE ]; then
17 mkdir -p $DATA
18 cp $CONFIG/data/sample.identities.dat $FILE
19fi
20
21# Load up Cert/X509 Artifacts
22# echo "Check Signer Keyfile"
23FILE="$LOCAL/org.osaaf.aaf.signer.p12"
24if [ ! -e $FILE ]; then
25 mkdir -p $LOCAL
26 mkdir -p $PUBLIC
27 if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then
28 cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE
29 else
30 echo "Decode"
31 base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE
32 base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12
33 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks
34 ln -s $PUBLIC/truststoreONAPall.jks $LOCAL
35 echo "cadi_keystore_password=something easy" >> $CONFIG/local/aaf.props
36 fi
37fi
38
39# echo "Check keyfile"
40FILE="$LOCAL/org.osaaf.aaf.p12"
41if [ ! -e $FILE ]; then
42 if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then
43 cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE
44 else
45 echo "Bootstrap Creation of Keystore from Signer"
46 cd $CONFIG/CA
47
48 # Remove this after Casablanca
49 CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US"
50 bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy'
51 cp aaf.bootstrap.p12 $FILE
52 if [ -n "$CADI_X509_ISSUERS" ]; then
53 CADI_X509_ISSUERS="$CADI_X509_ISSUERS:"
54 fi
55 BOOT_ISSUER="$(cat aaf.bootstrap.issuer)"
56 CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER"
57
58 I=${BOOT_ISSUER##CN=};I=${I%%,*}
59 CM_CA_PASS="something easy"
60 CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/org.osaaf.aaf.signer.p12;aaf_intermediate_9;enc:"
61 fi
Instrumental9ec28952018-07-12 11:14:10 -050062fi
63
64# Only initialize once, automatically...
Instrumentalbc299c02018-09-25 06:42:31 -050065if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then
66 rsync -avzh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -050067 for D in public etc logs; do
Instrumentalbc299c02018-09-25 06:42:31 -050068 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental4ad47632018-07-13 15:49:26 -050069 done
Instrumental9c8a8b02018-07-16 18:41:10 -050070
71 TMP=$(mktemp)
72 echo aaf_env=${AAF_ENV} >> ${TMP}
73 echo cadi_latitude=${LATITUDE} >> ${TMP}
74 echo cadi_longitude=${LONGITUDE} >> ${TMP}
Instrumentalbc299c02018-09-25 06:42:31 -050075 echo cadi_x509_issuers=${CADI_X509_ISSUERS} >> ${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -050076 echo aaf_register_as=${AAF_REGISTER_AS} >> ${TMP}
77 echo aaf_locate_url=https://${AAF_REGISTER_AS}:8095 >> ${TMP}
78
Instrumentalbc299c02018-09-25 06:42:31 -050079 cat $TMP
80
81 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config aaf@aaf.osaaf.org \
82 cadi_etc_dir=$LOCAL \
83 cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP}
Instrumental9c8a8b02018-07-16 18:41:10 -050084 rm ${TMP}
85 # Default Password for Default Cass
Instrumentalbc299c02018-09-25 06:42:31 -050086 CASS_PASS=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "cassandra" $LOCAL/org.osaaf.aaf.keyfile)
87 sed -i.backup -e "s/\\(cassandra.clusters.password=enc:\\)/\\1$CASS_PASS/" $LOCAL/org.osaaf.aaf.cassandra.props
88
89 if [ -n "$CM_CA_LOCAL" ]; then
90 if [ -n "$CM_CA_PASS" ]; then
91 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)
92 fi
93 # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex
94 FILE=$LOCAL/org.osaaf.aaf.cm.ca.props
95 mv $FILE $FILE.backup
96 grep -v "cm_ca.local=" $FILE.backup > $FILE
97 echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE
98 fi
Instrumental4ad47632018-07-13 15:49:26 -050099fi
Instrumental9ec28952018-07-12 11:14:10 -0500100
Instrumentalbc299c02018-09-25 06:42:31 -0500101
Instrumental4ad47632018-07-13 15:49:26 -0500102# Now run a command
103CMD=$2
104if [ ! "$CMD" = "" ]; then
105 shift
106 shift
107 case "$CMD" in
108 ls)
109 echo ls requested
110 find /opt/app/osaaf -depth
111 ;;
112 cat)
113 if [ "$1" = "" ]; then
114 echo "usage: cat <file... ONLY files ending in .props>"
115 else
116 if [[ $1 == *.props ]]; then
117 echo
118 echo "## CONTENTS OF $3"
119 echo
120 cat "$1"
121 else
122 echo "### ERROR ####"
123 echo " \"cat\" may only be used with files ending with \".props\""
124 fi
125 fi
126 ;;
127 update)
Instrumentalbc299c02018-09-25 06:42:31 -0500128 rsync -uh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL
Instrumental4ad47632018-07-13 15:49:26 -0500129 for D in public data etc logs; do
Instrumentalbc299c02018-09-25 06:42:31 -0500130 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental4ad47632018-07-13 15:49:26 -0500131 done
132 ;;
133 validate)
134 echo "## validate requested"
Instrumentalbc299c02018-09-25 06:42:31 -0500135 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate cadi_prop_files=$LOCAL/org.osaaf.aaf.props
Instrumental4ad47632018-07-13 15:49:26 -0500136 ;;
Instrumentalbc299c02018-09-25 06:42:31 -0500137 onap)
138 echo Initializing ONAP configurations.
139 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500140 bash)
Instrumentalbc299c02018-09-25 06:42:31 -0500141 echo "alias agent='/bin/bash $CONFIG/bin/agent.sh EMPTY \$*'" >>~/.bashrc
Instrumental4ad47632018-07-13 15:49:26 -0500142 if [ ! "$(grep aaf_config ~/.bashrc)" = "" ]; then
Instrumentalbc299c02018-09-25 06:42:31 -0500143 echo "alias cadi='/bin/bash $CONFIG/bin/agent.sh EMPTY cadi \$*'" >>~/.bashrc
144 echo "alias agent='/bin/bash $CONFIG/bin/agent.sh EMPTY \$*'" >>~/.bashrc
Instrumental4ad47632018-07-13 15:49:26 -0500145 #. ~/.bashrc
146 fi
147 shift
Instrumentalbc299c02018-09-25 06:42:31 -0500148 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500149 /bin/bash "$@"
150 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500151 setProp)
Instrumentalbc299c02018-09-25 06:42:31 -0500152 cd $LOCAL || exit
Instrumental4ad47632018-07-13 15:49:26 -0500153 FILES=$(grep -l "$1" ./*.props)
Instrumental9c8a8b02018-07-16 18:41:10 -0500154 if [ "$FILES" = "" ]; then
155 FILES="$3"
156 ADD=Y
157 fi
158 for F in $FILES; do
159 echo "Changing $1 in $F"
160 if [ "$ADD" = "Y" ]; then
Instrumentalaeb80c82018-08-21 10:24:08 -0500161 echo "$1=$2" >> $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500162 else
Instrumentalaeb80c82018-08-21 10:24:08 -0500163 VALUE=${2//\//\\\/}
Instrumental6095e292018-09-06 13:27:15 -0500164 sed -i.backup -e "s/\(${1}=\).*/\1${VALUE}/" $F
Instrumental9c8a8b02018-07-16 18:41:10 -0500165 fi
166 cat $F
167 done
168 ;;
169 encrypt)
Instrumentalbc299c02018-09-25 06:42:31 -0500170 cd $LOCAL || exit
Instrumental9c8a8b02018-07-16 18:41:10 -0500171 echo $1
172 FILES=$(grep -l "$1" ./*.props)
173 if [ "$FILES" = "" ]; then
Instrumentalbc299c02018-09-25 06:42:31 -0500174 FILES=$LOCAL/org.osaaf.aaf.cred.props
Instrumental9c8a8b02018-07-16 18:41:10 -0500175 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500176 fi
177 for F in $FILES; do
178 echo "Changing $1 in $F"
179 if [ "$2" = "" ]; then
180 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
181 echo " "
182 if [ "$ORIG_PW" = "" ]; then
183 echo canceling...
184 break
185 fi
186 else
187 ORIG_PW="$2"
188 fi
Instrumentalbc299c02018-09-25 06:42:31 -0500189 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 -0500190 if [ "$ADD" = "Y" ]; then
191 echo "$1=enc:$PWD" >> $F
192 else
193 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
194 fi
Instrumental4ad47632018-07-13 15:49:26 -0500195 cat $F
196 done
197 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500198 taillog)
199 sh /opt/app/osaaf/logs/taillog
200 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500201 --help | -?)
202 case "$1" in
203 "")
204 echo "--- Agent Container Comands ---"
205 echo " ls - Lists all files in Configuration"
206 echo " cat <file.props>> - Shows the contents (Prop files only)"
207 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500208 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500209 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
210 echo " bash - run bash in Container"
211 echo " Note: the following aliases are preset"
212 echo " cadi - CADI CmdLine tool"
213 echo " agent - Agent Java tool (see above help)"
214 echo ""
215 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
216 ;;
217 cadi)
218 echo "--- cadi Tool Comands ---"
Instrumentalbc299c02018-09-25 06:42:31 -0500219 $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 -0500220 ;;
221 agent)
222 echo "--- agent Tool Comands ---"
Instrumentalbc299c02018-09-25 06:42:31 -0500223 $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar
Instrumental4ad47632018-07-13 15:49:26 -0500224 ;;
225 esac
226 echo ""
227 ;;
228 *)
Instrumentalbc299c02018-09-25 06:42:31 -0500229 $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
Instrumental4ad47632018-07-13 15:49:26 -0500230 ;;
231 esac
232fi