blob: 33dca67fcc08c908cbe9e1616e50296318e185c1 [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
Instrumentalaeb80c82018-08-21 10:24:08 -050092 echo "$1=$2" >> $F
Instrumental9c8a8b02018-07-16 18:41:10 -050093 else
Instrumentalaeb80c82018-08-21 10:24:08 -050094 VALUE=${2//\//\\\/}
95 sed -i.backup -e "s/\(${1}=\).*/\1${VALUE}/" $F
Instrumental9c8a8b02018-07-16 18:41:10 -050096 fi
97 cat $F
98 done
99 ;;
100 encrypt)
101 cd /opt/app/osaaf/local || exit
102 echo $1
103 FILES=$(grep -l "$1" ./*.props)
104 if [ "$FILES" = "" ]; then
105 FILES=/opt/app/osaaf/local/org.osaaf.aaf.cred.props
106 ADD=Y
Instrumental4ad47632018-07-13 15:49:26 -0500107 fi
108 for F in $FILES; do
109 echo "Changing $1 in $F"
110 if [ "$2" = "" ]; then
111 read -r -p "Password (leave blank to cancel): " -s ORIG_PW
112 echo " "
113 if [ "$ORIG_PW" = "" ]; then
114 echo canceling...
115 break
116 fi
117 else
118 ORIG_PW="$2"
119 fi
120 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 -0500121 if [ "$ADD" = "Y" ]; then
122 echo "$1=enc:$PWD" >> $F
123 else
124 sed -i.backup -e "s/\\($1.*enc:\\).*/\\1$PWD/" $F
125 fi
Instrumental4ad47632018-07-13 15:49:26 -0500126 cat $F
127 done
128 ;;
Instrumental9c8a8b02018-07-16 18:41:10 -0500129 taillog)
130 sh /opt/app/osaaf/logs/taillog
131 ;;
Instrumental4ad47632018-07-13 15:49:26 -0500132 --help | -?)
133 case "$1" in
134 "")
135 echo "--- Agent Container Comands ---"
136 echo " ls - Lists all files in Configuration"
137 echo " cat <file.props>> - Shows the contents (Prop files only)"
138 echo " validate - Runs a test using Configuration"
Instrumental9c8a8b02018-07-16 18:41:10 -0500139 echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)"
Instrumental4ad47632018-07-13 15:49:26 -0500140 echo " encrypt <tag> [<pass>] - set passwords on Configuration (if no pass, it will be queried)"
141 echo " bash - run bash in Container"
142 echo " Note: the following aliases are preset"
143 echo " cadi - CADI CmdLine tool"
144 echo " agent - Agent Java tool (see above help)"
145 echo ""
146 echo " --help|-? [cadi|agent] - This help, cadi help or agent help"
147 ;;
148 cadi)
149 echo "--- cadi Tool Comands ---"
150 $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
151 ;;
152 agent)
153 echo "--- agent Tool Comands ---"
154 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/org.osaaf.aaf.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar
155 ;;
156 esac
157 echo ""
158 ;;
159 *)
160 $JAVA -Dcadi_prop_files=/opt/app/osaaf/local/org.osaaf.aaf.props -jar /opt/app/aaf_config/bin/aaf-cadi-aaf-*-full.jar "$CMD" "$@"
161 ;;
162 esac
163fi