2020-07-04 04:24:24 +03:00
|
|
|
#! /usr/bin/env bash
|
2019-05-12 13:21:14 +03:00
|
|
|
|
|
|
|
generate_from_stdin() {
|
|
|
|
outfile=$1
|
|
|
|
language=$2
|
|
|
|
|
|
|
|
echo "Generating '$language' ..."
|
|
|
|
|
|
|
|
pandoc --metadata-file=epub-metadata.yaml --metadata=lang:$2 --from=markdown -o $1 <&0
|
|
|
|
|
|
|
|
echo "Done! You can find the '$language' book at ./$outfile"
|
|
|
|
}
|
|
|
|
|
|
|
|
generate_with_solutions () {
|
|
|
|
tmpfile=$(mktemp /tmp/sytem-design-primer-epub-generator.XXX)
|
|
|
|
|
|
|
|
cat ./README.md >> $tmpfile
|
|
|
|
|
|
|
|
for dir in ./solutions/system_design/*; do
|
|
|
|
case $dir in *template*) continue;; esac
|
|
|
|
case $dir in *__init__.py*) continue;; esac
|
|
|
|
: [[ -d "$dir" ]] && ( cd "$dir" && cat ./README.md >> $tmpfile && echo "" >> $tmpfile )
|
|
|
|
done
|
|
|
|
|
|
|
|
cat $tmpfile | generate_from_stdin 'README.epub' 'en'
|
|
|
|
|
|
|
|
rm "$tmpfile"
|
|
|
|
}
|
|
|
|
|
|
|
|
generate () {
|
|
|
|
name=$1
|
|
|
|
language=$2
|
|
|
|
|
|
|
|
cat $name.md | generate_from_stdin $name.epub $language
|
|
|
|
}
|
|
|
|
|
2020-12-19 19:52:54 +03:00
|
|
|
|
2020-07-04 04:24:24 +03:00
|
|
|
# Check if depencies exist
|
|
|
|
check_dependencies () {
|
2020-12-19 19:52:54 +03:00
|
|
|
ITER=-1
|
2020-07-04 04:24:24 +03:00
|
|
|
for dependency in "${dependencies[@]}"
|
|
|
|
do
|
2020-12-19 19:52:54 +03:00
|
|
|
ITER=$(expr $ITER + 1)
|
2020-07-04 04:24:24 +03:00
|
|
|
if ! [ -x "$(command -v $dependency)" ]; then
|
|
|
|
echo "Error: $dependency is not installed." >&2
|
|
|
|
exit 1
|
2020-12-19 19:52:54 +03:00
|
|
|
else
|
|
|
|
requiredver="${dependencies_minimun_version[ITER]}"
|
|
|
|
currentver=$($dependency --version | head -1 | cut -d " " -f 2)
|
|
|
|
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" != "$requiredver" ]; then
|
|
|
|
echo "$dependency verion must be >= ${requiredver}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-07-04 04:24:24 +03:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies=("pandoc")
|
2020-12-19 19:52:54 +03:00
|
|
|
dependencies_minimun_version=("2.3")
|
2020-07-04 04:24:24 +03:00
|
|
|
|
|
|
|
check_dependencies
|
2019-05-12 13:21:14 +03:00
|
|
|
generate_with_solutions
|
|
|
|
generate README-ja ja
|
|
|
|
generate README-zh-Hans zh-Hans
|
|
|
|
generate README-zh-TW zh-TW
|