#!/bin/sh -e

os=$(cat "$__global/explorer/os")

case "$os" in
    devuan)
        :
    ;;
    *)
        echo "OS $os currently not supported" >&2
        exit 1
    ;;
esac

nginx_config_dir="/etc/nginx/conf.d"
domain="$__object_id"

__directory /var/www/html/$domain \
            --parents --mode 0755

require="__directory//var/www/html/$domain" \
	__file /var/www/html/$domain/index.html \
	--mode 0644 --source - << EOF
Hello Cdist!!!
EOF

__my_nginx

# configure nginx
require="__my_nginx" \
        __file "$nginx_config_dir/${domain}.conf" \
        --mode 0644 --source - << EOF
server {
        listen 80;
        listen [::]:80;

        server_name $domain;

        access_log  /var/log/nginx/access.log;

        client_max_body_size 256m;

        location / {
                root   /var/www/html/$domain;
                index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {
                root   /var/www/html/$domain;
        }
}
EOF
