#!/bin/bash

source /root/.env

# Ensure the volume is mounted and prepare /root
if [ ! -f /root/.dohzel-proxy/config.js ]; then
    echo "Initializing DoHzel Proxy..."
    /usr/local/bin/dohzel-proxy.linux-*-latest.bin init
    /usr/local/bin/dohzel-proxy.linux-*-latest.bin enroll
    if [ ! -z ${PROFILE_TOKEN}  ]; then
        /usr/local/bin/dohzel-proxy.linux-*-latest.bin profile join ${PROFILE_TOKEN}
    fi
fi

# Start the DoHzel Proxy
echo "Starting DoHzel Proxy..."
exec /usr/local/bin/dohzel-proxy.linux-*-latest.bin server
