|
1 | 1 | #!/bin/bash |
2 | | -set +eux |
| 2 | +set +eu |
| 3 | + |
| 4 | +init_error() { |
| 5 | + echo "Container initialization failed at $(caller)." >&2 |
| 6 | +} |
| 7 | +trap init_error ERR |
3 | 8 |
|
4 | 9 | if [ -e /var/lib/mysql/mysql ]; then |
5 | 10 | echo -e "Database already exists. Reuse it." |
@@ -27,24 +32,34 @@ if [ "$(sysctl -n crypto.fips_enabled)" == "1" ]; then |
27 | 32 | else |
28 | 33 | SSL_CIPHER='AES128-SHA256' |
29 | 34 | fi |
| 35 | +export SSL_CIPHER |
30 | 36 |
|
31 | 37 | PODNAME=$(hostname -f | cut -d. -f1,2) |
32 | 38 | PODIPV4=$(grep "${PODNAME}" /etc/hosts | grep -v ':' | cut -d$'\t' -f1) |
33 | 39 | PODIPV6=$(grep "${PODNAME}" /etc/hosts | grep ':' | cut -d$'\t' -f1) |
| 40 | +if [[ "" = "${PODIPV6}" ]]; then |
| 41 | + PODIP="${PODIPV4}" |
| 42 | + IPSTACK="IPV4" |
| 43 | +else |
| 44 | + PODIP="[::]" |
| 45 | + IPSTACK="IPV6" |
| 46 | +fi |
| 47 | +export PODNAME PODIP |
| 48 | + |
| 49 | +# mariabackup: default credentials if no configuration was provided |
| 50 | +: ${MARIABACKUP_USER=root} |
| 51 | +: ${MARIABACKUP_PASSWORD=$DB_ROOT_PASSWORD} |
| 52 | +export MARIABACKUP_USER MARIABACKUP_PASSWORD |
34 | 53 |
|
35 | 54 | cd /var/lib/config-data/default |
36 | 55 | for cfg in *.cnf.in; do |
37 | 56 | if [ -s "${cfg}" ]; then |
38 | | - |
39 | | - if [[ "" = "${PODIPV6}" ]]; then |
40 | | - PODIP="${PODIPV4}" |
41 | | - IPSTACK="IPV4" |
42 | | - else |
43 | | - PODIP="[::]" |
44 | | - IPSTACK="IPV6" |
45 | | - fi |
46 | | - |
47 | 57 | echo "Generating config file from template ${cfg}, will use ${IPSTACK} listen address of ${PODIP}" |
48 | | - sed -e "s/{ PODNAME }/${PODNAME}/" -e "s/{ PODIP }/${PODIP}/" -e "s/{ SSL_CIPHER }/${SSL_CIPHER}/" "/var/lib/config-data/default/${cfg}" > "/var/lib/config-data/generated/${cfg%.in}" |
| 58 | + # replace all occurrences of "{ xxx }" with their value from environment |
| 59 | + awk '{ |
| 60 | +patsplit($0,markers,/{ (PODNAME|PODIP|SSL_CIPHER|MARIABACKUP_USER|MARIABACKUP_PASSWORD) }/); |
| 61 | +for(i in markers){ m=markers[i]; gsub(/\W/,"",m); gsub(markers[i], ENVIRON[m])}; |
| 62 | +print $0 |
| 63 | +}' "/var/lib/config-data/default/${cfg}" > "/var/lib/config-data/generated/${cfg%.in}" |
49 | 64 | fi |
50 | 65 | done |
0 commit comments