Create Helm Instantiation
[aaf/authz.git] / auth / auth-cass / cass_init / cmd.sh
1 #!/bin/bash 
2 #
3 # Engage normal Cass Init, then check for data installation
4 #
5 DIR="/opt/app/aaf/status"
6
7 if [ ! -e /aaf_cmd ]; then
8   ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
9   chmod u+x /aaf_cmd
10 fi
11
12 function status {
13   if [ -d "$DIR" ]; then
14      echo "$@"
15      echo "$@" > $DIR/aaf_cass
16   fi
17 }
18
19 function install_cql {
20     status install 
21     sleep 10
22     status wait for cassandra to start
23     # Now, make sure data exists
24     if [ "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" = "" ]; then
25       for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
26          if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
27             echo "Waiting for Cassandra to start... Sleep 10"
28             sleep 10
29          else
30             break
31          fi
32       done
33       echo "Initializing Cassandra DB" 
34       if [ "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" == "" ]; then
35         echo "Docker Installed Basic Cassandra on aaf_cass.  Executing the following "
36         echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
37         echo ""
38         echo " cd /opt/app/aaf/cass_init"
39         cd /opt/app/aaf/cass_init
40         echo " cqlsh -f keyspace.cql"
41         /usr/bin/cqlsh -f keyspace.cql
42         status keyspace installed
43         echo " cqlsh -f init.cql"
44         /usr/bin/cqlsh -f init.cql
45         status data initialized
46         echo ""
47         echo "The following will give you a temporary identity with which to start working, or emergency"
48         echo " cqlsh -f temp_identity.cql"
49       fi
50     fi
51     status $1
52 }
53
54 function install_onap {
55         install_cql initialized
56
57         # Change date expiring dat files to more recent
58         status Creating ONAP Identities
59         ID_FILE=/opt/app/aaf/cass_init/sample.identities.dat    
60         if [ -e $ID_FILE ]; then
61             DATE=$(date "+%Y-%m-%d %H:%M:%S.000+0000" -d "+6 months")
62             echo $DATE
63             CRED="/opt/app/aaf/cass_init/dats/cred.dat"
64             # Enter for People
65             echo "Default Passwords for Apps"
66             for ID in $(grep '|a|' $ID_FILE | sed -e "s/|.*//"); do
67                if [ "$ID" = "aaf" ]; then
68                   DOMAIN="aaf.osaaf.org";
69                else
70                   DOMAIN="$ID.onap.org";
71                fi
72                unset FIRST
73                for D in ${DOMAIN//./ }; do
74                   if [ -z "$FIRST" ]; then
75                     NS="$D"
76                     FIRST="N"
77                   else
78                     NS="$D.$NS"
79                   fi
80                done
81                echo "$ID@$DOMAIN|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|$NS|53344|" >> $CRED
82             done
83             
84             # Enter for People
85             for ID in $(grep '|e|' $ID_FILE | sed -e "s/|.*//"); do
86                echo "$ID@people.osaaf.org|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|org.osaaf.people|53344|" >> $CRED
87             done
88
89             # Change UserRole
90             status Setting up User Roles
91             mv dats/user_role.dat tmp
92             sed "s/\(^.*|\)\(.*|\)\(.*|\)\(.*\)/\1${DATE}|\3\4/" tmp > dats/user_role.dat
93
94             # Remove ID File, which is marker for initializing Creds
95             rm $ID_FILE
96         fi
97       status Pushing data to cassandra
98       bash push.sh
99     status ready
100 }
101
102 case "$1" in
103   start)
104     # start install_cql in background, waiting for process to start
105     install_cql ready &
106
107     # Startup like normal
108     echo "Cassandra Startup"
109     /usr/local/bin/docker-entrypoint.sh 
110   ;;
111   onap)
112     # start install_onap (which calls install_cql first) in background, waiting for process to start
113     install_onap &
114
115     # Startup like normal
116     echo "Cassandra Startup"
117     /usr/local/bin/docker-entrypoint.sh 
118   ;;
119 esac
120