-
Notifications
You must be signed in to change notification settings - Fork 5
/
clair-container-scan.sh
executable file
·61 lines (53 loc) · 1.07 KB
/
clair-container-scan.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
#!/bin/sh
usage() {
echo "Usage: $0 [-pv] [IMAGE_NAME]"
echo
echo "Options:"
echo " -p : Pull images before running scan"
echo " -v : verbose output"
exit 1
}
redirect_stderr() {
if [ "$VERBOSE" = 1 ]; then
"$@"
else
"$@" 2>/dev/null
fi
}
redirect_all() {
if [ "$VERBOSE" = 1 ]; then
"$@"
else
"$@" 2>/dev/null >/dev/null
fi
}
PULL=0
VERBOSE=0
while getopts ":phv" opt; do
case $opt in
p)
PULL=1
;;
v)
VERBOSE=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
h)
usage
;;
esac
done
shift $(($OPTIND -1))
BASEDIR=$(cd $(dirname "$0") && pwd)
cd "$BASEDIR"
if [ ! -f "docker-compose.yaml" ]; then
wget -q https://raw.githubusercontent.com/usr42/clair-container-scan/master/docker-compose.yaml
fi
[ "$PULL" = 1 ] && redirect_all docker-compose pull
redirect_stderr docker-compose run --rm scanner "$@"
ret=$?
redirect_all docker-compose down
exit $ret