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]} |
| 18 | |
| 19 | |
| 20 | # Setup SSO info for Deploy ID |
| 21 | function 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 | |
| 25 | if [ ! -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} |
| 40 | fi |
| 41 | |
| 42 | # Only initialize once, automatically... |
| 43 | if [ ! -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 |
| 58 | fi |
| 59 | |
| 60 | # Now run a command |
| 61 | CMD=$2 |
| 62 | if [ ! "$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 | ;; |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 90 | showpass) |
| 91 | echo "## Show Passwords" |
| 92 | $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar showpass ${APP_FQI} ${APP_FQDN} |
| 93 | ;; |
| 94 | check) |
| 95 | $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/${NS}.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar check ${APP_FQI} ${APP_FQDN} |
| 96 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 97 | validate) |
| 98 | echo "## validate requested" |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 99 | $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar validate /opt/app/osaaf/local/${NS}.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 100 | ;; |
| 101 | bash) |
| 102 | if [ ! -e ~/.bash_aliases ]; then |
| 103 | echo "alias cadi='$JAVA -cp /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.CmdLine \$*'" >~/.bash_aliases |
| 104 | echo "alias agent='$JAVA -cp /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar org.onap.aaf.cadi.configure.Agent \$*'" >>~/.bash_aliases |
| 105 | fi |
| 106 | shift |
| 107 | cd /opt/app/osaaf/local || exit |
| 108 | /bin/bash "$@" |
| 109 | ;; |
| 110 | setProp) |
| 111 | cd /opt/app/osaaf/local || exit |
| 112 | FILES=$(grep -l "$1" ./*.props) |
| 113 | if [ "$FILES" = "" ]; then |
| 114 | FILES="$3" |
| 115 | ADD=Y |
| 116 | fi |
| 117 | for F in $FILES; do |
| 118 | echo "Changing $1 in $F" |
| 119 | if [ "$ADD" = "Y" ]; then |
| 120 | echo $2 >> $F |
| 121 | else |
| 122 | sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F |
| 123 | fi |
| 124 | cat $F |
| 125 | done |
| 126 | ;; |
| 127 | encrypt) |
| 128 | cd /opt/app/osaaf/local || exit |
| 129 | echo $1 |
| 130 | FILES=$(grep -l "$1" ./*.props) |
| 131 | if [ "$FILES" = "" ]; then |
| 132 | FILES=/opt/app/osaaf/local/${NS}.cred.props |
| 133 | ADD=Y |
| 134 | fi |
| 135 | for F in $FILES; do |
| 136 | echo "Changing $1 in $F" |
| 137 | if [ "$2" = "" ]; then |
| 138 | read -r -p "Password (leave blank to cancel): " -s ORIG_PW |
| 139 | echo " " |
| 140 | if [ "$ORIG_PW" = "" ]; then |
| 141 | echo canceling... |
| 142 | break |
| 143 | fi |
| 144 | else |
| 145 | ORIG_PW="$2" |
| 146 | fi |
| 147 | PWD=$("$JAVA" -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" /opt/app/osaaf/local/${NS}.keyfile) |
| 148 | if [ "$ADD" = "Y" ]; then |
| 149 | echo "$1=enc:$PWD" >> $F |
| 150 | else |
| 151 | sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F |
| 152 | fi |
| 153 | cat $F |
| 154 | done |
| 155 | ;; |
| 156 | taillog) |
| 157 | sh /opt/app/osaaf/logs/taillog |
| 158 | ;; |
| 159 | --help | -?) |
| 160 | case "$1" in |
| 161 | "") |
| 162 | echo "--- Agent Container Comands ---" |
| 163 | echo " ls - Lists all files in Configuration" |
| 164 | echo " cat <file.props>> - Shows the contents (Prop files only)" |
| 165 | echo " validate - Runs a test using Configuration" |
| 166 | echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)" |
| 167 | echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)" |
| 168 | echo " bash - run bash in Container" |
| 169 | echo " Note: the following aliases are preset" |
| 170 | echo " cadi - CADI CmdLine tool" |
| 171 | echo " agent - Agent Java tool (see above help)" |
| 172 | echo "" |
| 173 | echo " --help|-? [cadi|agent] - This help, cadi help or agent help" |
| 174 | ;; |
| 175 | cadi) |
| 176 | echo "--- cadi Tool Comands ---" |
| 177 | $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 |
| 178 | ;; |
| 179 | agent) |
| 180 | echo "--- agent Tool Comands ---" |
| 181 | $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/${NS}.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar |
| 182 | ;; |
| 183 | esac |
| 184 | echo "" |
| 185 | ;; |
| 186 | *) |
| 187 | $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/${NS}.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@" |
| 188 | ;; |
| 189 | esac |
| 190 | fi |