forked from zellij-org/zellij-org.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch-serve.sh
executable file
·54 lines (41 loc) · 1.42 KB
/
watch-serve.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
# 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 & mdbook watch docs-old/ -d ../static/old-documentation & hugo server; }
exit 0
fi
# Some pre-requisites are missing, try to use containers
CRT=""
CONTAINER_NAME="zellij-docs:latest"
if $(_exists nix); then
echo "Trying 'nix develop' to execute script"
nix develop --command "$0"
if [[ $? -ne 0 ]] && $(_exists nix-shell); then
echo "Using 'nix-shell' to execute script instead"
nix-shell --command "$0"
fi
elif $(_exists podman); then
CRT="$(which podman)"
echo "Using '$CRT' as container runtime"
$CRT build --tag "$CONTAINER_NAME" -f Containerfile
$CRT run --rm -it --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" <Containerfile
$CRT run --rm -it --user "$(id -u):$(id -g)" -v "$PWD:$PWD" -w "$PWD" -p 1313:1313 $CONTAINER_NAME
else
echo "You must have installed either of:"
echo ""
echo " - nix"
echo " - docker"
echo " - podman"
echo " - mdbook AND hugo"
echo ""
echo "To compile and preview the docs locally."
exit 1
fi
exit 0