-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·73 lines (66 loc) · 1.76 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·73 lines (66 loc) · 1.76 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/bash
# Help message
usage() {
echo "Start the Jekyll server for local version of the website."
echo "If the server cannot be run natively start a docker container"
echo "and inside it start the server. If the docker image docs"
echo "does not exist build it first."
echo
echo "Syntax: bash run.sh [options]"
echo "options: Every option must be set separately."
echo "-h, --help Print this help message."
echo "-i, --interactive Docker in interactive mode."
echo "-b, --build Force docker image build."
}
PROJECT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
DOCKER_PROJECT_DIR="/usr/src/docs"
# If running in docker
run() {
# Check if image is available
if [[ $(docker image inspect aro-docs 2>/dev/null) == "[]" ]]; then
build
fi
echo "Running in docker"
docker run \
--network="host" \
-v "$PROJECT_DIR:$DOCKER_PROJECT_DIR" \
$docker_mode aro-docs
}
build() {
echo "Building docker image"
docker build \
--build-arg DOCKER_PROJECT_DIR="$DOCKER_PROJECT_DIR" \
-t aro-docs \
"$PROJECT_DIR"
}
main() {
# Process flags
docker_mode="-td"
# force_docker=false
force_build=false
while [ $# -gt 0 ]; do
case $1 in
-h | --help) # display Help
usage
exit 0
;;
-i | --interactive) # interactive mode
docker_mode="-it" ;;
-b | --build) # force build
force_build=true ;;
*) # invalid option
echo "Error: Invalid option"
echo
usage
exit 1
;;
esac
shift
done
if $force_build; then
build
fi
run
}
set -e
main "$@"