aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/docs/jekyll_build.sh.tpl
blob: 0528794920007163ccf3c0bf3d39ed8589931eb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
HOST="${HOST-localhost}"
PORT="${PORT-12345}"
RUNFILES=$(cd ${JAVA_RUNFILES-$0.runfiles}/%{workspace_name} && pwd -P)
SOURCE_DIR="$RUNFILES/%{source_dir}"
prod_dir="$RUNFILES/%{prod_dir}"
bucket="%{bucket}"

function serve() {
  TDIR=$(mktemp -d)
  RDIR=$(mktemp -d)
  trap "rm -fr $RDIR $TDIR" EXIT
  (cd $RDIR && \
    jekyll serve --host "$HOST" --port "$PORT" -s "$SOURCE_DIR" -d "$TDIR")
}

function push() {
  # Get gsutil
  gs="${GSUTIL:-$(which gsutil 2>/dev/null || : )}"
  if [ ! -x "${gs}" ]; then
    echo "Please set GSUTIL to the path the gsutil binary." >&2
    echo "gsutil (https://cloud.google.com/storage/docs/gsutil/) is the" >&2
    echo "command-line interface to google cloud." >&2
    exit 1
  fi

  # Rsync:
  #   -r: recursive
  #   -c: compute checksum even though the input is from the filesystem
  #   -d: remove deleted files
  cd "${prod_dir}"
  "${gs}" -m rsync -r -c -d . "gs://${bucket}"
  "${gs}" web set -m index.html -e 404.html "gs://${bucket}"
  "${gs}" -m acl ch -R -u AllUsers:R "gs://${bucket}"
}

case "${1-}" in
  --push)
    push
    ;;
  --serve|"")
    serve
    ;;
  *)
    echo "Usage: $0 [--push|--serve]" >&2
    exit 1
    ;;
esac