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" |
| 19 | LOCAL="/opt/app/osaaf/local" |
| 20 | DOT_AAF="$HOME/.aaf" |
| 21 | SSO="$DOT_AAF/sso.props" |
| 22 | |
| 23 | # Setup Bash, first time only |
| 24 | if [ ! -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 |
| 29 | fi |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 30 | |
| 31 | # Setup SSO info for Deploy ID |
| 32 | function sso_encrypt() { |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 33 | $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] | 34 | } |
| 35 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 36 | |
| 37 | if [ ! -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 |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 42 | 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} |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 50 | |
| 51 | base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $DOT_AAF/truststoreONAPall.jks |
| 52 | echo "cadi_truststore=$DOT_AAF/truststoreONAPall.jks" >> ${SSO} |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 53 | echo cadi_truststore_password=enc:$(sso_encrypt changeit) >> ${SSO} |
| 54 | fi |
| 55 | |
| 56 | # Only initialize once, automatically... |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 57 | if [ ! -e $LOCAL/${NS}.props ]; then |
| 58 | mkdir -p $LOCAL |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 59 | for D in bin logs; do |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 60 | rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 61 | done |
| 62 | |
| 63 | # setup Configs |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 64 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config $APP_FQI \ |
| 65 | cadi_etc_dir=$LOCAL cadi_prop_files=$SSO |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 66 | |
| 67 | # Place Certificates |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 68 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar place ${APP_FQI} ${APP_FQDN} |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 69 | |
| 70 | # Validate |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 71 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate \ |
| 72 | cadi_prop_files=$LOCAL/${NS}.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 73 | fi |
| 74 | |
| 75 | # Now run a command |
| 76 | CMD=$2 |
| 77 | if [ ! "$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 |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 102 | rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 103 | done |
| 104 | ;; |
Instrumental | 87da9fe | 2018-07-19 16:44:02 -0500 | [diff] [blame] | 105 | showpass) |
| 106 | echo "## Show Passwords" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 107 | $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] | 108 | ;; |
| 109 | check) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 110 | $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] | 111 | ;; |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 112 | validate) |
| 113 | echo "## validate requested" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 114 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate $LOCAL/${NS}.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 115 | ;; |
| 116 | bash) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 117 | #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 |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 121 | shift |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 122 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 123 | /bin/bash "$@" |
| 124 | ;; |
| 125 | setProp) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 126 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 127 | 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 |
Instrumental | 6095e29 | 2018-09-06 13:27:15 -0500 | [diff] [blame] | 137 | sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 138 | fi |
| 139 | cat $F |
| 140 | done |
| 141 | ;; |
| 142 | encrypt) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 143 | cd $LOCAL || exit |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 144 | echo $1 |
| 145 | FILES=$(grep -l "$1" ./*.props) |
| 146 | if [ "$FILES" = "" ]; then |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 147 | FILES=$LOCAL/${NS}.cred.props |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 148 | 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 |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 162 | 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] | 163 | 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 ---" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 192 | $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] | 193 | ;; |
| 194 | agent) |
| 195 | echo "--- agent Tool Comands ---" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 196 | $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] | 197 | ;; |
| 198 | esac |
| 199 | echo "" |
| 200 | ;; |
| 201 | *) |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame^] | 202 | $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] | 203 | ;; |
| 204 | esac |
| 205 | fi |