run_ort.sh 3.98 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

16
export ORT_CONFIG_DIR=/ort/eclipsefdn-ort/conf
17
18
export ORT_DATA_DIR=/data/cache/ort/
export GRADLE_USER_HOME=/data/cache/gradle/
19

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

28
PROJECT_IN=$1
29
if [ ! -d $PROJECT_IN ]; then
30
31
32
33
    echo "[$PROJECT_IN] is not a directory. Quitting."
    exit 0
fi
    
34
REPO_IN=$2
35
if [ ! -d $PROJECT_IN/$REPO_IN ]; then
36
37
38
39
    echo "[$REPO_IN] is not a directory. Quitting."
    exit 0
fi

40
41
42
DIR_IN=${PROJECT_IN}/${REPO_IN}

DIR_OUT_BASE=$3
Boris Baldassari's avatar
Boris Baldassari committed
43
44
45
46
[ -d $DIR_OUT_BASE ] || die "[$DIR_OUT_BASE] is not a directory."


# Compute directory vars
47
48
PROJECT=$(basename $PROJECT_IN)
REPO=$REPO_IN
Boris Baldassari's avatar
Boris Baldassari committed
49
DATE_RUN=$(date +'%Y%m%d%H%M')
50
51
52
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
53

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

57
58
59
60
61
# 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
62

63
64
65
66
67
68
69
70
71
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
72
73

echo "Start scan at $(date +"%Y-%m-%d %H:%M")" | tee -a $LOG
74
echo "- Using ort from [ort]." | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
75
76
77
78
echo "- Log written to [$LOG]." | tee -a $LOG
echo "- Working on project [$DIR_IN]." | tee -a $LOG
echo "" | tee -a $LOG

79

Boris Baldassari's avatar
Boris Baldassari committed
80
echo "* Start analyzer at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG
81
82
time ort analyze -f JSON  \
    --package-curations-dir ${ORT_CONFIG_DIR}/curations/ \
83
    --clearly-defined-curations \
84
    -i $DIR_IN -o $DIR_OUT | tee -a $LOG
Boris Baldassari's avatar
Boris Baldassari committed
85
86
echo "* Finish analyzer at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG

87

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

94

Boris Baldassari's avatar
Boris Baldassari committed
95
echo "* Start evaluator at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG
96
time ort evaluate -f JSON \
97
98
99
100
    --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
101
102
echo "* Finish evaluator at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG

103

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

Boris Baldassari's avatar
Boris Baldassari committed
107
echo "* Start reporter at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG
108
time ort report \
109
110
    -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
111
112
echo "* Finish reporter at $(date +'%Y-%m-%d %H:%M')" | tee -a $LOG

113

114
115
116
# 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 {} \;