#!/bin/sh
set -euo pipefail

# Ensure the ctf user exists (defensive in case the base image changes)
if ! id ctf >/dev/null 2>&1; then
  useradd -m -u 1001 ctf
fi

# Ensure the history directory exists and has correct ownership
mkdir -p /app/history
chown -R ctf:ctf /app/history

# Run the grob service as ctf user
exec runuser -u ctf -- /app/grob
