AAF Sample CA change
[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/public_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/config/sample_ca/aaf.signer.p12"
56 AAF_P12="$CURRENT_DIR/config/sample_ca/aaf.bootstrap.p12"
57 P12_PASSWORD="something easy"
58
59 if [ ! -e "$SIGNER_P12" ]; then
60   mkdir -p "$CURRENT_DIR/sample_ca"
61   cp /opt/authz/conf/onap.sample.signer.p12 "$SIGNER_P12"
62 fi
63
64 if [ ! -e "$AAF_P12" ]; then
65   mkdir -p $CURRENT_DIR/sample_ca
66   cd /opt/authz/conf/CA 
67   /bin/bash bootstrap.sh $SIGNER_P12 "$P12_PASSWORD"
68   if [ ! -e "aaf.bootstrap.p12" ]; then
69           echo "Certificates NOT created.  Stopping installation"
70           exit
71   else
72           mv aaf.bootstrap.p12 $AAF_P12
73   fi
74   cd -
75 fi 
76
77 if [ -e "$AAF_P12" ]; then
78     sed -i "s/AAF_INITIAL_X509_P12=.*/AAF_INITIAL_X509_P12=${AAF_P12//\//\\/}/g" /opt/authz/auth/docker/d.props
79     sed -i "s/AAF_INITIAL_X509_PASSWORD=.*/AAF_INITIAL_X509_PASSWORD=\"$P12_PASSWORD\"/g" /opt/authz/auth/docker/d.props
80 fi
81
82 if [ -e "$SIGNER_P12" ]; then
83     if [ -e "/opt/config/cadi_x509_issuers.txt" ]; then
84             ISSUERS=$(cat "/opt/config/cadi_x509_issuers.txt")":"
85     fi
86     # Pick the REAL subject off the P12
87     SUBJECT=$(echo "$P12_PASSWORD" | openssl pkcs12 -info -clcerts -in $SIGNER_P12 -nokeys -passin stdin | grep subject)
88     SUBJECT=${SUBJECT//\// }
89     SUBJECT=${SUBJECT/subject= /}
90     # Needs to be reversed, separated by ", "
91     for S in $SUBJECT ; do
92         if [ "$RSUBJECT" = "" ]; then
93            RSUBJECT=$S
94         else
95            RSUBJECT="$S, $RSUBJECT"
96         fi
97     done
98     ISSUERS="$ISSUERS$RSUBJECT"
99     sed -i "s/CADI_X509_ISSUERS=.*/CADI_X509_ISSUERS=\"$ISSUERS\"/g" /opt/authz/auth/docker/d.props
100     sed -i "s/AAF_SIGNER_P12=.*/AAF_SIGNER_P12=${SIGNER_P12//\//\\/}/g" /opt/authz/auth/docker/d.props
101     sed -i "s/AAF_SIGNER_PASSWORD=.*/AAF_SIGNER_PASSWORD=\"$P12_PASSWORD\"/g" /opt/authz/auth/docker/d.props
102 fi
103
104 cd /opt/authz/auth/docker
105 # Need new Deployment system properties
106 bash ./aaf.sh
107
108 # run it
109 bash ./drun.sh