2021-11-23 22:48:06 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# vim: set ft=sh:
|
|
|
|
|
2021-12-23 21:42:53 +00:00
|
|
|
# Set defaults
|
|
|
|
BASEDIR="$(pwd)"
|
2021-12-21 15:39:51 +00:00
|
|
|
ACTION="watch"
|
2022-01-26 16:03:07 +00:00
|
|
|
VERBOSITY="0"
|
2021-11-23 22:48:06 +00:00
|
|
|
DOCKER_IMAGE=glenux/teaching-boilerplate:latest
|
2021-12-21 15:39:51 +00:00
|
|
|
DOCKER_OPT_TTY="-t"
|
|
|
|
|
2022-01-26 16:03:07 +00:00
|
|
|
gxt_usage() {
|
|
|
|
echo "Usage: $0 [options]"
|
|
|
|
echo ""
|
|
|
|
echo "-d, --data-dir DIR Content directory"
|
|
|
|
echo "-a, --action ACTION Action (watch, build, shell, etc.)"
|
|
|
|
echo "-t, --tty Enable TTY mode (needed for shell)"
|
|
|
|
echo "-v, --verbose Enable verbosity"
|
|
|
|
echo "-h, --help Show this help"
|
|
|
|
}
|
|
|
|
|
2021-12-21 15:39:51 +00:00
|
|
|
# Parse arguments
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
ARG="${1:-}"
|
|
|
|
OPT="${2:-}"
|
|
|
|
shift
|
|
|
|
|
2021-12-21 15:55:46 +00:00
|
|
|
# echo "DEBUG: ARG=$ARG OPT=$OPT"
|
2021-12-21 15:39:51 +00:00
|
|
|
|
|
|
|
case "$ARG" in
|
2022-01-26 16:03:07 +00:00
|
|
|
-a|--action)
|
|
|
|
shift # argument requires a parameter
|
|
|
|
if [ -z "$OPT" ]; then
|
|
|
|
>&2 echo "ERROR: missing argument for --action"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ACTION="$OPT"
|
|
|
|
;;
|
2021-12-21 15:39:51 +00:00
|
|
|
-d|--data-dir)
|
|
|
|
shift # argument requires a parameter
|
|
|
|
if [ -z "$OPT" ]; then
|
|
|
|
>&2 echo "ERROR: missing argument for --data-dir"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! -d "$OPT" ]; then
|
|
|
|
>&2 echo "ERROR: argument for --data-dir must be a directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
BASEDIR="$(cd "$OPT" && pwd)"
|
|
|
|
;;
|
2022-01-26 16:03:07 +00:00
|
|
|
-h|--help)
|
|
|
|
>&2 gxt_usage
|
|
|
|
exit 0
|
2021-12-21 15:39:51 +00:00
|
|
|
;;
|
|
|
|
-T|--no-tty)
|
|
|
|
DOCKER_OPT_TTY=""
|
|
|
|
;;
|
2022-01-26 16:03:07 +00:00
|
|
|
-v|--verbosity)
|
|
|
|
VERBOSITY="$((VERBOSITY+1))"
|
2021-12-21 15:39:51 +00:00
|
|
|
;;
|
|
|
|
*)
|
2022-01-26 16:03:07 +00:00
|
|
|
>&2 gxt_usage
|
2021-12-21 15:39:51 +00:00
|
|
|
>&2 echo "ERROR: unknown option '$ARG'"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2021-11-23 22:48:06 +00:00
|
|
|
|
|
|
|
echo "basedir = $BASEDIR"
|
|
|
|
echo "docker_image = $DOCKER_IMAGE"
|
|
|
|
echo "action = $ACTION"
|
|
|
|
|
2021-11-25 16:52:03 +00:00
|
|
|
if [ -f "$BASEDIR/.marp/theme.scss" ]; then
|
2021-11-24 18:35:20 +00:00
|
|
|
DOCKER_OPT_MARP_THEME="-v $BASEDIR/.marp:/app/.marp"
|
2021-11-25 16:52:03 +00:00
|
|
|
echo "Theme: detected Marp files. Adding option to command line ($DOCKER_OPT_MARP_THEME)"
|
|
|
|
else
|
|
|
|
echo "Theme: no theme detected. Using default files"
|
2021-11-24 18:35:20 +00:00
|
|
|
fi
|
|
|
|
|
2021-12-06 10:11:24 +00:00
|
|
|
if [ -f "$BASEDIR/mkdocs.yml" ]; then
|
2022-01-28 17:41:34 +00:00
|
|
|
>&2 echo "Mkdocs: detected mkdocs.yml file. Please rename to mkdocs-patch.yml"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$BASEDIR/mkdocs-patch.yml" ]; then
|
|
|
|
DOCKER_OPT_MKDOCS_CONFIG="-v $BASEDIR/mkdocs.yml:/app/mkdocs-patch.yml"
|
|
|
|
echo "Mkdocs: detected mkdocs-patch.yml file. Adding option to command line ($DOCKER_OPT_MKDOCS_CONFIG)"
|
2021-12-06 10:11:24 +00:00
|
|
|
else
|
2022-01-28 17:41:34 +00:00
|
|
|
echo "Mkdocs: no mkdocs-patch.yml detected. Using default files"
|
2021-12-06 10:11:24 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "$BASEDIR/slides" ]; then
|
|
|
|
DOCKER_OPT_MARP_PORT="-p 5200:5200"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "$BASEDIR/docs" ]; then
|
|
|
|
DOCKER_OPT_MKDOCS_PORT="-p 5100:5100"
|
|
|
|
fi
|
2021-11-24 18:35:20 +00:00
|
|
|
|
2022-01-26 16:03:07 +00:00
|
|
|
if [ "$VERBOSITY" -gt 0 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2021-12-21 15:39:51 +00:00
|
|
|
docker run -i $DOCKER_OPT_TTY \
|
2021-12-06 10:11:24 +00:00
|
|
|
--shm-size=1gb \
|
|
|
|
-e "EXT_UID=$(id -u)" \
|
|
|
|
-e "EXT_GID=$(id -g)" \
|
2021-11-23 22:48:06 +00:00
|
|
|
-v "$BASEDIR/docs:/app/docs" \
|
|
|
|
-v "$BASEDIR/slides:/app/slides" \
|
2021-11-25 17:44:46 +00:00
|
|
|
-v "$BASEDIR/images:/app/images" \
|
2021-11-23 22:48:06 +00:00
|
|
|
-v "$BASEDIR/_build:/app/_build" \
|
2021-12-06 10:11:24 +00:00
|
|
|
$DOCKER_OPT_MKDOCS_CONFIG \
|
2021-11-24 18:35:20 +00:00
|
|
|
$DOCKER_OPT_MARP_THEME \
|
2021-12-06 10:11:24 +00:00
|
|
|
$DOCKER_OPT_MKDOCS_PORT \
|
|
|
|
$DOCKER_OPT_MARP_PORT \
|
2021-11-23 22:48:06 +00:00
|
|
|
"$DOCKER_IMAGE" "$ACTION"
|
2022-01-26 16:03:07 +00:00
|
|
|
if [ "$VERBOSITY" -gt 0 ]; then
|
|
|
|
set +x
|
|
|
|
fi
|
2021-11-23 22:48:06 +00:00
|
|
|
|
|
|
|
# TODO: ask current user permissions
|
|
|
|
# TODO: fix permissions on generated files
|