#!/bin/sh
set -e

# If LAB_LINKS is not set, use an empty array
LAB_LINKS_JSON=${LAB_LINKS:-[]}

# Escape / and & for sed
ESCAPED_JSON=$(printf '%s' "$LAB_LINKS_JSON" | sed -e 's/[\/&]/\\&/g')

# Replace placeholder in index.html
sed "s/__LAB_LINKS__/$ESCAPED_JSON/" /usr/share/nginx/html/index.html > /tmp/index.html
mv /tmp/index.html /usr/share/nginx/html/index.html

# Run nginx
exec nginx -g 'daemon off;'
