blob: 15c3714d1db725a364c01fbe97a0f26cba94ac9c [file] [log] [blame]
Instrumental4ad47632018-07-13 15:49:26 -05001#!/bin/bash
Instrumental9ec28952018-07-12 11:14:10 -05002# This script is run when starting aaf_config Container.
3# It needs to cover the cases where the initial data doesn't exist, and when it has already been configured (don't overwrite)
4#
5JAVA=/usr/bin/java
6
7# Only load Identities once
8if [ ! -e /opt/app/osaaf/data/identities.dat ]; then
Instrumental4ad47632018-07-13 15:49:26 -05009 mkdir -p /opt/app/osaaf/data
10 cp /opt/app/aaf_config/data/sample.identities.dat /opt/app/osaaf/data/identities.dat
Instrumental9ec28952018-07-12 11:14:10 -050011fi
12
13# Only initialize once, automatically...
14if [ ! -e /opt/app/osaaf/local/org.osaaf.aaf.props ]; then
Instrumental4ad47632018-07-13 15:49:26 -050015 rsync -avzh --exclude=.gitignore /opt/app/aaf_config/local/org.osaaf.aaf* /opt/app/osaaf/local
16 for D in public etc logs; do
17 rsync -avzh --exclude=.gitignore /opt/app/aaf_config/$D/* /opt/app/osaaf/$D
18 done
Instrumental9c8a8b02018-07-16 18:41:10 -050019
20 TMP=$(mktemp)
21 echo aaf_env=${AAF_ENV} >> ${TMP}
22 echo cadi_latitude=${LATITUDE} >> ${TMP}
23 echo cadi_longitude=${LONGITUDE} >> ${TMP}
24 echo aaf_register_as=${AAF_REGISTER_AS} >> ${TMP}
25 echo aaf_locate_url=https://${AAF_REGISTER_AS}:8095 >> ${TMP}
26
27 $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar config aaf@aaf.osaaf.org \
Instrumental4ad47632018-07-13 15:49:26 -050028 cadi_etc_dir=/opt/app/osaaf/local \
Instrumental9c8a8b02018-07-16 18:41:10 -050029 cadi_prop_files=/opt/app/aaf_config/local/initialConfig.props:/opt/app/aaf_config/local/aaf.props:${TMP}
30 rm ${TMP}
31 # Default Password for Default Cass
32 CASS_PASS=$("$JAVA" -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar cadi digest "cassandra" /opt/app/osaaf/local/org.osaaf.aaf.keyfile)
33 sed -i.backup -e "s/\\(cassandra.clusters.password=enc:\\)/\\1$CASS_PASS/" /opt/app/osaaf/local/org.osaaf.aaf.cassandra.props
Instrumental4ad47632018-07-13 15:49:26 -050034fi
Instrumental9ec28952018-07-12 11:14:10 -050035
Instrumental4ad47632018-07-13 15:49:26 -050036# Now run a command
37CMD=$2
38if [ ! "$CMD" = "" ]; then
39 shift
40 shift
41 case "$CMD" in
42 ls)
43 echo ls requested
44 find /opt/app/osaaf -depth
45 ;;
46 cat)
47 if [ "$1" = "" ]; then
48 echo "usage: cat <file... ONLY files ending in .props>"
49 else
50 if [[ $1 == *.props ]]; then
51 echo
52 echo "## CONTENTS OF $3"
53 echo
54 cat "$1"
55 else
56 echo "### ERROR ####"
57 echo " \"cat\" may only be used with files ending with \".props\""
58 fi
59 fi
60 ;;
61 update)
62 rsync -uh --exclude=.gitignore /opt/app/aaf_config/local/org.osaaf.aaf* /opt/app/osaaf/local
63 for D in public data etc logs; do
64 rsync -uh --exclude=.gitignore /opt/app/aaf_config/$D/* /opt/app/osaaf/$D
65 done
66 ;;
67 validate)
68 echo "## validate requested"
69 $JAVA -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar validate cadi_prop_files=/opt/app/osaaf/local/org.osaaf.aaf.props
70 ;;
71 bash)
72 echo "alias agent='/bin/bash /opt/app/aaf_config/bin/agent.sh EMPTY \$*'" >>~/.bashrc
73 if [ ! "$(grep aaf_config ~/.bashrc)" = "" ]; then
74 echo "alias cadi='/bin/bash /opt/app/aaf_config/bin/agent.sh EMPTY cadi \$*'" >>~/.bashrc
75 echo "alias agent='/bin/bash /opt/app/aaf_config/bin/agent.sh EMPTY \$*'" >>~/.bashrc
76 #. ~/.bashrc
77 fi
78 shift
79 cd /opt/app/osaaf/local || exit
80 /bin/bash "$@"
81 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -050082 setProp)
Instrumental4ad47632018-07-13 15:49:26 -050083 cd /opt/app/osaaf/local || exit
84 FILES=$(grep -l "$1" ./*.props)
Instrumental9c8a8b02018-07-16 18:41:10 -050085 if [ "$FILES" = "" ]; then
86 FILES="$3"
87 ADD=Y
88 fi
89 for F in $FILES; do
90 echo "Changing $1 in $F"
91 if [ "$ADD" = "Y" ]; then
92 echo $2 >> $F
93 else
94 sed -i.backup -e "s/\\(${1}.*=\\).*/\\1${2}/" $F
95 fi
96 cat $F
97 done
98 ;;
99 encrypt)
100 cd /opt/app/osaaf/local || exit
101 echo $1
102 FILES=$(grep -l "$1" ./*.props)
103 if [ "$FILES" = "" ]; then
104 FILES=/opt/app/osaaf/local/org.osaaf.aaf.cred.props
105 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500106 fi
107 for F in $FILES; do
108 echo "Changing $1 in $F"
109 if [ "$2" = "" ]; then
110 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
111 echo " "
112 if [ "$ORIG_PW" = "" ]; then
113 echo canceling...
114 break
115 fi
116 else
117 ORIG_PW="$2"
118 fi
119 PWD=$("$JAVA" -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar cadi digest "$ORIG_PW" /opt/app/osaaf/local/org.osaaf.aaf.keyfile)
Instrumental9c8a8b02018-07-16 18:41:10 -0500120 if [ "$ADD" = "Y" ]; then
121 echo "$1=enc:$PWD" >> $F
122 else
123 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
124 fi
Instrumental4ad47632018-07-13 15:49:26 -0500125 cat $F
126 done
127 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500128 taillog)
129 sh /opt/app/osaaf/logs/taillog
130 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500131 --help | -?)
132 case "$1" in
133 "")
134 echo "--- Agent Container Comands ---"
135 echo " ls - Lists all files in Configuration"
136 echo " cat <file.props>> - Shows the contents (Prop files only)"
137 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500138 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500139 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
140 echo " bash - run bash in Container"
141 echo " Note: the following aliases are preset"
142 echo " cadi - CADI CmdLine tool"
143 echo " agent - Agent Java tool (see above help)"
144 echo ""
145 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
146 ;;
147 cadi)
148 echo "--- cadi Tool Comands ---"
149 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/org.osaaf.aaf.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar cadi | tail -n +6
150 ;;
151 agent)
152 echo "--- agent Tool Comands ---"
153 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/org.osaaf.aaf.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar
154 ;;
155 esac
156 echo ""
157 ;;
158 *)
159 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/org.osaaf.aaf.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
160 ;;
161 esac
162fi