-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint.sh
executable file
·57 lines (48 loc) · 2.06 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
set -e
# Defaults
ADMIN_USER=${ADMIN_USER:-admin}
MAIL_SERVER=${MAIL_SERVER:-smtp}
POSTGRES_HOST=${POSTGRES_HOST:-postgres}
POSTGRES_PORT=${POSTGRES_PORT:-5432}
POSTGRES_DB=${POSTGRES_DB:-pdns}
POSTGRES_USER=${POSTGRES_USER:-pdns}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-pdns}
PDNS_API_HOST=${PDNS_API_HOST:-172.17.0.1}
PDNS_API_PORT=${PDNS_API_PORT:-8081}
PDNS_API_KEY=${PDNS_API_KEY:-unset}
mkdir -p /data
sed -i -e "s/^mailhub=.*$/mailhub=${MAIL_SERVER}/" /etc/ssmtp/ssmtp.conf
if [ ! -f /data/config.ini ]; then
echo "Creating initial config file..."
cp /srv/dns-ui/config/config.ini.orig /data/config.ini
fi
ln -sf /data/config.ini /srv/dns-ui/config/
if grep -q '^; AUTOCONFIG_ENABLED=yes$' /data/config.ini; then
echo "Updating configuration..."
sed -e "s/^\(dsn\s*=\s*\"pgsql:host=\)[^;]\+\(;port=\)[^;]\+\(;dbname=\)[^;]\+\"$/\1${POSTGRES_HOST}\2${POSTGRES_PORT}\3${POSTGRES_DB}\"/" \
-e "s/^\(username\s*=\s*\"\).*\"$/\1${POSTGRES_USER}\"/" \
-e "s/^\(password\s*=\s*\"\).*\"$/\1${POSTGRES_PASSWORD}\"/" \
-e "s/^\(api_url\s*=\s*\"http:\/\/\).*\(\/api\/v1\/servers\/localhost\"\)$/\1${PDNS_API_HOST}:${PDNS_API_PORT}\2/" \
-e "s/^\(api_key\s*=\s*\"\).*\"$/\1${PDNS_API_KEY}\"/" \
-i /data/config.ini
else
echo "Auto config update disabled... skipping."
fi
if ! grep -q 'INSERT INTO "user"' /srv/dns-ui/migrations/002.php; then
echo "Adding initial user creation to db migrations..."
sed -i '/\}$/{e cat -'$'\n''}' /srv/dns-ui/migrations/002.php <<-EOF
\$this->database->prepare('
INSERT INTO "user" (uid, name, email, active, admin, auth_realm)
VALUES (?, ?, ?, ?, ?, ?)
')->execute(
array("${ADMIN_USER}", "Admin User", "[email protected]", 1, 1, "local")
);
EOF
fi
while ! nc -z "$POSTGRES_HOST" "$POSTGRES_PORT"; do
echo "Waiting for database..."
sleep 1
done
echo "Starting Caddy..."
exec /usr/bin/caddy --conf /etc/Caddyfile --log stdout