noredink-ui/script/serve.sh

27 lines
469 B
Bash
Raw Normal View History

2019-04-01 21:15:02 +03:00
#!/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
2019-04-02 23:26:36 +03:00
exec python -m http.server
2019-04-01 21:15:02 +03:00
else
2019-04-02 23:26:36 +03:00
exec python -m SimpleHTTPServer
2019-04-01 21:15:02 +03:00
fi