Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | . ./d.props |
| 3 | |
Instrumental | ab50267 | 2018-08-20 14:31:35 -0500 | [diff] [blame] | 4 | function run_it() { |
| 5 | docker run $@ \ |
Instrumental | 32cdd55 | 2018-07-19 13:29:32 -0500 | [diff] [blame] | 6 | --mount 'type=volume,src=aaf_config,dst='$CONF_ROOT_DIR',volume-driver=local' \ |
| 7 | --add-host="$HOSTNAME:$HOST_IP" \ |
| 8 | --add-host="aaf.osaaf.org:$HOST_IP" \ |
| 9 | --env AAF_ENV=${AAF_ENV} \ |
| 10 | --env AAF_REGISTER_AS=${AAF_REGISTER_AS} \ |
| 11 | --env LATITUDE=${LATITUDE} \ |
| 12 | --env LONGITUDE=${LONGITUDE} \ |
| 13 | --name aaf_config_$USER \ |
Instrumental | e44d2f7 | 2018-08-16 17:22:45 -0500 | [diff] [blame] | 14 | $PREFIX${ORG}/${PROJECT}/aaf_config:${VERSION} \ |
Instrumental | ab50267 | 2018-08-20 14:31:35 -0500 | [diff] [blame] | 15 | /bin/bash $PARAMS |
| 16 | } |
| 17 | |
| 18 | function encrypt_it() { |
| 19 | docker exec -t aaf_config_$USER /bin/bash /opt/app/aaf_config/bin/agent.sh NOOP encrypt "$1" "$2" |
| 20 | } |
| 21 | |
| 22 | P12_LOAD="no" |
| 23 | |
| 24 | for PROP in AAF_INITIAL_X509_P12 AAF_INITIAL_X509_PASSWORD AAF_SIGNER_P12 AAF_SIGNER_PASSWORD; do |
| 25 | if [ "${!PROP}" != "" ]; then |
| 26 | P12_LOAD='yes' |
| 27 | break; |
| 28 | fi |
| 29 | done |
| 30 | |
| 31 | # First Time Run does a bit more setup |
| 32 | if [ "$(docker volume ls | grep aaf_config)" = "" ] && [ ${P12_LOAD} = "yes" ]; then |
| 33 | echo "Initializing first aaf_config" |
| 34 | if [ "$(docker container ls | grep aaf_config_$USER)" = "" ]; then |
| 35 | PARAMS="bash" |
| 36 | run_it -t -d |
| 37 | else |
| 38 | echo "aaf_config_$USER is already running" |
| 39 | fi |
| 40 | docker container cp ${AAF_INITIAL_X509_P12} aaf_config_$USER:/opt/app/osaaf/local/org.osaaf.aaf.p12 |
| 41 | docker container cp ${AAF_SIGNER_P12} aaf_config_$USER:/opt/app/osaaf/local/org.osaaf.aaf.signer.p12 |
| 42 | |
| 43 | encrypt_it cadi_keystore_password "${AAF_INITIAL_X509_PASSWORD}" |
| 44 | encrypt_it cm_ca.local "${AAF_SIGNER_PASSWORD}" |
| 45 | |
| 46 | echo -n "Stopping " |
| 47 | docker container stop aaf_config_$USER |
| 48 | echo -n "Removing " |
| 49 | docker container rm aaf_config_$USER |
| 50 | fi |
| 51 | |
| 52 | PARAMS="$@" |
| 53 | if [ "$PARAMS" != "" ]; then |
| 54 | run_it -it --rm |
| 55 | fi |
| 56 | |