2 # 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)
6 AAF_INTERFACE_VERSION=2.1
8 # Extract Name, Domain and NS from FQI
9 FQIA=($(echo ${APP_FQI} | tr '@' '\n'))
12 # Reverse DOMAIN for NS
13 FQIA_E=($(echo ${FQI_DOMAIN} | tr '.' '\n'))
14 for (( i=( ${#FQIA_E[@]} -1 ); i>0; i-- )); do
15 NS=${NS}${FQIA_E[i]}'.'
18 CONFIG="/opt/app/aaf_config"
19 OSAAF="/opt/app/osaaf"
22 SSO="$DOT_AAF/sso.props"
25 if [ ! -d $LOCAL ]; then
28 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
32 # Setup Bash, first time only
33 if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep aaf_config $HOME/.bash_aliases)" ]; then
34 echo "alias cadi='$OSAAF/bin/agent.sh EMPTY cadi \$*'" >>$HOME/.bash_aliases
35 echo "alias agent='$OSAAF/bin/agent.sh EMPTY \$*'" >>$HOME/.bash_aliases
36 chmod a+x $OSAAF/bin/agent.sh
40 # Setup SSO info for Deploy ID
41 function sso_encrypt() {
42 $JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine digest ${1} $DOT_AAF/keyfile
46 # Create Deployer Info, located at /root/.aaf
47 if [ ! -e "$DOT_AAF/keyfile" ]; then
49 $JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine keygen $DOT_AAF/keyfile
50 chmod 400 $DOT_AAF/keyfile
51 echo cadi_latitude=${LATITUDE} > ${SSO}
52 echo cadi_longitude=${LONGITUDE} >> ${SSO}
53 echo aaf_id=${DEPLOY_FQI} >> ${SSO}
54 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
55 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
57 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
58 echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
60 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
61 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
62 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
65 # Only initialize once, automatically...
66 if [ ! -e $LOCAL/${NS}.props ]; then
68 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config $APP_FQI \
69 aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \
73 # Read Certificate info (by deployer)
74 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar read ${APP_FQI} ${APP_FQDN} \
75 cadi_prop_files=${SSO} \
78 # Place Certificates (by deployer)
79 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar place ${APP_FQI} ${APP_FQDN} \
80 cadi_prop_files=${SSO} \
84 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate \
85 cadi_prop_files=$LOCAL/${NS}.props
90 if [ ! "$CMD" = "" ]; then
96 find /opt/app/osaaf -depth
99 if [ "$1" = "" ]; then
100 echo "usage: cat <file... ONLY files ending in .props>"
102 if [[ $1 == *.props ]]; then
104 echo "## CONTENTS OF $3"
108 echo "### ERROR ####"
109 echo " \"cat\" may only be used with files ending with \".props\""
114 for D in bin logs; do
115 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
119 echo "## Show Passwords"
120 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar showpass ${APP_FQI} ${APP_FQDN}
123 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar check ${APP_FQI} ${APP_FQDN}
126 echo "## validate requested"
127 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate $LOCAL/${NS}.props
130 #if [ ! -e $HOME/bash_aliases ]; then
131 # echo "alias cadi='$JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine \$*'" >$HOME/bash_aliases
132 # echo "alias agent='/bin/bash $CONFIG/bin/agent.sh no-op \$*'" >>$HOME/bash_aliases
140 FILES=$(grep -l "$1" ./*.props)
141 if [ "$FILES" = "" ]; then
146 echo "Changing $1 in $F"
147 if [ "$ADD" = "Y" ]; then
150 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
158 FILES=$(grep -l "$1" ./*.props)
159 if [ "$FILES" = "" ]; then
160 FILES=$LOCAL/${NS}.cred.props
164 echo "Changing $1 in $F"
165 if [ "$2" = "" ]; then
166 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
168 if [ "$ORIG_PW" = "" ]; then
175 PWD=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
176 if [ "$ADD" = "Y" ]; then
177 echo "$1=enc:$PWD" >> $F
179 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
185 sh /opt/app/osaaf/logs/taillog
190 echo "--- Agent Container Comands ---"
191 echo " ls - Lists all files in Configuration"
192 echo " cat <file.props>> - Shows the contents (Prop files only)"
193 echo " validate - Runs a test using Configuration"
194 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
195 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
196 echo " bash - run bash in Container"
197 echo " Note: the following aliases are preset"
198 echo " cadi - CADI CmdLine tool"
199 echo " agent - Agent Java tool (see above help)"
201 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
204 echo "--- cadi Tool Comands ---"
205 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi | tail -n +6
208 echo "--- agent Tool Comands ---"
209 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar
212 echo "--- run Sample Servlet App ---"
213 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar:$CONFIG/bin/aaf-cadi-servlet-sample-*-sample.jar org.onap.aaf.sample.cadi.jetty.JettyStandalone ${NS}.props
218 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"