This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.sh
executable file
·78 lines (64 loc) · 1.53 KB
/
run.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
printHelp() {
cat << EOM
Usage: ./run.sh PATH [OPTIONS]
PATH: Absolute or relative path to directory with kb files.
OPTIONS:
--help -h Shows this message.
--noupdate -n Prevents container from updating repositories.
--port= -p= Sets the server port equal to given value.
EOM
}
cleanDockerIndex() {
docker rm -f $(docker ps -aq) > /dev/null 2>&1
docker rmi -f $(docker images -a | grep "^<none>" | awk "{print $3}") > /dev/null 2>&1
docker rmi -f ostis > /dev/null 2>&1
}
if [ -z "$1" ]
then
echo "Error: script requires path argument"
printHelp
exit 1
fi
if [[ -d "$1" ]]; then
path_to_kb=$1
shift
else
if [[ $1 = "-h" || $1 = "--help" ]]; then
printHelp
exit 0
else
echo "Error: $1 is not a directory"
printHelp
exit 1
fi
fi
port="8000"
while [ $# -gt 0 ]; do
case "$1" in
--noupdate*) noupdate="true" ;;
-n*) noupdate="true" ;;
--port=*) port="${1#*=}" ;;
-p=*) port="${1#*=}" ;;
-h*) printHelp ;;
--help*) printHelp ;;
*)
echo "Error: invalid argument: $1"
printHelp
exit 1
;;
esac
shift
done
if ! [ "$(ls -A $path_to_kb)" ]; then
echo "The target directory $path_to_kb is empty, creating .keep file"
touch $path_to_kb/.keep
fi
cleanDockerIndex
if [ -z "$noupdate" ]
then
docker build --pull --tag ostis --file Dockerfile $path_to_kb
else
docker build --pull --tag ostis --file Dockerfile.noupdate $path_to_kb
fi
docker run -p $port:8000/tcp ostis bash -c "./run.sh"