-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
35 lines (27 loc) · 861 Bytes
/
docker-entrypoint.sh
File metadata and controls
35 lines (27 loc) · 861 Bytes
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
#!/bin/sh
set -e
KEY_FILE="/data/private.key"
LISTEN_PORT="${LISTEN_PORT:-1337}"
# Ensure runtime directory exists
mkdir -p "$XDG_RUNTIME_DIR"
# Generate identity if key doesn't exist
if [ ! -f "$KEY_FILE" ]; then
echo "Generating new identity..."
gratcli identity -g -k "$KEY_FILE"
fi
# Symlink to default path so gratcli works without -k
ln -sf "$KEY_FILE" /root/private.key
# Print our address
gratcli identity
# Resolve EXTERNAL_IP hostname to an IP address.
# gratserver's -e flag expects an IP (net.ParseIP), not a hostname.
RESOLVED_IP=""
if [ -n "$EXTERNAL_IP" ]; then
RESOLVED_IP=$(getent hosts "$EXTERNAL_IP" | awk '{print $1; exit}')
fi
if [ -z "$RESOLVED_IP" ]; then
RESOLVED_IP="::1"
fi
echo "Resolved external IP: $RESOLVED_IP"
# Start gratserver
exec gratserver -k /root/private.key -e "$RESOLVED_IP" -p "$LISTEN_PORT" -v