blob: 99ed2793f3c51f126560e3a4b1ccae1a4ddd3b15 [file] [log] [blame]
Instrumental32cdd552018-07-19 13:29:32 -05001#!/bin/bash
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)
4#
5JAVA=/usr/bin/java
6AAF_INTERFACE_VERSION=2.1
7
8# Extract Name, Domain and NS from FQI
9FQIA=($(echo ${APP_FQI} | tr '@' '\n'))
10FQI_SHORT=${FQIA[0]}
11FQI_DOMAIN=${FQIA[1]}
12# Reverse DOMAIN for NS
13FQIA_E=($(echo ${FQI_DOMAIN} | tr '.' '\n'))
14for (( i=( ${#FQIA_E[@]} -1 ); i>0; i-- )); do
15 NS=${NS}${FQIA_E[i]}'.'
16done
17NS=${NS}${FQIA_E[0]}
Instrumental365638c2018-10-01 15:26:03 -050018CONFIG="/opt/app/aaf_config"
Instrumental49525302018-10-06 20:32:59 -050019OSAAF="/opt/app/osaaf"
20LOCAL="$OSAAF/local"
Instrumental365638c2018-10-01 15:26:03 -050021DOT_AAF="$HOME/.aaf"
22SSO="$DOT_AAF/sso.props"
23
Instrumental49525302018-10-06 20:32:59 -050024# Check for local dir
25if [ ! -d $LOCAL ]; then
26 mkdir -p $LOCAL
27 for D in bin logs; do
28 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
29 done
30fi
31
Instrumental365638c2018-10-01 15:26:03 -050032# Setup Bash, first time only
33if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep aaf_config $HOME/.bash_aliases)" ]; then
Instrumental49525302018-10-06 20:32:59 -050034 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
Instrumental365638c2018-10-01 15:26:03 -050037 . $HOME/.bash_aliases
38fi
Instrumental32cdd552018-07-19 13:29:32 -050039
40# Setup SSO info for Deploy ID
41function sso_encrypt() {
Instrumental365638c2018-10-01 15:26:03 -050042 $JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine digest ${1} $DOT_AAF/keyfile
Instrumental32cdd552018-07-19 13:29:32 -050043}
44
Instrumental365638c2018-10-01 15:26:03 -050045
Instrumental49525302018-10-06 20:32:59 -050046# Create Deployer Info, located at /root/.aaf
Instrumental365638c2018-10-01 15:26:03 -050047if [ ! -e "$DOT_AAF/keyfile" ]; then
48 mkdir -p $DOT_AAF
Instrumental365638c2018-10-01 15:26:03 -050049 $JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine keygen $DOT_AAF/keyfile
50 chmod 400 $DOT_AAF/keyfile
Instrumental32cdd552018-07-19 13:29:32 -050051 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}
56 fi
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}
Instrumental365638c2018-10-01 15:26:03 -050059
60 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
61 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
Instrumental32cdd552018-07-19 13:29:32 -050062 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
63fi
64
65# Only initialize once, automatically...
Instrumental365638c2018-10-01 15:26:03 -050066if [ ! -e $LOCAL/${NS}.props ]; then
Instrumental32cdd552018-07-19 13:29:32 -050067 # setup Configs
Instrumental365638c2018-10-01 15:26:03 -050068 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config $APP_FQI \
Instrumental49525302018-10-06 20:32:59 -050069 aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \
70 cadi_etc_dir=$LOCAL
71 cat $LOCAL/$NS.props
Instrumental32cdd552018-07-19 13:29:32 -050072
Instrumental49525302018-10-06 20:32:59 -050073 # 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} \
76 cadi_etc_dir=$LOCAL
77
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} \
81 cadi_etc_dir=$LOCAL
Instrumental32cdd552018-07-19 13:29:32 -050082
83 # Validate
Instrumental365638c2018-10-01 15:26:03 -050084 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate \
85 cadi_prop_files=$LOCAL/${NS}.props
Instrumental32cdd552018-07-19 13:29:32 -050086fi
87
88# Now run a command
89CMD=$2
90if [ ! "$CMD" = "" ]; then
91 shift
92 shift
93 case "$CMD" in
94 ls)
95 echo ls requested
96 find /opt/app/osaaf -depth
97 ;;
98 cat)
99 if [ "$1" = "" ]; then
100 echo "usage: cat <file... ONLY files ending in .props>"
101 else
102 if [[ $1 == *.props ]]; then
103 echo
104 echo "## CONTENTS OF $3"
105 echo
106 cat "$1"
107 else
108 echo "### ERROR ####"
109 echo " \"cat\" may only be used with files ending with \".props\""
110 fi
111 fi
112 ;;
113 update)
114 for D in bin logs; do
Instrumental365638c2018-10-01 15:26:03 -0500115 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental32cdd552018-07-19 13:29:32 -0500116 done
117 ;;
Instrumental87da9fe2018-07-19 16:44:02 -0500118 showpass)
119 echo "## Show Passwords"
Instrumental365638c2018-10-01 15:26:03 -0500120 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar showpass ${APP_FQI} ${APP_FQDN}
Instrumental87da9fe2018-07-19 16:44:02 -0500121 ;;
122 check)
Instrumental365638c2018-10-01 15:26:03 -0500123 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar check ${APP_FQI} ${APP_FQDN}
Instrumental87da9fe2018-07-19 16:44:02 -0500124 ;;
Instrumental32cdd552018-07-19 13:29:32 -0500125 validate)
126 echo "## validate requested"
Instrumental365638c2018-10-01 15:26:03 -0500127 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate $LOCAL/${NS}.props
Instrumental32cdd552018-07-19 13:29:32 -0500128 ;;
129 bash)
Instrumental365638c2018-10-01 15:26:03 -0500130 #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
133 #fi
Instrumental32cdd552018-07-19 13:29:32 -0500134 shift
Instrumental365638c2018-10-01 15:26:03 -0500135 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500136 /bin/bash "$@"
137 ;;
138 setProp)
Instrumental365638c2018-10-01 15:26:03 -0500139 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500140 FILES=$(grep -l "$1" ./*.props)
141 if [ "$FILES" = "" ]; then
142 FILES="$3"
143 ADD=Y
144 fi
145 for F in $FILES; do
146 echo "Changing $1 in $F"
147 if [ "$ADD" = "Y" ]; then
148 echo $2 >> $F
149 else
Instrumental6095e292018-09-06 13:27:15 -0500150 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
Instrumental32cdd552018-07-19 13:29:32 -0500151 fi
152 cat $F
153 done
154 ;;
155 encrypt)
Instrumental365638c2018-10-01 15:26:03 -0500156 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500157 echo $1
158 FILES=$(grep -l "$1" ./*.props)
159 if [ "$FILES" = "" ]; then
Instrumental365638c2018-10-01 15:26:03 -0500160 FILES=$LOCAL/${NS}.cred.props
Instrumental32cdd552018-07-19 13:29:32 -0500161 ADD=Y
162 fi
163 for F in $FILES; do
164 echo "Changing $1 in $F"
165 if [ "$2" = "" ]; then
166 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
167 echo " "
168 if [ "$ORIG_PW" = "" ]; then
169 echo canceling...
170 break
171 fi
172 else
173 ORIG_PW="$2"
174 fi
Instrumental365638c2018-10-01 15:26:03 -0500175 PWD=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
Instrumental32cdd552018-07-19 13:29:32 -0500176 if [ "$ADD" = "Y" ]; then
177 echo "$1=enc:$PWD" >> $F
178 else
179 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
180 fi
181 cat $F
182 done
183 ;;
184 taillog)
185 sh /opt/app/osaaf/logs/taillog
186 ;;
187 --help | -?)
188 case "$1" in
189 "")
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)"
200 echo ""
201 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
202 ;;
203 cadi)
204 echo "--- cadi Tool Comands ---"
Instrumental365638c2018-10-01 15:26:03 -0500205 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi | tail -n +6
Instrumental32cdd552018-07-19 13:29:32 -0500206 ;;
207 agent)
208 echo "--- agent Tool Comands ---"
Instrumental365638c2018-10-01 15:26:03 -0500209 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar
Instrumental32cdd552018-07-19 13:29:32 -0500210 ;;
211 esac
212 echo ""
213 ;;
214 *)
Instrumental365638c2018-10-01 15:26:03 -0500215 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
Instrumental32cdd552018-07-19 13:29:32 -0500216 ;;
217 esac
218fi