blob: 2c73614279ee7c125f1a4b945592163fd43d48c2 [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]}
18
19
20# Setup SSO info for Deploy ID
21function sso_encrypt() {
22 $JAVA -cp /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine digest ${1} ~/.aaf/keyfile
23}
24
25if [ ! -e " ~/.aaf/keyfile" ]; then
26 mkdir -p ~/.aaf
27 SSO=~/.aaf/sso.props
28 $JAVA -cp /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine keygen ~/.aaf/keyfile
29 chmod 400 ~/.aaf/keyfile
30 echo cadi_latitude=${LATITUDE} > ${SSO}
31 echo cadi_longitude=${LONGITUDE} >> ${SSO}
32 echo aaf_id=${DEPLOY_FQI} >> ${SSO}
33 if [ ! "${DEPLOY_PASSWORD}" = "" ]; then
34 echo aaf_password=enc:$(sso_encrypt ${DEPLOY_PASSWORD}) >> ${SSO}
35 fi
36 echo aaf_locate_url=https://${AAF_FQDN}:8095 >> ${SSO}
37 echo aaf_url=https://AAF_LOCATE_URL/AAF_NS.service:${AAF_INTERFACE_VERSION} >> ${SSO}
38 echo cadi_truststore=$(ls /opt/app/aaf_config/public/*trust*) >> ${SSO}
39 echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO}
40fi
41
42# Only initialize once, automatically...
43if [ ! -e /opt/app/osaaf/local/${NS}.props ]; then
44 for D in bin logs; do
45 rsync -avzh --exclude=.gitignore /opt/app/aaf_config/$D/* /opt/app/osaaf/$D
46 done
47
48 # setup Configs
49 $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar config $APP_FQI \
50 cadi_etc_dir=/opt/app/osaaf/local
51
52 # Place Certificates
53 $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar place ${APP_FQI} ${APP_FQDN}
54
55 # Validate
56 $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar validate \
57 cadi_prop_files=/opt/app/osaaf/local/${NS}.props
58fi
59
60# Now run a command
61CMD=$2
62if [ ! "$CMD" = "" ]; then
63 shift
64 shift
65 case "$CMD" in
66 ls)
67 echo ls requested
68 find /opt/app/osaaf -depth
69 ;;
70 cat)
71 if [ "$1" = "" ]; then
72 echo "usage: cat <file... ONLY files ending in .props>"
73 else
74 if [[ $1 == *.props ]]; then
75 echo
76 echo "## CONTENTS OF $3"
77 echo
78 cat "$1"
79 else
80 echo "### ERROR ####"
81 echo " \"cat\" may only be used with files ending with \".props\""
82 fi
83 fi
84 ;;
85 update)
86 for D in bin logs; do
87 rsync -uh --exclude=.gitignore /opt/app/aaf_config/$D/* /opt/app/osaaf/$D
88 done
89 ;;
90 validate)
91 echo "## validate requested"
92 $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar validate cadi_prop_files=/opt/app/osaaf/local/${NS}.props
93 ;;
94 bash)
95 if [ ! -e ~/.bash_aliases ]; then
96 echo "alias cadi='$JAVA -cp /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine \$*'" >~/.bash_aliases
97 echo "alias agent='$JAVA -cp /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.configure.Agent \$*'" >>~/.bash_aliases
98 fi
99 shift
100 cd /opt/app/osaaf/local || exit
101 /bin/bash "$@"
102 ;;
103 setProp)
104 cd /opt/app/osaaf/local || exit
105 FILES=$(grep -l "$1" ./*.props)
106 if [ "$FILES" = "" ]; then
107 FILES="$3"
108 ADD=Y
109 fi
110 for F in $FILES; do
111 echo "Changing $1 in $F"
112 if [ "$ADD" = "Y" ]; then
113 echo $2 >> $F
114 else
115 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
116 fi
117 cat $F
118 done
119 ;;
120 encrypt)
121 cd /opt/app/osaaf/local || exit
122 echo $1
123 FILES=$(grep -l "$1" ./*.props)
124 if [ "$FILES" = "" ]; then
125 FILES=/opt/app/osaaf/local/${NS}.cred.props
126 ADD=Y
127 fi
128 for F in $FILES; do
129 echo "Changing $1 in $F"
130 if [ "$2" = "" ]; then
131 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
132 echo " "
133 if [ "$ORIG_PW" = "" ]; then
134 echo canceling...
135 break
136 fi
137 else
138 ORIG_PW="$2"
139 fi
140 PWD=$("$JAVA" -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" /opt/app/osaaf/local/${NS}.keyfile)
141 if [ "$ADD" = "Y" ]; then
142 echo "$1=enc:$PWD" >> $F
143 else
144 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
145 fi
146 cat $F
147 done
148 ;;
149 taillog)
150 sh /opt/app/osaaf/logs/taillog
151 ;;
152 --help | -?)
153 case "$1" in
154 "")
155 echo "--- Agent Container Comands ---"
156 echo " ls - Lists all files in Configuration"
157 echo " cat <file.props>> - Shows the contents (Prop files only)"
158 echo " validate - Runs a test using Configuration"
159 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
160 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
161 echo " bash - run bash in Container"
162 echo " Note: the following aliases are preset"
163 echo " cadi - CADI CmdLine tool"
164 echo " agent - Agent Java tool (see above help)"
165 echo ""
166 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
167 ;;
168 cadi)
169 echo "--- cadi Tool Comands ---"
170 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/${NS}.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar cadi | tail -n +6
171 ;;
172 agent)
173 echo "--- agent Tool Comands ---"
174 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/${NS}.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar
175 ;;
176 esac
177 echo ""
178 ;;
179 *)
180 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/${NS}.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
181 ;;
182 esac
183fi