run_ort.sh 3.73 KB
Newer Older
1
#!/bin/bash
Boris Baldassari's avatar
Boris Baldassari committed
2
3
4
5
6
7
8
9
10
11
12

###########################################################################
# Copyright (c) 2022 The Eclipse Foundation.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution, and is available at https://www.eclipse.org/legal/epl-2.0
#
# SPDX-License-Identifier: EPL-2.0
###########################################################################

13
# Get the path of the scripts/ directory.
14
ORT_ECLIPSE_SCRIPTS=$(dirname $(readlink -f "$0"))
15

Boris Baldassari's avatar
Boris Baldassari committed
16
17
18
# Check parameters
die () {
    echo >&2 "$@"
19
    echo "Usage: $0 <dir_project> <repo> <dir_results>"
Boris Baldassari's avatar
Boris Baldassari committed
20
21
    exit 1
}
22
[ "$#" -eq 3 ] || die "3 arguments required, $# provided."
Boris Baldassari's avatar
Boris Baldassari committed
23

24
25
26
27
28
29
30
PROJECT_IN=$1
[ -d $PROJECT_IN ] || die "[$PROJECT_IN] is not a directory."
REPO_IN=$2
[ -d $PROJECT_IN/$REPO_IN ] || die "[$REPO_IN] is not a directory."
DIR_IN=${PROJECT_IN}/${REPO_IN}

DIR_OUT_BASE=$3
Boris Baldassari's avatar
Boris Baldassari committed
31
32
33
34
[ -d $DIR_OUT_BASE ] || die "[$DIR_OUT_BASE] is not a directory."


# Compute directory vars
35
36
PROJECT=$(basename $PROJECT_IN)
REPO=$REPO_IN
Boris Baldassari's avatar
Boris Baldassari committed
37
DATE_RUN=$(date +'%Y%m%d%H%M')
38
39
40
DIR_OUT="${DIR_OUT_BASE%/}/${PROJECT%/}/${REPO%/}/${DATE_RUN}"
LOG="${DIR_OUT_BASE%/}/${PROJECT%/}/${REPO%/}/${PROJECT%/}_${REPO%/}_${DATE_RUN}.log"
mkdir -p "${DIR_OUT_BASE%/}/${PROJECT%/}/${REPO%/}/"
Boris Baldassari's avatar
Boris Baldassari committed
41

42
43
# Debug: uncomment following line to set conf directory.
#ORT_CONFIG_DIR=~/Projects/00_eclipse/eclipsefdn-ort/conf
Boris Baldassari's avatar
Boris Baldassari committed
44

45
46
47
48
49
# Check if env vars are set, otherwise optionally set defaults.
if [[ -z "$ORT_CONFIG_DIR" ]]; then
    echo "Please set ORT_CONFIG_DIR env var to point to the conf directory."
    die "Cannot find ORT_CONFIG_DIR directory."
fi
Boris Baldassari's avatar
Boris Baldassari committed
50

51
52
53
54
55
56
57
58
59
if [[ -z "$JAVA_HOME" ]]; then
    # This is the default on debian
    export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
fi


# Use for debug purpose - these should be normally defined in the PATH.
#export PATH=/opt/ort/cli/build/install/ort/bin/:$PATH
#export PATH=/opt/scancode-toolkit-30.1.0/:$PATH
Boris Baldassari's avatar
Boris Baldassari committed
60
61

echo "Start scan at $(date +"%Y-%m-%d %H:%M")" | tee -a $LOG
62
echo "- Using ort from [ort]." | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
63
64
65
66
67
echo "- Log written to [$LOG]." | tee -a $LOG
echo "- Working on project [$DIR_IN]." | tee -a $LOG
echo "" | tee -a $LOG

echo "* Start analyzer at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG
68
69
70
time ort analyze -f JSON  \
    --package-curations-dir ${ORT_CONFIG_DIR}/curations/ \
    -i $DIR_IN -o $DIR_OUT | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
71
72
73
74
echo "* Finish analyzer at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG

 
echo "* Start scanner at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
75
time ort scan -f JSON \
76
77
    -s ScanCode \
    -i $DIR_OUT/analyzer-result.json -o $DIR_OUT | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
78
79
echo "* Finish scanner at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG

80

Boris Baldassari's avatar
Boris Baldassari committed
81
echo "* Start evaluator at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG
82
time ort evaluate -f JSON \
83
84
85
86
    --rules-file ${ORT_CONFIG_DIR}/evaluator.rules.kts \
    --license-classifications-file ${ORT_CONFIG_DIR}/licenses_ort_eclipse.yml \
    --package-curations-dir ${ORT_CONFIG_DIR}/curations/ \
    -i $DIR_OUT/scan-result.json -o $DIR_OUT | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
87
88
echo "* Finish evaluator at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG

89
# Parse JSON evaluation report, get clearlydefined data and create curations file.
90
$ORT_ECLIPSE_SCRIPTS/curate_clearlydefined.py -i $DIR_OUT/evaluation-result.json -o ${ORT_CONFIG_DIR}/curations/clearlydefined_curations.yml
91

Boris Baldassari's avatar
Boris Baldassari committed
92
echo "* Start reporter at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG
93
time ort report \
94
95
    -f NoticeTemplate,SpdxDocument,CycloneDx,StaticHtml,WebApp \
    -i $DIR_OUT/evaluation-result.json -o $DIR_OUT | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
96
97
echo "* Finish reporter at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG

98
99
100
101
102
# Clean up /tmp directory, remove all directories at level 1
# that belong to us and that have not been modified for at least 12 hours
find /tmp/ -maxdepth 1 -type d -mmin +720 -exec rm -rf {} \;