diff options
author | hlopko <hlopko@google.com> | 2017-05-30 16:51:44 +0200 |
---|---|---|
committer | László Csomor <laszlocsomor@google.com> | 2017-05-31 09:18:18 +0200 |
commit | a1fb6f26cfeaa712f447e5d41d2a98565e9ab478 (patch) | |
tree | 624570f398561cad7b985cd8522549fcc9299a70 /scripts/serve-docs.sh | |
parent | 166f28cd620f9fc9c4694242916a7fe1a9a998da (diff) |
Fix scripts/serve-docs.sh
RELNOTES: None.
PiperOrigin-RevId: 157463020
Diffstat (limited to 'scripts/serve-docs.sh')
-rwxr-xr-x | scripts/serve-docs.sh | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/scripts/serve-docs.sh b/scripts/serve-docs.sh index 27d157731f..edbe41384d 100755 --- a/scripts/serve-docs.sh +++ b/scripts/serve-docs.sh @@ -15,6 +15,12 @@ set -eu +readonly WORKING_DIR=$(mktemp -d) +HOST=localhost +PORT=12345 +TARGET= +SERVING_PREFIX= + usage() { cat <<EOF Usage: $0 [--port 12345] [--target DIR [PREFIX]] [--share] @@ -33,45 +39,6 @@ Usage: $0 [--port 12345] [--target DIR [PREFIX]] [--share] EOF } -HOST=localhost -PORT=12345 -TARGET= -SERVING_PREFIX= -while [[ $# -gt 0 ]] -do - key="$1" - case $key in - --port) - PORT="$2" - shift - ;; - --share) - HOST="$HOSTNAME" - ;; - --target) - TARGET="$2" - shift - SERVING_PREFIX="${2:-}" - build_static - exit 0 - ;; - --help|help) - usage - exit 0 - ;; - *) - usage - exit 1 - esac - shift -done - -readonly WORKING_DIR=$(mktemp -d) - -check() { - which $1 > /dev/null || (echo "$1 not installed. Please install $1."; exit 1) -} - build_tree() { bazel build //site:jekyll-tree.tar rm -rf $WORKING_DIR/* @@ -96,6 +63,20 @@ build_and_serve() { jekyll serve --host "$HOST" --detach --quiet --port "$PORT" --source "$WORKING_DIR" } +check() { + which $1 > /dev/null || (echo "$1 not installed. Please install $1."; exit 1) +} + +kill_jekyll() { + pid="$(lsof "-tiTCP:$PORT" -sTCP:LISTEN)" || true + if [ ! -z "$pid" ]; then + kill "$pid" + fi + # I found I got bind errors sometimes if I didn't wait a second for the server to + # actually shut down. + sleep 2 +} + main() { check jekyll @@ -125,15 +106,34 @@ main() { done } -kill_jekyll() { - pid="$(lsof "-tiTCP:$PORT" -sTCP:LISTEN)" || true - if [ ! -z "$pid" ]; then - kill "$pid" - fi - # I found I got bind errors sometimes if I didn't wait a second for the server to - # actually shut down. - sleep 2 -} +while [[ $# -gt 0 ]] +do + key="$1" + case $key in + --port) + PORT="$2" + shift + ;; + --share) + HOST="$HOSTNAME" + ;; + --target) + TARGET="$2" + shift + SERVING_PREFIX="${2:-}" + build_static + exit 0 + ;; + --help|help) + usage + exit 0 + ;; + *) + usage + exit 1 + esac + shift +done cleanup() { rm -rf $WORKING_DIR |