blob: ded8c409608da8dc3222a69f2bc0ad2ac4e785a5 [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"
19LOCAL="/opt/app/osaaf/local"
20DOT_AAF="$HOME/.aaf"
21SSO="$DOT_AAF/sso.props"
22
23# Setup Bash, first time only
24if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep aaf_config $HOME/.bash_aliases)" ]; then
25 echo "alias cadi='$CONFIG/bin/agent.sh EMPTY cadi \$*'" >>$HOME/.bash_aliases
26 echo "alias agent='$CONFIG/bin/agent.sh EMPTY \$*'" >>$HOME/.bash_aliases
27 chmod a+x $CONFIG/bin/agent.sh
28 . $HOME/.bash_aliases
29fi
Instrumental32cdd552018-07-19 13:29:32 -050030
31# Setup SSO info for Deploy ID
32function sso_encrypt() {
Instrumental365638c2018-10-01 15:26:03 -050033 $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 -050034}
35
Instrumental365638c2018-10-01 15:26:03 -050036
37if [ ! -e "$DOT_AAF/keyfile" ]; then
38 mkdir -p $DOT_AAF
Instrumental365638c2018-10-01 15:26:03 -050039 $JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine keygen $DOT_AAF/keyfile
40 chmod 400 $DOT_AAF/keyfile
Instrumental32cdd552018-07-19 13:29:32 -050041 echo cadi_latitude=${LATITUDE} > ${SSO}
42 echo cadi_longitude=${LONGITUDE} >> ${SSO}
43 echo aaf_id=${DEPLOY_FQI} >> ${SSO}
44 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
45 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
46 fi
47 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
48 echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
Instrumental365638c2018-10-01 15:26:03 -050049
50 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
51 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
Instrumental32cdd552018-07-19 13:29:32 -050052 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
53fi
54
55# Only initialize once, automatically...
Instrumental365638c2018-10-01 15:26:03 -050056if [ ! -e $LOCAL/${NS}.props ]; then
57 mkdir -p $LOCAL
Instrumental32cdd552018-07-19 13:29:32 -050058 for D in bin logs; do
Instrumental365638c2018-10-01 15:26:03 -050059 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental32cdd552018-07-19 13:29:32 -050060 done
61
62 # setup Configs
Instrumental365638c2018-10-01 15:26:03 -050063 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config $APP_FQI \
64 cadi_etc_dir=$LOCAL cadi_prop_files=$SSO
Instrumental32cdd552018-07-19 13:29:32 -050065
66 # Place Certificates
Instrumental365638c2018-10-01 15:26:03 -050067 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar place ${APP_FQI} ${APP_FQDN}
Instrumental32cdd552018-07-19 13:29:32 -050068
69 # Validate
Instrumental365638c2018-10-01 15:26:03 -050070 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate \
71 cadi_prop_files=$LOCAL/${NS}.props
Instrumental32cdd552018-07-19 13:29:32 -050072fi
73
74# Now run a command
75CMD=$2
76if [ ! "$CMD" = "" ]; then
77 shift
78 shift
79 case "$CMD" in
80 ls)
81 echo ls requested
82 find /opt/app/osaaf -depth
83 ;;
84 cat)
85 if [ "$1" = "" ]; then
86 echo "usage: cat <file... ONLY files ending in .props>"
87 else
88 if [[ $1 == *.props ]]; then
89 echo
90 echo "## CONTENTS OF $3"
91 echo
92 cat "$1"
93 else
94 echo "### ERROR ####"
95 echo " \"cat\" may only be used with files ending with \".props\""
96 fi
97 fi
98 ;;
99 update)
100 for D in bin logs; do
Instrumental365638c2018-10-01 15:26:03 -0500101 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental32cdd552018-07-19 13:29:32 -0500102 done
103 ;;
Instrumental87da9fe2018-07-19 16:44:02 -0500104 showpass)
105 echo "## Show Passwords"
Instrumental365638c2018-10-01 15:26:03 -0500106 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar showpass ${APP_FQI} ${APP_FQDN}
Instrumental87da9fe2018-07-19 16:44:02 -0500107 ;;
108 check)
Instrumental365638c2018-10-01 15:26:03 -0500109 $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 -0500110 ;;
Instrumental32cdd552018-07-19 13:29:32 -0500111 validate)
112 echo "## validate requested"
Instrumental365638c2018-10-01 15:26:03 -0500113 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate $LOCAL/${NS}.props
Instrumental32cdd552018-07-19 13:29:32 -0500114 ;;
115 bash)
Instrumental365638c2018-10-01 15:26:03 -0500116 #if [ ! -e $HOME/bash_aliases ]; then
117 # echo "alias cadi='$JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine \$*'" >$HOME/bash_aliases
118 # echo "alias agent='/bin/bash $CONFIG/bin/agent.sh no-op \$*'" >>$HOME/bash_aliases
119 #fi
Instrumental32cdd552018-07-19 13:29:32 -0500120 shift
Instrumental365638c2018-10-01 15:26:03 -0500121 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500122 /bin/bash "$@"
123 ;;
124 setProp)
Instrumental365638c2018-10-01 15:26:03 -0500125 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500126 FILES=$(grep -l "$1" ./*.props)
127 if [ "$FILES" = "" ]; then
128 FILES="$3"
129 ADD=Y
130 fi
131 for F in $FILES; do
132 echo "Changing $1 in $F"
133 if [ "$ADD" = "Y" ]; then
134 echo $2 >> $F
135 else
Instrumental6095e292018-09-06 13:27:15 -0500136 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
Instrumental32cdd552018-07-19 13:29:32 -0500137 fi
138 cat $F
139 done
140 ;;
141 encrypt)
Instrumental365638c2018-10-01 15:26:03 -0500142 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500143 echo $1
144 FILES=$(grep -l "$1" ./*.props)
145 if [ "$FILES" = "" ]; then
Instrumental365638c2018-10-01 15:26:03 -0500146 FILES=$LOCAL/${NS}.cred.props
Instrumental32cdd552018-07-19 13:29:32 -0500147 ADD=Y
148 fi
149 for F in $FILES; do
150 echo "Changing $1 in $F"
151 if [ "$2" = "" ]; then
152 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
153 echo " "
154 if [ "$ORIG_PW" = "" ]; then
155 echo canceling...
156 break
157 fi
158 else
159 ORIG_PW="$2"
160 fi
Instrumental365638c2018-10-01 15:26:03 -0500161 PWD=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
Instrumental32cdd552018-07-19 13:29:32 -0500162 if [ "$ADD" = "Y" ]; then
163 echo "$1=enc:$PWD" >> $F
164 else
165 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
166 fi
167 cat $F
168 done
169 ;;
170 taillog)
171 sh /opt/app/osaaf/logs/taillog
172 ;;
173 --help | -?)
174 case "$1" in
175 "")
176 echo "--- Agent Container Comands ---"
177 echo " ls - Lists all files in Configuration"
178 echo " cat <file.props>> - Shows the contents (Prop files only)"
179 echo " validate - Runs a test using Configuration"
180 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
181 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
182 echo " bash - run bash in Container"
183 echo " Note: the following aliases are preset"
184 echo " cadi - CADI CmdLine tool"
185 echo " agent - Agent Java tool (see above help)"
186 echo ""
187 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
188 ;;
189 cadi)
190 echo "--- cadi Tool Comands ---"
Instrumental365638c2018-10-01 15:26:03 -0500191 $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 -0500192 ;;
193 agent)
194 echo "--- agent Tool Comands ---"
Instrumental365638c2018-10-01 15:26:03 -0500195 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar
Instrumental32cdd552018-07-19 13:29:32 -0500196 ;;
197 esac
198 echo ""
199 ;;
200 *)
Instrumental365638c2018-10-01 15:26:03 -0500201 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
Instrumental32cdd552018-07-19 13:29:32 -0500202 ;;
203 esac
204fi