blob: 0e3d1ca10dfda695226af92f53bad512f4203805 [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
39 echo "WRITING $DOT_AAF Props ($SSO)"
40 $JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine keygen $DOT_AAF/keyfile
41 chmod 400 $DOT_AAF/keyfile
Instrumental32cdd552018-07-19 13:29:32 -050042 echo cadi_latitude=${LATITUDE} > ${SSO}
43 echo cadi_longitude=${LONGITUDE} >> ${SSO}
44 echo aaf_id=${DEPLOY_FQI} >> ${SSO}
45 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
46 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
47 fi
48 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
49 echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
Instrumental365638c2018-10-01 15:26:03 -050050
51 base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks
52 echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO}
Instrumental32cdd552018-07-19 13:29:32 -050053 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
54fi
55
56# Only initialize once, automatically...
Instrumental365638c2018-10-01 15:26:03 -050057if [ ! -e $LOCAL/${NS}.props ]; then
58 mkdir -p $LOCAL
Instrumental32cdd552018-07-19 13:29:32 -050059 for D in bin logs; do
Instrumental365638c2018-10-01 15:26:03 -050060 rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental32cdd552018-07-19 13:29:32 -050061 done
62
63 # setup Configs
Instrumental365638c2018-10-01 15:26:03 -050064 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config $APP_FQI \
65 cadi_etc_dir=$LOCAL cadi_prop_files=$SSO
Instrumental32cdd552018-07-19 13:29:32 -050066
67 # Place Certificates
Instrumental365638c2018-10-01 15:26:03 -050068 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar place ${APP_FQI} ${APP_FQDN}
Instrumental32cdd552018-07-19 13:29:32 -050069
70 # Validate
Instrumental365638c2018-10-01 15:26:03 -050071 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate \
72 cadi_prop_files=$LOCAL/${NS}.props
Instrumental32cdd552018-07-19 13:29:32 -050073fi
74
75# Now run a command
76CMD=$2
77if [ ! "$CMD" = "" ]; then
78 shift
79 shift
80 case "$CMD" in
81 ls)
82 echo ls requested
83 find /opt/app/osaaf -depth
84 ;;
85 cat)
86 if [ "$1" = "" ]; then
87 echo "usage: cat <file... ONLY files ending in .props>"
88 else
89 if [[ $1 == *.props ]]; then
90 echo
91 echo "## CONTENTS OF $3"
92 echo
93 cat "$1"
94 else
95 echo "### ERROR ####"
96 echo " \"cat\" may only be used with files ending with \".props\""
97 fi
98 fi
99 ;;
100 update)
101 for D in bin logs; do
Instrumental365638c2018-10-01 15:26:03 -0500102 rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D
Instrumental32cdd552018-07-19 13:29:32 -0500103 done
104 ;;
Instrumental87da9fe2018-07-19 16:44:02 -0500105 showpass)
106 echo "## Show Passwords"
Instrumental365638c2018-10-01 15:26:03 -0500107 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar showpass ${APP_FQI} ${APP_FQDN}
Instrumental87da9fe2018-07-19 16:44:02 -0500108 ;;
109 check)
Instrumental365638c2018-10-01 15:26:03 -0500110 $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 -0500111 ;;
Instrumental32cdd552018-07-19 13:29:32 -0500112 validate)
113 echo "## validate requested"
Instrumental365638c2018-10-01 15:26:03 -0500114 $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate $LOCAL/${NS}.props
Instrumental32cdd552018-07-19 13:29:32 -0500115 ;;
116 bash)
Instrumental365638c2018-10-01 15:26:03 -0500117 #if [ ! -e $HOME/bash_aliases ]; then
118 # echo "alias cadi='$JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine \$*'" >$HOME/bash_aliases
119 # echo "alias agent='/bin/bash $CONFIG/bin/agent.sh no-op \$*'" >>$HOME/bash_aliases
120 #fi
Instrumental32cdd552018-07-19 13:29:32 -0500121 shift
Instrumental365638c2018-10-01 15:26:03 -0500122 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500123 /bin/bash "$@"
124 ;;
125 setProp)
Instrumental365638c2018-10-01 15:26:03 -0500126 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500127 FILES=$(grep -l "$1" ./*.props)
128 if [ "$FILES" = "" ]; then
129 FILES="$3"
130 ADD=Y
131 fi
132 for F in $FILES; do
133 echo "Changing $1 in $F"
134 if [ "$ADD" = "Y" ]; then
135 echo $2 >> $F
136 else
Instrumental6095e292018-09-06 13:27:15 -0500137 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
Instrumental32cdd552018-07-19 13:29:32 -0500138 fi
139 cat $F
140 done
141 ;;
142 encrypt)
Instrumental365638c2018-10-01 15:26:03 -0500143 cd $LOCAL || exit
Instrumental32cdd552018-07-19 13:29:32 -0500144 echo $1
145 FILES=$(grep -l "$1" ./*.props)
146 if [ "$FILES" = "" ]; then
Instrumental365638c2018-10-01 15:26:03 -0500147 FILES=$LOCAL/${NS}.cred.props
Instrumental32cdd552018-07-19 13:29:32 -0500148 ADD=Y
149 fi
150 for F in $FILES; do
151 echo "Changing $1 in $F"
152 if [ "$2" = "" ]; then
153 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
154 echo " "
155 if [ "$ORIG_PW" = "" ]; then
156 echo canceling...
157 break
158 fi
159 else
160 ORIG_PW="$2"
161 fi
Instrumental365638c2018-10-01 15:26:03 -0500162 PWD=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" $LOCAL/${NS}.keyfile)
Instrumental32cdd552018-07-19 13:29:32 -0500163 if [ "$ADD" = "Y" ]; then
164 echo "$1=enc:$PWD" >> $F
165 else
166 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
167 fi
168 cat $F
169 done
170 ;;
171 taillog)
172 sh /opt/app/osaaf/logs/taillog
173 ;;
174 --help | -?)
175 case "$1" in
176 "")
177 echo "--- Agent Container Comands ---"
178 echo " ls - Lists all files in Configuration"
179 echo " cat <file.props>> - Shows the contents (Prop files only)"
180 echo " validate - Runs a test using Configuration"
181 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
182 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
183 echo " bash - run bash in Container"
184 echo " Note: the following aliases are preset"
185 echo " cadi - CADI CmdLine tool"
186 echo " agent - Agent Java tool (see above help)"
187 echo ""
188 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
189 ;;
190 cadi)
191 echo "--- cadi Tool Comands ---"
Instrumental365638c2018-10-01 15:26:03 -0500192 $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 -0500193 ;;
194 agent)
195 echo "--- agent Tool Comands ---"
Instrumental365638c2018-10-01 15:26:03 -0500196 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar
Instrumental32cdd552018-07-19 13:29:32 -0500197 ;;
198 esac
199 echo ""
200 ;;
201 *)
Instrumental365638c2018-10-01 15:26:03 -0500202 $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
Instrumental32cdd552018-07-19 13:29:32 -0500203 ;;
204 esac
205fi