blob: 09379730e49ee5142347ee2d983e2c968853c195 [file] [log] [blame]
Instrumentalbc299c02018-09-25 06:42:31 -05001#!/bin/bash
2#
3# Engage normal Cass Init, then check for data installation
4#
Instrumental08e93402018-10-03 08:38:52 -05005DIR="/opt/app/aaf/status"
6
Instrumentalbc299c02018-09-25 06:42:31 -05007if [ ! -e /aaf_cmd ]; then
8 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
9 chmod u+x /aaf_cmd
10fi
11
Instrumental08e93402018-10-03 08:38:52 -050012function status {
13 if [ -d "$DIR" ]; then
14 echo "$@"
15 echo "$@" > $DIR/aaf_cass
16 fi
17}
18
Instrumentalbc299c02018-09-25 06:42:31 -050019function install_cql {
Instrumental08e93402018-10-03 08:38:52 -050020 status install
21 sleep 10
22 status wait for cassandra to start
Instrumentalbc299c02018-09-25 06:42:31 -050023 # 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
Instrumental08e93402018-10-03 08:38:52 -050042 status keyspace installed
Instrumentalbc299c02018-09-25 06:42:31 -050043 echo " cqlsh -f init.cql"
44 /usr/bin/cqlsh -f init.cql
Instrumental08e93402018-10-03 08:38:52 -050045 status data initialized
Instrumentalbc299c02018-09-25 06:42:31 -050046 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
Instrumental08e93402018-10-03 08:38:52 -050051 status $1
Instrumentalbc299c02018-09-25 06:42:31 -050052}
53
Instrumental08e93402018-10-03 08:38:52 -050054function install_onap {
55 install_cql initialized
Instrumentalbc299c02018-09-25 06:42:31 -050056
57 # Change date expiring dat files to more recent
Instrumental08e93402018-10-03 08:38:52 -050058 status Creating ONAP Identities
Instrumentalbc299c02018-09-25 06:42:31 -050059 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
Instrumental08e93402018-10-03 08:38:52 -050090 status Setting up User Roles
Instrumentalbc299c02018-09-25 06:42:31 -050091 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
Instrumental08e93402018-10-03 08:38:52 -050097 status Pushing data to cassandra
98 bash push.sh
99 status ready
100}
101
102case "$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
Instrumentalbc299c02018-09-25 06:42:31 -0500118 ;;
119esac
120