noredink-ui/script/serve.sh
2020-03-06 20:00:34 +01:00

27 lines
469 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
TARGET="${1:-}"
if test -z "$TARGET"; then
echo "USAGE: ${0:-} directory-to-serve"
exit 1
fi
if ! test -d "$TARGET"; then
echo 'cannot serve a non-directory, exiting!'
exit 1
fi
if ! which python > /dev/null; then
echo 'need a python installed, exiting!'
exit 1
fi
cd "$TARGET"
if python --version | grep -qE '^Python 3'; then
exec python -m http.server
else
exec python -m SimpleHTTPServer
fi