1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #!/usr/bin/env bash
- set -e
- function log_to_dockerout {
- cd /var/log/firebird
- while true
- do
- for i in $(ls *.log)
- do
- if [ -z "$(pgrep -f ${i})" ] ; then
- echo Processing ${i} > /var/log/dockerout
- tail -f /var/log/firebird/$i 2> /dev/null | while read fread; do echo "[${i}]: ${fread}" >> /var/log/dockerout; :> /var/log/firebird/$i; done &
- fi
- done
- sleep 10
- done
- }
- function sec_init
- {
- cat <<EOF | isql-fb security.db
- create or alter user SYSDBA password '$_SYSDBA_PWD' using plugin Srp;
- create or alter user SYSDBA password '$_SYSDBA_PWD' using plugin Legacy_UserManager;
- commit;
- quit;
- EOF
- if [ -f /run/secrets/FB3_USER_NAME ] && [ -f /run/secrets/FB3_USER_PWD ]; then
- echo "Setting up Firebird user $(cat /run/secrets/FB3_USER_NAME) with 'grant create database'"
- cat <<EOF | isql-fb security.db
- create or alter user $(cat /run/secrets/FB3_USER_NAME) password '$(cat /run/secrets/FB3_USER_PWD)' using plugin Srp;
- create or alter user $(cat /run/secrets/FB3_USER_NAME) password '$(cat /run/secrets/FB3_USER_PWD)' using plugin Legacy_UserManager;
- grant create database to user $(cat /run/secrets/FB3_USER_NAME);
- commit;
- quit;
- EOF
- fi
- }
- function checkbase_init
- {
- mktemp > /etc/firebird/check-database.conf
- rm -f $(cat /etc/firebird/check-database.conf)
- isql-fb << EOF
- CREATE DATABASE "$(cat /etc/firebird/check-database.conf)";
- EOF
- }
- if [ ! -f /run/secrets/FB3_SYSDBA_PWD ]; then
- mkdir -p /run/secrets
- echo $RANDOM$RANDOM > /run/secrets/FB3_SYSDBA_PWD
- echo "Setting SYSDBA's random password: "$( cat /run/secrets/FB3_SYSDBA_PWD )
- fi
- _SYSDBA_PWD=$(cat /run/secrets/FB3_SYSDBA_PWD)
- sec_init
- checkbase_init
- mkfifo /var/log/dockerout
- tail -f /var/log/dockerout &
- log_to_dockerout &
- exec "$@"
|