Damien Martin-Guillerez | 49a3e4b | 2017-11-03 15:30:52 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | HOST="${HOST-localhost}" |
| 3 | PORT="${PORT-12345}" |
| 4 | RUNFILES=$(cd ${JAVA_RUNFILES-$0.runfiles}/%{workspace_name} && pwd -P) |
| 5 | SOURCE_DIR="$RUNFILES/%{source_dir}" |
| 6 | prod_dir="$RUNFILES/%{prod_dir}" |
| 7 | bucket="%{bucket}" |
| 8 | |
| 9 | function 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 | |
| 17 | function 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 | |
| 37 | case "${1-}" in |
| 38 | --push) |
| 39 | push |
| 40 | ;; |
| 41 | --serve|"") |
| 42 | serve |
| 43 | ;; |
| 44 | *) |
| 45 | echo "Usage: $0 [--push|--serve]" >&2 |
| 46 | exit 1 |
| 47 | ;; |
| 48 | esac |