Skip to content

Commit 3b47114

Browse files
authored
Merge pull request #22174 from sftim/20200629_capture_tidying_autodetect_repository_root
Autodetect content directory for capture cleanup tool
2 parents 23c27eb + 8384b2e commit 3b47114

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

scripts/replace-capture.sh

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
#!/bin/bash
22

33
# set K8S_WEBSITE in your env to your docs website root
4+
# or rely on this script to determine it automatically
5+
# You must run the script inside the repository for that to work
6+
#
47
# Note: website/content/<lang>/docs
5-
CONTENT_DIR=${K8S_WEBSITE}/content
8+
9+
find_content_dir() {
10+
local self
11+
local top
12+
if command git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
13+
self="$0"
14+
top="$(command git rev-parse --show-toplevel)"
15+
while ( cd "${top}/.." && command git rev-parse --is-inside-work-tree> /dev/null 2>&1 ); do
16+
top="$( cd "${top}/.." && "${self}" )"
17+
done
18+
printf "%s/content" "${top}"
19+
else
20+
printf "Could not autodetect CONTENT_DIR\n" 1>&2
21+
exit 1
22+
fi
23+
}
24+
25+
if [ -z ${K8S_WEBSITE+x} ]; then
26+
CONTENT_DIR="$( find_content_dir )"
27+
else
28+
CONTENT_DIR=${K8S_WEBSITE}/content
29+
fi
30+
31+
if ! [ -d "${CONTENT_DIR}" ]; then
32+
printf "Directory %s not found\n" "${CONTENT_DIR}" 1>&2
33+
exit 1
34+
fi
635

736
# 16 langs
837
# de en es fr hi id it ja ko no pl pt ru uk vi zh

0 commit comments

Comments
 (0)