2017-04-26 22:35:49 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
## Generate keys if they do not exist
|
|
|
|
if [[ ! -f /opt/postal/config/signing.key ]]; then
|
2017-04-27 10:29:03 +02:00
|
|
|
/opt/postal/bin/postal initialize-config
|
2017-04-26 22:35:49 +02:00
|
|
|
fi
|
|
|
|
|
2017-04-27 09:50:07 +02:00
|
|
|
## Set Hostname
|
|
|
|
sed -i "s/postal\.example\.com/$POSTAL_HOSTNAME/" /opt/postal/config/postal.yml
|
|
|
|
|
2017-04-27 10:38:29 +02:00
|
|
|
## Set MySQL/RabbitMQ usernames/passwords
|
2017-04-27 09:50:07 +02:00
|
|
|
### MySQL Main DB
|
|
|
|
sed -i -e '/main_db:/!b' -e ':a' -e "s/host.*/host: mysql/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
|
|
|
sed -i -e'/main_db:/!b' -e ':a' -e "s/username.*/username: root/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
2017-04-27 10:29:03 +02:00
|
|
|
sed -i -e'/main_db:/!b' -e ':a' -e "s/password.*/password: $MYSQL_ROOT_PASSWORD/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
|
|
|
sed -i -e'/main_db:/!b' -e ':a' -e "s/database.*/database: $MYSQL_DATABASE/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
2017-04-27 09:50:07 +02:00
|
|
|
### MySQL Message DB
|
|
|
|
sed -i -e '/message_db:/!b' -e ':a' -e "s/host.*/host: mysql/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
|
|
|
sed -i -e'/message_db:/!b' -e ':a' -e "s/username.*/username: root/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
2017-04-27 10:29:03 +02:00
|
|
|
sed -i -e'/message_db:/!b' -e ':a' -e "s/password.*/password: $MYSQL_ROOT_PASSWORD/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
2017-04-27 09:50:07 +02:00
|
|
|
### RabbitMQ
|
|
|
|
sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/host.*/host: rabbitmq/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
2017-04-27 10:29:03 +02:00
|
|
|
sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/username.*/username: $RABBITMQ_DEFAULT_USER/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
|
|
|
sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/password.*/password: $RABBITMQ_DEFAULT_PASS/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
|
|
|
sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/vhost.*/vhost: \/$RABBITMQ_DEFAULT_VHOST/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml
|
2017-04-26 22:35:49 +02:00
|
|
|
|
2017-04-27 10:29:03 +02:00
|
|
|
### Initialize DB
|
|
|
|
if [[ ! -f /opt/postal/docker/postal_initialized ]]; then
|
|
|
|
/opt/postal/bin/postal initialize && touch /opt/postal/docker/postal_initialized
|
2017-04-27 10:38:29 +02:00
|
|
|
else
|
|
|
|
/opt/postal/bin/postal upgrade
|
2017-04-27 10:29:03 +02:00
|
|
|
fi
|
|
|
|
|
2017-04-26 22:35:49 +02:00
|
|
|
## Run
|
2017-04-27 10:29:03 +02:00
|
|
|
/opt/postal/bin/postal run
|