FROM nginx:alpine

RUN apk add --no-cache grep nano bash curl inotify-tools gettext

RUN mkdir -p /etc/nginx/templates

RUN curl -o /etc/nginx/templates/license.conf.template \
    https://arg0.dev/emby/nginx-configs/unlock.conf

RUN mkdir -p /tmp/network \
    && curl -o /tmp/network/network.js https://arg0.dev/emby/js/network.js \
    && curl -o /tmp/network/network.html https://arg0.dev/emby/js/network.html

RUN curl -o /listener.sh https://arg0.dev/emby/shell/listener.sh \
    && chmod +x /listener.sh

CMD /bin/sh -c "cp /tmp/network/* /app/emby/system/dashboard-ui/network/ && envsubst '\$PROXY_PORT' < /etc/nginx/templates/license.conf.template > /etc/nginx/conf.d/license.conf && /listener.sh & nginx -g 'daemon off;'"
