BOSL2/scripts/make_tutorials.sh
Michael Diamond 0666f6482c Refactor and tidy BOSL's shell scripts
* Fixed ShellCheck.net warnings, including
  * exit -1: https://github.com/koalaman/shellcheck/wiki/SC2242
  * cd || exit: https://github.com/koalaman/shellcheck/wiki/SC2164
  * "$foo": https://github.com/koalaman/shellcheck/wiki/SC2086
  * $(( $foo )): https://github.com/koalaman/shellcheck/wiki/SC2004
  * grep | wc -l: https://github.com/koalaman/shellcheck/wiki/SC2126
* Use arrays instead of unquoted strings for loops and command arguments
* Use (( ... )) arithmetic context instead of string comparisons
* Use bash's built-in regex support instead of grep+sed+awk
* Write errors to stderr
2021-05-21 01:01:15 -07:00

39 lines
1 KiB
Bash
Executable file

#!/bin/bash
DISPMD=0
GEN_ARGS=()
FILES=()
for opt in "$@" ; do
case "$opt" in
-f ) GEN_ARGS+=(-f) ;;
-d ) DISPMD=1 ;;
-* ) echo "Unknown option $opt" >&2; exit 1 ;;
* ) FILES+=("$opt") ;;
esac
done
if (( ${#FILES[@]} == 0 )); then
FILES=(Shapes2d Shapes3d Transforms Distributors Mutators Attachments Paths FractalTree)
fi
# Try to cd to the BOSL2.wiki directory if run from the BOSL2 root
if [[ "$(basename "$PWD")" != "BOSL2.wiki" ]]; then
if ! cd BOSL2.wiki; then
echo "BOSL2.wiki directory not found, try running from the BOSL2 or BOSL2/BOSL2.wiki directory" >&2
exit 1
fi
fi
rm -f tmp_*.scad
for base in "${FILES[@]}"; do
base="$(basename "$base" .md)"
mkdir -p images/tutorials
rm -f "images/tutorials/${base}"_*.png "images/tutorials/${base}"_*.gif
echo "${base}.md"
../scripts/tutorial_gen.py "../tutorials/${base}.md" -o "Tutorial-${base}.md" "${GEN_ARGS[@]}" -I images/tutorials/ || exit 1
if (( DISPMD )); then
open -a Typora "Tutorial-${base}.md"
fi
done