forked from fedora-eln/eln-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.sh
executable file
·41 lines (34 loc) · 1.28 KB
/
preview.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
#!/bin/sh
: ${PORT:=8080}
if [ "$(uname)" == "Darwin" ]; then
# Running on macOS.
# Let's assume that the user has the Docker CE installed
# which doesn't require a root password.
echo "The preview will be available at http://localhost:$PORT/"
docker run --rm -v $(pwd):/antora:ro -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro -p $PORT:80 nginx
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Running on Linux.
# Fedora Workstation has python3 installed as a default, so using that
echo ""
echo "The preview is available at http://localhost:$PORT"
echo ""
if [[ "$*" == *--refresh* ]]; then
if ! [ -x "$(command -v inotifywait)" ]; then
echo 'Error: inofitywait (inotify-utils) is not installed.' >&2
exit 1
fi
# Setup trap to kill this process group on ctrl+c.
killgroup(){
kill 0
}
trap killgroup SIGINT
# Run the Python's webserver.
python3 -m http.server $PORT --directory ./public &
while inotifywait -r ./modules -e create -e moved_to -e modify; do
echo "Documentation source changed, rebuilding ..."
./build.sh
done
else
python3 -m http.server $PORT --directory ./public
fi
fi