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