Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 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 |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 6 | LOCAL=/opt/app/osaaf/local |
| 7 | DATA=/opt/app/osaaf/data |
| 8 | PUBLIC=/opt/app/osaaf/public |
| 9 | CONFIG=/opt/app/aaf_config |
Instrumental | 5451a50 | 2018-10-10 18:51:33 -0500 | [diff] [blame] | 10 | |
| 11 | # If doesn't exist... still create |
| 12 | mkdir -p /opt/app/osaaf |
| 13 | |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 14 | # Temp use for clarity of code |
| 15 | FILE= |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 16 | |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 17 | # Setup Bash, first time only |
| 18 | if [ ! -e "$HOME/.bash_aliases" ] || [ -z "$(grep aaf_config $HOME/.bash_aliases)" ]; then |
| 19 | echo "alias cadi='$CONFIG/bin/agent.sh EMPTY cadi \$*'" >>$HOME/.bash_aliases |
| 20 | echo "alias agent='$CONFIG/bin/agent.sh EMPTY \$*'" >>$HOME/.bash_aliases |
| 21 | chmod a+x $CONFIG/bin/agent.sh |
| 22 | . $HOME/.bash_aliases |
| 23 | fi |
| 24 | |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 25 | # Only load Identities once |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 26 | # echo "Check Identities" |
| 27 | FILE="$DATA/identities.dat" |
| 28 | if [ ! -e $FILE ]; then |
| 29 | mkdir -p $DATA |
| 30 | cp $CONFIG/data/sample.identities.dat $FILE |
| 31 | fi |
| 32 | |
| 33 | # Load up Cert/X509 Artifacts |
| 34 | # echo "Check Signer Keyfile" |
| 35 | FILE="$LOCAL/org.osaaf.aaf.signer.p12" |
| 36 | if [ ! -e $FILE ]; then |
| 37 | mkdir -p $LOCAL |
| 38 | mkdir -p $PUBLIC |
| 39 | if [ -e $CONFIG/cert/org.osaaf.aaf.signer.p12 ]; then |
| 40 | cp $CONFIG/cert/org.osaaf.aaf.signer.p12 $FILE |
| 41 | else |
| 42 | echo "Decode" |
| 43 | base64 -d $CONFIG/cert/demoONAPsigner.p12.b64 > $FILE |
| 44 | base64 -d $CONFIG/cert/truststoreONAP.p12.b64 > $PUBLIC/truststoreONAP.p12 |
| 45 | base64 -d $CONFIG/cert/truststoreONAPall.jks.b64 > $PUBLIC/truststoreONAPall.jks |
| 46 | ln -s $PUBLIC/truststoreONAPall.jks $LOCAL |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 47 | cp $CONFIG/cert/AAF_RootCA.cer $PUBLIC |
| 48 | CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 49 | echo "cadi_keystore_password=something easy" >> $CONFIG/local/aaf.props |
| 50 | fi |
| 51 | fi |
| 52 | |
| 53 | # echo "Check keyfile" |
| 54 | FILE="$LOCAL/org.osaaf.aaf.p12" |
| 55 | if [ ! -e $FILE ]; then |
| 56 | if [ -e $CONFIG/cert/org.osaaf.aaf.p12 ]; then |
| 57 | cp $CONFIG/cert/org.osaaf.aaf.p12 $FILE |
| 58 | else |
| 59 | echo "Bootstrap Creation of Keystore from Signer" |
| 60 | cd $CONFIG/CA |
| 61 | |
| 62 | # Remove this after Casablanca |
| 63 | CADI_X509_ISSUERS="CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US:CN=intermediateCA_7, OU=OSAAF, O=ONAP, C=US" |
| 64 | bash bootstrap.sh $LOCAL/org.osaaf.aaf.signer.p12 'something easy' |
| 65 | cp aaf.bootstrap.p12 $FILE |
| 66 | if [ -n "$CADI_X509_ISSUERS" ]; then |
| 67 | CADI_X509_ISSUERS="$CADI_X509_ISSUERS:" |
| 68 | fi |
| 69 | BOOT_ISSUER="$(cat aaf.bootstrap.issuer)" |
| 70 | CADI_X509_ISSUERS="$CADI_X509_ISSUERS$BOOT_ISSUER" |
| 71 | |
| 72 | I=${BOOT_ISSUER##CN=};I=${I%%,*} |
| 73 | CM_CA_PASS="something easy" |
| 74 | CM_CA_LOCAL="org.onap.aaf.auth.cm.ca.LocalCA,$LOCAL/org.osaaf.aaf.signer.p12;aaf_intermediate_9;enc:" |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 75 | CM_TRUST_CAS="$PUBLIC/AAF_RootCA.cer" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 76 | fi |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 77 | fi |
| 78 | |
| 79 | # Only initialize once, automatically... |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 80 | if [ ! -e $LOCAL/org.osaaf.aaf.props ]; then |
| 81 | rsync -avzh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 82 | for D in public etc logs; do |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 83 | rsync -avzh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 84 | done |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 85 | |
| 86 | TMP=$(mktemp) |
| 87 | echo aaf_env=${AAF_ENV} >> ${TMP} |
Instrumental | 575c982 | 2018-10-19 11:13:05 -0500 | [diff] [blame^] | 88 | echo aaf_release=${VERSION} >> ${TMP} |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 89 | echo cadi_latitude=${LATITUDE} >> ${TMP} |
| 90 | echo cadi_longitude=${LONGITUDE} >> ${TMP} |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 91 | echo cadi_x509_issuers=${CADI_X509_ISSUERS} >> ${TMP} |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 92 | echo aaf_register_as=${AAF_REGISTER_AS} >> ${TMP} |
Instrumental | 93871ff | 2018-10-15 07:37:28 -0500 | [diff] [blame] | 93 | AAF_LOCATOR_AS=${AAF_LOCATOR_AS:=$AAF_REGISTER_AS} |
Instrumental | 5451a50 | 2018-10-10 18:51:33 -0500 | [diff] [blame] | 94 | echo aaf_locate_url=https://${AAF_LOCATOR_AS}:8095 >> ${TMP} |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 95 | |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 96 | cat $TMP |
| 97 | |
| 98 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar config aaf@aaf.osaaf.org \ |
| 99 | cadi_etc_dir=$LOCAL \ |
| 100 | cadi_prop_files=$CONFIG/local/initialConfig.props:$CONFIG/local/aaf.props:${TMP} |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 101 | rm ${TMP} |
Instrumental | 196000b | 2018-10-05 19:30:59 -0500 | [diff] [blame] | 102 | |
| 103 | # Cassandra Config stuff |
| 104 | # Default is expect a Cassandra on same Node |
Instrumental | 93871ff | 2018-10-15 07:37:28 -0500 | [diff] [blame] | 105 | CASS_HOST=${CASS_HOST:="aaf_cass"} |
Instrumental | 196000b | 2018-10-05 19:30:59 -0500 | [diff] [blame] | 106 | CASS_PASS=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "${CASSANDRA_PASSWORD:-cassandra}" $LOCAL/org.osaaf.aaf.keyfile) |
| 107 | CASS_NAME=${CASS_HOST/:*/} |
Instrumental | 14f3707 | 2018-10-09 08:32:06 -0500 | [diff] [blame] | 108 | sed -i.backup -e "s/\\(cassandra.clusters=\\).*/\\1${CASSANDRA_CLUSTERS:=$CASS_HOST}/" \ |
Instrumental | 196000b | 2018-10-05 19:30:59 -0500 | [diff] [blame] | 109 | -e "s/\\(cassandra.clusters.user=\\).*/\\1${CASSANDRA_USER:=cassandra}/" \ |
| 110 | -e "s/\\(cassandra.clusters.password=enc:\\).*/\\1$CASS_PASS/" \ |
| 111 | -e "s/\\(cassandra.clusters.port=\\).*/\\1${CASSANDRA_PORT:=9042}/" \ |
| 112 | $LOCAL/org.osaaf.aaf.cassandra.props |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 113 | |
| 114 | if [ -n "$CM_CA_LOCAL" ]; then |
| 115 | if [ -n "$CM_CA_PASS" ]; then |
| 116 | CM_CA_LOCAL=$CM_CA_LOCAL$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$CM_CA_PASS" $LOCAL/org.osaaf.aaf.keyfile) |
| 117 | fi |
| 118 | # Move and copy method, rather than sed, because of slashes in CM_CA_LOCAL makes too complex |
| 119 | FILE=$LOCAL/org.osaaf.aaf.cm.ca.props |
| 120 | mv $FILE $FILE.backup |
| 121 | grep -v "cm_ca.local=" $FILE.backup > $FILE |
| 122 | echo "cm_ca.local=$CM_CA_LOCAL" >> $FILE |
Instrumental | 365638c | 2018-10-01 15:26:03 -0500 | [diff] [blame] | 123 | echo "cm_trust_cas=$CM_TRUST_CAS" >> $FILE |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 124 | fi |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 125 | fi |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 126 | |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 127 | |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 128 | # Now run a command |
| 129 | CMD=$2 |
| 130 | if [ ! "$CMD" = "" ]; then |
| 131 | shift |
| 132 | shift |
| 133 | case "$CMD" in |
| 134 | ls) |
| 135 | echo ls requested |
| 136 | find /opt/app/osaaf -depth |
| 137 | ;; |
| 138 | cat) |
| 139 | if [ "$1" = "" ]; then |
| 140 | echo "usage: cat <file... ONLY files ending in .props>" |
| 141 | else |
| 142 | if [[ $1 == *.props ]]; then |
| 143 | echo |
| 144 | echo "## CONTENTS OF $3" |
| 145 | echo |
| 146 | cat "$1" |
| 147 | else |
| 148 | echo "### ERROR ####" |
| 149 | echo " \"cat\" may only be used with files ending with \".props\"" |
| 150 | fi |
| 151 | fi |
| 152 | ;; |
| 153 | update) |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 154 | rsync -uh --exclude=.gitignore $CONFIG/local/org.osaaf.aaf* $LOCAL |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 155 | for D in public data etc logs; do |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 156 | rsync -uh --exclude=.gitignore $CONFIG/$D/* /opt/app/osaaf/$D |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 157 | done |
| 158 | ;; |
| 159 | validate) |
| 160 | echo "## validate requested" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 161 | $JAVA -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar validate cadi_prop_files=$LOCAL/org.osaaf.aaf.props |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 162 | ;; |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 163 | onap) |
| 164 | echo Initializing ONAP configurations. |
| 165 | ;; |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 166 | bash) |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 167 | shift |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 168 | cd $LOCAL || exit |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 169 | /bin/bash "$@" |
| 170 | ;; |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 171 | setProp) |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 172 | cd $LOCAL || exit |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 173 | FILES=$(grep -l "$1" ./*.props) |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 174 | if [ "$FILES" = "" ]; then |
| 175 | FILES="$3" |
| 176 | ADD=Y |
| 177 | fi |
| 178 | for F in $FILES; do |
| 179 | echo "Changing $1 in $F" |
| 180 | if [ "$ADD" = "Y" ]; then |
Instrumental | aeb80c8 | 2018-08-21 10:24:08 -0500 | [diff] [blame] | 181 | echo "$1=$2" >> $F |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 182 | else |
Instrumental | aeb80c8 | 2018-08-21 10:24:08 -0500 | [diff] [blame] | 183 | VALUE=${2//\//\\\/} |
Instrumental | 6095e29 | 2018-09-06 13:27:15 -0500 | [diff] [blame] | 184 | sed -i.backup -e "s/\(${1}=\).*/\1${VALUE}/" $F |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 185 | fi |
| 186 | cat $F |
| 187 | done |
| 188 | ;; |
| 189 | encrypt) |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 190 | cd $LOCAL || exit |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 191 | echo $1 |
| 192 | FILES=$(grep -l "$1" ./*.props) |
| 193 | if [ "$FILES" = "" ]; then |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 194 | FILES=$LOCAL/org.osaaf.aaf.cred.props |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 195 | ADD=Y |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 196 | fi |
| 197 | for F in $FILES; do |
| 198 | echo "Changing $1 in $F" |
| 199 | if [ "$2" = "" ]; then |
| 200 | read -r -p "Password (leave blank to cancel): " -s ORIG_PW |
| 201 | echo " " |
| 202 | if [ "$ORIG_PW" = "" ]; then |
| 203 | echo canceling... |
| 204 | break |
| 205 | fi |
| 206 | else |
| 207 | ORIG_PW="$2" |
| 208 | fi |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 209 | PWD=$("$JAVA" -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" $LOCAL/org.osaaf.aaf.keyfile) |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 210 | if [ "$ADD" = "Y" ]; then |
| 211 | echo "$1=enc:$PWD" >> $F |
| 212 | else |
| 213 | sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F |
| 214 | fi |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 215 | cat $F |
| 216 | done |
| 217 | ;; |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 218 | taillog) |
| 219 | sh /opt/app/osaaf/logs/taillog |
| 220 | ;; |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 221 | --help | -?) |
| 222 | case "$1" in |
| 223 | "") |
| 224 | echo "--- Agent Container Comands ---" |
| 225 | echo " ls - Lists all files in Configuration" |
| 226 | echo " cat <file.props>> - Shows the contents (Prop files only)" |
| 227 | echo " validate - Runs a test using Configuration" |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 228 | echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)" |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 229 | echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)" |
| 230 | echo " bash - run bash in Container" |
| 231 | echo " Note: the following aliases are preset" |
| 232 | echo " cadi - CADI CmdLine tool" |
| 233 | echo " agent - Agent Java tool (see above help)" |
| 234 | echo "" |
| 235 | echo " --help|-? [cadi|agent] - This help, cadi help or agent help" |
| 236 | ;; |
| 237 | cadi) |
| 238 | echo "--- cadi Tool Comands ---" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 239 | $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar cadi | tail -n +6 |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 240 | ;; |
| 241 | agent) |
| 242 | echo "--- agent Tool Comands ---" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 243 | $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 244 | ;; |
| 245 | esac |
| 246 | echo "" |
| 247 | ;; |
| 248 | *) |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 249 | $JAVA -Dcadi_prop_files=$LOCAL/org.osaaf.aaf.props -jar $CONFIG/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@" |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 250 | ;; |
| 251 | esac |
| 252 | fi |