12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/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 /secrets/FB3_USER_NAME ] && [ -f /secrets/FB3_USER_PWD ]; then
- echo "Setting up Firebird user $(cat /secrets/FB3_USER_NAME) with 'grant create database'"
- cat <<EOF | isql-fb security.db
- create or alter user $(cat /secrets/FB3_USER_NAME) password '$(cat /secrets/FB3_USER_PWD)' using plugin Srp;
- create or alter user $(cat /secrets/FB3_USER_NAME) password '$(cat /secrets/FB3_USER_PWD)' using plugin Legacy_UserManager;
- grant create database to user $(cat /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 /secrets/FB3_SYSDBA_PWD ]; then
- mkdir -p /secrets
- echo $RANDOM$RANDOM > /secrets/FB3_SYSDBA_PWD
- echo "Setting SYSDBA's random password: "$( cat /secrets/FB3_SYSDBA_PWD )
- fi
- _SYSDBA_PWD=$(cat /secrets/FB3_SYSDBA_PWD)
- # Вынос security3.fdb на ПМЖ
- [[ ${EXT_SECURITY} && ${EXT_SECURITY}="true" ]] && \
- { [ ! -d /data/security3.fdb ] && cp /var/lib/firebird/secdb/security3.fdb /data/security3.fdb; }
- # Создаем символические ссылки на конфигурационные файлы
- for i in $(ls -d /configs/*.conf); do ln -sf ${i} /etc/firebird/;done
- [ -f /secrets/cluster.conf ] && ln -sf /secrets/cluster.conf /usr/lib64/firebird/plugins/
- sec_init
- checkbase_init
- mkfifo /var/log/dockerout
- tail -f /var/log/dockerout &
- log_to_dockerout &
- exec "$@"
|