|
8 | 8 | # ScanCode is a trademark of nexB Inc. |
9 | 9 |
|
10 | 10 | # Usage: |
11 | | -# Scan current directory with default pipeline 'scan_codebase': |
12 | | -# ./run-scan.sh |
| 11 | +# Default scan of current directory using 'scan_codebase': |
| 12 | +# ./run-scan.sh |
13 | 13 | # |
14 | | -# Scan a specific directory with a custom pipeline: |
15 | | -# ./run-scan.sh /path/to/scan/dir scan_single_package |
| 14 | +# Run pipelines on current directory: |
| 15 | +# ./run-scan.sh scan_codebase find_vulnerabilities |
16 | 16 | # |
17 | | -# Scan a specific directory with multiple pipelines: |
18 | | -# ./run-scan.sh /path/to/scan/dir "scan_codebase find_vulnerabilities" |
| 17 | +# Run pipelines on a specific directory: |
| 18 | +# ./run-scan.sh scan_codebase /path/to/scan/dir |
| 19 | +# |
| 20 | +# Run multiple pipelines on a specific directory (directory must come last): |
| 21 | +# ./run-scan.sh scan_codebase find_vulnerabilities /my/codebase |
| 22 | +# |
| 23 | +# Scan a directory using default pipeline: |
| 24 | +# ./run-scan.sh /path/to/codebase |
19 | 25 |
|
20 | 26 | set -e |
21 | 27 |
|
22 | | -# Use first argument as scan directory or default to current directory |
23 | | -SCAN_DIR="${1:-$(pwd)}" |
24 | | -# Use second argument as pipeline name or default to 'scan_codebase' |
25 | | -PIPELINE="${2:-scan_codebase}" |
26 | | -SCIO_DOCKER_IMAGE="ghcr.io/aboutcode-org/scancode.io:latest" |
27 | | -RESULTS_LOCATION="results.json" |
28 | | -ABS_RESULTS_PATH="$(pwd)/$RESULTS_LOCATION" |
| 28 | +readonly SCIO_DOCKER_IMAGE="ghcr.io/aboutcode-org/scancode.io:latest" |
| 29 | +readonly RESULTS_LOCATION="results.json" |
| 30 | + |
| 31 | +# Default values |
| 32 | +SCAN_DIR="$(pwd)" |
| 33 | +PIPELINES=() |
| 34 | + |
| 35 | +# Check if last argument is a directory |
| 36 | +LAST_ARG="${!#}" |
| 37 | +if [ -d "$LAST_ARG" ]; then |
| 38 | + SCAN_DIR="$LAST_ARG" |
| 39 | + PIPELINES=("${@:1:$#-1}") # All args except last |
| 40 | +else |
| 41 | + PIPELINES=("$@") |
| 42 | +fi |
29 | 43 |
|
30 | | -# Run the pipeline |
| 44 | +# Default pipeline if none specified |
| 45 | +if [ "${#PIPELINES[@]}" -eq 0 ]; then |
| 46 | + PIPELINES=("scan_codebase") |
| 47 | +fi |
| 48 | + |
| 49 | +# Run the scan |
31 | 50 | docker run --rm \ |
32 | 51 | -v "$SCAN_DIR":/codebase \ |
33 | 52 | "$SCIO_DOCKER_IMAGE" \ |
34 | | - run $PIPELINE /codebase \ |
| 53 | + run "${PIPELINES[@]}" /codebase \ |
35 | 54 | > "$RESULTS_LOCATION" |
36 | 55 |
|
37 | | -# Check if docker run succeeded |
38 | | -if [ $? -eq 0 ]; then |
39 | | - echo "✅ Scan complete using pipeline '$PIPELINE'. Results saved to $ABS_RESULTS_PATH" |
40 | | -else |
41 | | - echo "❌ Scan failed. Please check the error messages above." |
42 | | - exit 1 |
43 | | -fi |
| 56 | +ABS_RESULTS_PATH="$(pwd)/$RESULTS_LOCATION" |
| 57 | + |
| 58 | +echo "✅ Scan complete using pipeline(s): ${PIPELINES[*]}" |
| 59 | +echo "💾 Results saved to: $ABS_RESULTS_PATH" |
0 commit comments