#!/bin/sh -e
# SPDX-License-Identifier: WTFPL
# shellcheck enable=

die () {
	ex=$1
	shift
    printf "%s\n" "$*" >&2
    exit "$ex"
}

[ $# -le 1 ] || die 64 "usage: $0 [DIR]"
[ "${1-}" != -h ] || die 0 "usage: $0 [DIR]"

dir="${1-.}"
[ -d "$dir" ] || die 1 "error: $dir is not a directory"

cd "$dir"

rm -f index.html

trap 'kill $!' EXIT INT
python3 -m http.server --bind localhost 8000 &
sleep 1
curl http://localhost:8000 -o index.html
