diff --git a/watch-serve.sh b/watch-serve.sh index 9310ae5..c1802b4 100755 --- a/watch-serve.sh +++ b/watch-serve.sh @@ -1,3 +1,42 @@ #!/usr/bin/env bash -{ mdbook watch docs/ -d ../static/documentation & hugo server; } +# Return 0 if command $1 exists, 1 otherwise. +function _exists { + command -v "$1" >/dev/null +} + +if [[ $(_exists mdbook) && $(_exists hugo) ]]; then + { mdbook watch docs/ -d ../static/documentation & hugo server; } + exit 0 +fi + +# Some pre-requisites are missing, try to use containers +CRT="" +CONTAINER_NAME="zellij-docs:latest" + +if $(_exists podman); then + CRT="$(which podman)" + echo "Using '$CRT' as container runtime" + + $CRT build --tag "$CONTAINER_NAME" -f Containerfile + $CRT run --userns keep-id --user "$(id -u):$(id -g)" -v "$PWD:$PWD:z" -w "$PWD" -p 1313:1313 $CONTAINER_NAME + +elif $(_exists docker); then + CRT="$(which docker)" + echo "Using '$CRT' as container runtime" + + $CRT build --tag "$CONTAINER_NAME"