blob: 0528794920007163ccf3c0bf3d39ed8589931eb0 [file] [log] [blame]
Damien Martin-Guillerez49a3e4b2017-11-03 15:30:52 +01001#!/bin/sh
2HOST="${HOST-localhost}"
3PORT="${PORT-12345}"
4RUNFILES=$(cd ${JAVA_RUNFILES-$0.runfiles}/%{workspace_name} && pwd -P)
5SOURCE_DIR="$RUNFILES/%{source_dir}"
6prod_dir="$RUNFILES/%{prod_dir}"
7bucket="%{bucket}"
8
9function serve() {
10 TDIR=$(mktemp -d)
11 RDIR=$(mktemp -d)
12 trap "rm -fr $RDIR $TDIR" EXIT
13 (cd $RDIR && \
14 jekyll serve --host "$HOST" --port "$PORT" -s "$SOURCE_DIR" -d "$TDIR")
15}
16
17function push() {
18 # Get gsutil
19 gs="${GSUTIL:-$(which gsutil 2>/dev/null || : )}"
20 if [ ! -x "${gs}" ]; then
21 echo "Please set GSUTIL to the path the gsutil binary." >&2
22 echo "gsutil (https://cloud.google.com/storage/docs/gsutil/) is the" >&2
23 echo "command-line interface to google cloud." >&2
24 exit 1
25 fi
26
27 # Rsync:
28 # -r: recursive
29 # -c: compute checksum even though the input is from the filesystem
30 # -d: remove deleted files
31 cd "${prod_dir}"
32 "${gs}" -m rsync -r -c -d . "gs://${bucket}"
33 "${gs}" web set -m index.html -e 404.html "gs://${bucket}"
34 "${gs}" -m acl ch -R -u AllUsers:R "gs://${bucket}"
35}
36
37case "${1-}" in
38 --push)
39 push
40 ;;
41 --serve|"")
42 serve
43 ;;
44 *)
45 echo "Usage: $0 [--push|--serve]" >&2
46 exit 1
47 ;;
48esac