forked from EricJMarti/inventory-hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_run.bash
executable file
·53 lines (42 loc) · 1.11 KB
/
docker_run.bash
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
#!/bin/bash
set -e
usage() {
[ -n "$1" ] && echo "error: $1"
echo "usage: $0 -c CONFIG -e EMAIL -r RELAY"
exit 1
}
[ $# -eq 0 ] && usage
while getopts c:e:r: arg
do
case "${arg}" in
c) config=${OPTARG};;
e) emails+=(${OPTARG});;
r) relay=${OPTARG};;
esac
done
[ -z "$config" ] && usage "missing config argument"
[ -z "$emails" ] && usage "missing email argument"
[ -z "$relay" ] && usage "missing relay argument"
[ ! -f "$config" ] && usage "$config does not exist or is not a regular file"
image="inventory-hunter"
retcode=0
(docker image inspect $image &> /dev/null) || retcode=1
if [ $retcode -ne 0 ]; then
echo "the $image docker image does not exist... please build the image and try again"
echo "build command: docker build -t $image ."
exit 1
fi
# docker requires absolute paths
if [ "$(uname)" = "Darwin" ]; then
if [[ ! "$config" == /* ]]; then
config="$(pwd -P)/${config#./}"
fi
else
config=$(readlink -f $config)
fi
docker run -d \
--network host \
-v $config:/config.yaml \
$image \
--email ${emails[@]} \
--relay $relay