-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautobash
76 lines (71 loc) · 1.34 KB
/
autobash
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
#!/bin/bash
# Default variables
file_path=""
sn=false
tr=false
gr=false
file_path=""
# Options processing
while [[ "$#" -gt 0 ]]; do
case $1 in
-s)
sn=true
;;
-t)
tr=true
;;
-g)
gr=true
;;
-f)
shift
file_path="$1"
;;
*)
echo "Option no valid or missing argument: $1"
exit 1
;;
esac
shift
done
# Verify if the file exists
if [ ! -f "$file_path" ]; then
echo "File does not exist: $file_path"
exit 1
fi
#Connect to snyk if needed
if [ "$sn" == true ];
then
snyk auth <auth-token>
fi
while IFS= read -r line; do
# Process each line here
name=$(basename ${line})
resPath="/home/pere/results/${name}"
if [ ! -d "$resPath" ]; then
mkdir -p "$resPath"
fi
outputSnyk="$resPath/Snyk.txt"
outputTrivy="$resPath/Trivy.txt"
outputGrype="$resPath/Grype.txt"
if [ ! -d "/home/pere/${name}" ];
then
git clone $line
fi
if [ "$sn" == true ];
then
snyk test --all-projects --json "/home/pere/${name}" >"$outputSnyk"
fi
if [ "$tr" == true ];
then
trivy repository ${line} -f json --scanners vuln >"$outputTrivy"
fi
if [ "$gr" == true ];
then
grype "/home/pere/${name}" --add-cpes-if-none --scope all-layers -o json > "$outputGrype"
fi
if [ -n "$name" ];
then
rm -r "/home/pere/${name}"
fi
done < "$file_path"