This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
build-jekyll-tree.sh
executable file
·65 lines (55 loc) · 1.7 KB
/
build-jekyll-tree.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Copyright 2016 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Workaround to rename bazel_release.pub.gpg to bazel-release.pub.gpg in order
# to not break links.
set -eu
readonly OUTPUT=${PWD}/$1
readonly JEKYLL_BASE=${PWD}/$2
readonly REDIRECTS_FILE=${3:-""}
readonly OWD=${PWD}
# Create temporary directory that is removed when this script exits.
readonly TMP=$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXX")
readonly OUT_DIR="$TMP/out"
trap "rm -rf ${TMP}" EXIT
function main {
mkdir -p "$OUT_DIR"
cd "$OUT_DIR"
tar -xf "${JEKYLL_BASE}"
if [[ -n "$REDIRECTS_FILE" ]]; then
local redirects_path="${OWD}/${REDIRECTS_FILE}"
while IFS=$'\t' read old new; do
if [[ -e "$old" ]]; then
echo "Cannot create redirect file $old. File exists."
exit 1
fi
local old_dir=$(dirname $old)
if [[ ! -d "$old_dir" ]]; then
mkdir -p "$old_dir"
fi
cat <<EOF > $old
<html>
<head>
<script>
window.location.replace("${new}" + window.location.hash);
</script>
</head>
</html>
EOF
done < "$redirects_path"
fi
mv bazel_release.pub.gpg bazel-release.pub.gpg
tar -hcf $OUTPUT $(find . -type f | sort)
}
main