59486e941f1da634b08769798c1033a2dbb59bc1
[demo.git] / heat / ONAP / cloud-config / aaf_vm_init.sh
1 #!/bin/bash
2
3 CURRENT_DIR=$(pwd)
4
5 NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)
6 NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)
7 if [ -e /opt/authz/auth/docker/d.props ]; then
8   NEXUS_DOCKER_REPO=`grep "DOCKER_REPOSITORY=" /opt/authz/auth/docker/d.props`
9 else 
10   NEXUS_DOCKER_REPO="DOCKER_REPOSITORY="
11 fi
12
13 if [ "$NEXUS_DOCKER_REPO" = "DOCKER_REPOSITORY=" ]; then
14   NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
15 else
16   NEXUS_DOCKER_REPO=${NEXUS_DOCKER_REPO#DOCKER_REPOSITORY=}
17 fi
18
19 echo $NEXUS_DOCKER_REPO
20 HOSTNAME=`hostname -f`
21 FQDN=aaf.api.simpledemo.onap.org
22 HOST_IP=$(cat /opt/config/local_ip.txt)
23
24 cd /opt/authz/auth/auth-cass/docker
25 if [ "`docker container ls | grep aaf_cass`" = "" ]; then
26   # Cassandra Install
27   echo Phase 1 Cassandra Install
28   bash ./dinstall.sh
29 fi
30
31 if [ ! -e /opt/authz/auth/docker/d.props ]; then
32   cp /opt/authz/auth/docker/d.props.init /opt/authz/auth/docker/d.props
33 fi
34
35 VERSION=$(grep VERSION /opt/authz/auth/docker/d.props)
36 VERSION=${VERSION#VERSION=}
37 CASS_IP=`docker inspect aaf_cass | grep '"IPAddress' | head -1 | cut -d '"' -f 4`
38 CASS_HOST="cass.aaf.osaaf.org:"$CASS_IP
39 if [ ! -e /opt/authz/auth/docker/cass.props ]; then
40   cp /opt/authz/auth/docker/cass.props.init /opt/authz/auth/docker/cass.props
41 fi
42
43 sed -i "s/CASS_HOST=.*/CASS_HOST="$CASS_HOST"/g" /opt/authz/auth/docker/cass.props
44 # TODO Pull from Config Dir
45 CADI_LATITUDE=37.781
46 CADI_LONGITUDE=-122.261
47
48 sed -i "s/DOCKER_REPOSITORY=.*/DOCKER_REPOSITORY=$NEXUS_DOCKER_REPO/g" /opt/authz/auth/docker/d.props
49 sed -i "s/VERSION=.*/VERSION=$VERSION/g" /opt/authz/auth/docker/d.props
50 sed -i "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/g" /opt/authz/auth/docker/d.props
51 sed -i "s/HOST_IP=.*/HOST_IP=$HOST_IP/g" /opt/authz/auth/docker/d.props
52 sed -i "s/LATITUDE=.*/LATITUDE=$CADI_LATITUDE/g" /opt/authz/auth/docker/d.props
53 sed -i "s/LONGITUDE=.*/LONGITUDE=$CADI_LONGITUDE/g" /opt/authz/auth/docker/d.props
54
55 SIGNER_P12="$CURRENT_DIR/sample_ca/aaf.signer.p12"
56 AAF_P12="$CURRENT_DIR/sample_ca/aaf.bootstrap.p12"
57 P12_PASSWORD="something easy"
58
59 if [ ! -e "$AAF_P12" ]; then
60   mkdir -p $CURRENT_DIR/sample_ca
61   cd /opt/authz/conf/CA 
62   /bin/bash bootstrap.sh $SIGNER_P12 "$P12_PASSWORD"
63   if [ ! -e "aaf.bootstrap.p12" ]; then
64           echo "Certificates NOT created.  Stopping installation"
65           exit
66   else
67           mv aaf.bootstrap.p12 $AAF_P12
68   fi
69   cd -
70 fi 
71
72 if [ -e "$AAF_P12" ]; then
73     sed -i "s/AAF_INITIAL_X509_P12=.*/AAF_INITIAL_X509_P12=${AAF_P12//\//\\/}/g" /opt/authz/auth/docker/d.props
74     sed -i "s/AAF_INITIAL_X509_PASSWORD=.*/AAF_INITIAL_X509_PASSWORD=\"$P12_PASSWORD\"/g" /opt/authz/auth/docker/d.props
75 fi
76
77 if [ -e "$SIGNER_P12" ]; then
78     if [ -e "/opt/config/cadi_x509_issuers.txt" ]; then
79             ISSUERS=$(cat "/opt/config/cadi_x509_issuers.txt")":"
80     fi
81     # Pick the REAL subject off the P12
82     SUBJECT=$(echo "$P12_PASSWORD" | openssl pkcs12 -info -clcerts -in $SIGNER_P12 -nokeys -passin stdin | grep subject)
83     SUBJECT=${SUBJECT//\// }
84     SUBJECT=${SUBJECT/subject= /}
85     # Needs to be reversed, separated by ", "
86     for S in $SUBJECT ; do
87         if [ "$RSUBJECT" = "" ]; then
88            RSUBJECT=$S
89         else
90            RSUBJECT="$S, $RSUBJECT"
91         fi
92     done
93     ISSUERS="$ISSUERS$RSUBJECT"
94     sed -i "s/CADI_X509_ISSUERS=.*/CADI_X509_ISSUERS=\"$ISSUERS\"/g" /opt/authz/auth/docker/d.props
95     sed -i "s/AAF_SIGNER_P12=.*/AAF_SIGNER_P12=${SIGNER_P12//\//\\/}/g" /opt/authz/auth/docker/d.props
96     sed -i "s/AAF_SIGNER_PASSWORD=.*/AAF_SIGNER_PASSWORD=\"$P12_PASSWORD\"/g" /opt/authz/auth/docker/d.props
97 fi
98
99 cd /opt/authz/auth/docker
100 # Need new Deployment system properties
101 bash ./aaf.sh
102
103 # run it
104 bash ./drun.sh