#!/usr/bin/with-contenv bash

# Create required folders
mkdir -p /tmp/nginx/body \
	/run/nginx \
	/var/log/nginx \
	/var/lib/nginx/cache/public \
	/var/lib/nginx/cache/private \
	/var/cache/nginx/proxy_temp \
	/data/logs

touch /var/log/nginx/error.log && chmod 777 /var/log/nginx/error.log && chmod -R 777 /var/cache/nginx

# Dynamically generate resolvers file
echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)" ";" > /etc/nginx/conf.d/include/resolvers.conf

# Fire off acme.sh wrapper script to "install" itself if required
acme.sh -h > /dev/null 2>&1