Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 1 | #!/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 | # |
| 5 | JAVA=/usr/bin/java |
| 6 | AAF_INTERFACE_VERSION=2.1 |
| 7 | |
| 8 | # Extract Name, Domain and NS from FQI |
| 9 | FQIA=($(echo ${APP_FQI} | tr '@' '\n')) |
| 10 | FQI_SHORT=${FQIA[0]} |
| 11 | FQI_DOMAIN=${FQIA[1]} |
| 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]}'.' |
| 16 | done |
| 17 | NS=${NS}${FQIA_E[0]} |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 18 | CONFIG="/opt/app/aaf_config" |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 19 | OSAAF="/opt/app/osaaf" |
| 20 | LOCAL="$OSAAF/local" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 21 | DOT_AAF="$HOME/.aaf" |
| 22 | SSO="$DOT_AAF/sso.props" |
| 23 | |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 24 | # Check for local dir |
| 25 | if [ ! -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 |
| 30 | fi |
| 31 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 32 | # Setup Bash, first time only |
| 33 | if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep aaf_config $HOME/.bash_aliases)" ]; then |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 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 |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 37 | . $HOME/.bash_aliases |
| 38 | fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 39 | |
| 40 | # Setup SSO info for Deploy ID |
| 41 | function sso_encrypt() { |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 42 | $JAVA -cp $CONFIG/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine digest ${1} $DOT_AAF/keyfile |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 45 | |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 46 | # Create Deployer Info, located at /root/.aaf |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 47 | if [ ! -e "$DOT_AAF/keyfile" ]; then |
| 48 | mkdir -p $DOT_AAF |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 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 |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 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} |
| 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} |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 59 | |
| 60 | base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks |
| 61 | echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO} |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 62 | echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO} |
| 63 | fi |
| 64 | |
| 65 | # Only initialize once, automatically... |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 66 | if [ ! -e $LOCAL/${NS}.props ]; then |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 67 | # setup Configs |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 68 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config $APP_FQI \ |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 69 | aaf_url=https://AAF_LOCATE_URL/AAF_NS.locate:${AAF_INTERFACE_VERSION} \ |
| 70 | cadi_etc_dir=$LOCAL |
| 71 | cat $LOCAL/$NS.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 72 | |
Instrumental | 4952530 | 2018-10-06 20:32:59 -0500 | [diff] [blame] | 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} \ |
| 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 |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 82 | |
| 83 | # Validate |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 84 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate \ |
| 85 | cadi_prop_files=$LOCAL/${NS}.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 86 | fi |
| 87 | |
| 88 | # Now run a command |
| 89 | CMD=$2 |
| 90 | if [ ! "$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 |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 115 | rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 116 | done |
| 117 | ;; |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 118 | showpass) |
| 119 | echo "## Show Passwords" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 120 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar showpass ${APP_FQI} ${APP_FQDN} |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 121 | ;; |
| 122 | check) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 123 | $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar check ${APP_FQI} ${APP_FQDN} |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 124 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 125 | validate) |
| 126 | echo "## validate requested" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 127 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate $LOCAL/${NS}.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 128 | ;; |
| 129 | bash) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 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 |
| 133 | #fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 134 | shift |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 135 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 136 | /bin/bash "$@" |
| 137 | ;; |
| 138 | setProp) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 139 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 140 | 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 |
Instrumental | 6095e29 | 2018-09-06 13:27:15 -0500 | [diff] [blame] | 150 | sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 151 | fi |
| 152 | cat $F |
| 153 | done |
| 154 | ;; |
| 155 | encrypt) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 156 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 157 | echo $1 |
| 158 | FILES=$(grep -l "$1" ./*.props) |
| 159 | if [ "$FILES" = "" ]; then |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 160 | FILES=$LOCAL/${NS}.cred.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 161 | 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 |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 175 | PWD=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" $LOCAL/${NS}.keyfile) |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 176 | 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 ---" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 205 | $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi | tail -n +6 |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 206 | ;; |
| 207 | agent) |
| 208 | echo "--- agent Tool Comands ---" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 209 | $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 210 | ;; |
| 211 | esac |
| 212 | echo "" |
| 213 | ;; |
| 214 | *) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 215 | $JAVA -Dcadi_prop_files=$LOCAL/${NS}.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@" |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 216 | ;; |
| 217 | esac |
| 218 | fi |