blob: 4f8805c87cd03965e7c0c63c35f4026a352f318f [file] [log] [blame]
Instrumental94053612018-10-08 11:27:18 -05001#!/bin/bash
2#
3# Copies of Repo data need to be added to "dats" dir for loading by push.sh
4#
5# Further, repo data has dates that are out of date and may have IDs not valid. We need to make
6# sure the important data is consistent with Identities.
7#
8# This is expected to be run from a controlling Machine data "authz/auth/sample/cass_data" when a backup
9# is created that is intended to be "Bootstrap Data"
10#
11# Date resets on key data load on the system at load time
12#
Instrumental28f5a472018-10-04 13:22:18 -050013
Instrumental94053612018-10-08 11:27:18 -050014DIR=$(pwd)
15ID_FILE=../data/sample.identities.dat
Instrumental28f5a472018-10-04 13:22:18 -050016
Instrumental94053612018-10-08 11:27:18 -050017if [ -e $ID_FILE ]; then
18 if [ "$(uname -s)" = "Darwin" ]; then
Instrumentalc687ff52018-10-16 19:22:04 -050019 DATE=$(date -v "+6m" "+%Y-%m-%d %H:%M:%S.000+0000")
Instrumental94053612018-10-08 11:27:18 -050020 else
21 DATE=$(date "+%Y-%m-%d %H:%M:%S.000+0000" -d "+6 months")
22 fi
23 echo $DATE
Instrumental28f5a472018-10-04 13:22:18 -050024
Instrumental94053612018-10-08 11:27:18 -050025 #### CRED
26 # Enter for People
27 CRED="cred.dat"
Instrumentalc687ff52018-10-16 19:22:04 -050028 rm cred.dat
Instrumental94053612018-10-08 11:27:18 -050029 echo "Create default Passwords for all Identities in $CRED"
30 for ID in $(grep '|a|' $ID_FILE | sed -e "s/|.*//"); do
31 if [ "$ID" = "aaf" ]; then
32 DOMAIN="aaf.osaaf.org";
33 else
34 DOMAIN="$ID.onap.org";
35 fi
36 unset FIRST
37 for D in ${DOMAIN//./ }; do
38 if [ -z "$FIRST" ]; then
39 NS="$D"
40 FIRST="N"
41 else
42 NS="$D.$NS"
43 fi
44 done
45 echo "$ID@$DOMAIN|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|$NS|53344|" >> $CRED
46 done
Instrumental28f5a472018-10-04 13:22:18 -050047
Instrumental94053612018-10-08 11:27:18 -050048 for ID in $(grep '|e|' $ID_FILE | sed -e "s/|.*//"); do
49 echo "$ID@people.osaaf.org|2|${DATE}|0xd993c5617486296f1b99d04de31633332b8ba1a550038e23860f9dbf0b2fcf95|Initial ID|org.osaaf.people|53344|" >> $CRED
50 done
51
Instrumental94053612018-10-08 11:27:18 -050052 ##### USER_ROLE
53 echo "Scrubbing user_roles not in $ID_FILE"
Instrumentalc687ff52018-10-16 19:22:04 -050054
55 ## Covering for when scrubbing in cass_init versus a Backup
56 if [ -d "dats" ]; then
57 for D in ns ns_attrib perm role config artifact; do
58 if [ -e "dats/$D.dat" ]; then
59 cp dats/$D.dat .
60 fi
61 done
62 else
63 mkdir -p dats
64 cp user_role.dat dats
65 REMOVE_DATS=true
66 fi
Instrumental94053612018-10-08 11:27:18 -050067 > user_role.dat
68 for ID in $(grep -v "#" $ID_FILE | awk -F\| '{print $1}' | grep -v "^$"); do
69 grep "$ID@" dats/user_role.dat >> user_role.dat
70 done
71
Instrumental94053612018-10-08 11:27:18 -050072 UR="$(mktemp)"
73 DUR="$(mktemp)"
74
75 cat user_role.dat | awk -F\| '{print $1}' | sort -u > $UR
76 cat dats/user_role.dat | awk -F\| '{print $1}' | sort -u > $DUR
77
78 echo "Removed IDs from user_roles"
79 diff $UR $DUR | grep "^>" | sort -u
80
81 rm "$UR" "$DUR"
82
83 mv user_role.dat tmp
84 sed "s/\(^.*|\)\(.*|\)\(.*|\)\(.*\)/\1${DATE}|\3\4/" tmp > user_role.dat
85 rm tmp
Instrumentalc687ff52018-10-16 19:22:04 -050086 if [ -n "$REMOVE_DATS" ]; then
87 rm -Rf dats
88 fi
Instrumental94053612018-10-08 11:27:18 -050089else
90 echo $0 requires access to $ID_FILE
91fi
92
93