Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 2 | # 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 | # |
| 5 | JAVA=/usr/bin/java |
| 6 | |
| 7 | # Only load Identities once |
| 8 | if [ ! -e /opt/app/osaaf/data/identities.dat ]; then |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 9 | mkdir -p /opt/app/osaaf/data |
| 10 | cp /opt/app/aaf_config/data/sample.identities.dat /opt/app/osaaf/data/identities.dat |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 11 | fi |
| 12 | |
| 13 | # Only initialize once, automatically... |
| 14 | if [ ! -e /opt/app/osaaf/local/org.osaaf.aaf.props ]; then |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 15 | 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 |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 19 | |
| 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 \ |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 28 | cadi_etc_dir=/opt/app/osaaf/local \ |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 29 | 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 |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 34 | fi |
Instrumental | 9ec2895 | 2018-07-12 11:14:10 -0500 | [diff] [blame] | 35 | |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 36 | # Now run a command |
| 37 | CMD=$2 |
| 38 | if [ ! "$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 | ;; |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 82 | setProp) |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 83 | cd /opt/app/osaaf/local || exit |
| 84 | FILES=$(grep -l "$1" ./*.props) |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 85 | 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 |
Instrumental | aeb80c8 | 2018-08-21 10:24:08 -0500 | [diff] [blame] | 92 | echo "$1=$2" >> $F |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 93 | else |
Instrumental | aeb80c8 | 2018-08-21 10:24:08 -0500 | [diff] [blame] | 94 | VALUE=${2//\//\\\/} |
Instrumental | 08a5c43 | 2018-09-06 12:07:06 -0500 | [diff] [blame^] | 95 | sed -i.backup -e "s/\(${1}=\).*/\1\"${VALUE}\"/" $F |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 96 | 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 |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 107 | 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) |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 121 | 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 |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 126 | cat $F |
| 127 | done |
| 128 | ;; |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 129 | taillog) |
| 130 | sh /opt/app/osaaf/logs/taillog |
| 131 | ;; |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 132 | --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" |
Instrumental | 9c8a8b0 | 2018-07-16 18:41:10 -0500 | [diff] [blame] | 139 | echo " setProp <tag> [<value>] - set value on 'tag' (if no value, it will be queried from config)" |
Instrumental | 4ad4763 | 2018-07-13 15:49:26 -0500 | [diff] [blame] | 140 | 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 |
| 163 | fi |