-
Notifications
You must be signed in to change notification settings - Fork 3
/
orthw
executable file
·1297 lines (1003 loc) · 35 KB
/
orthw
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
########################################
# Required configuration:
#
required_commands="curl md5sum xz"
required_directories="configuration_home ort_home orthw_home scancode_home exports_home"
orthw_config_file="$HOME/.orthwconfig"
if [ -f "$orthw_config_file" ]; then
# shellcheck source=orthconfig-template
. "$orthw_config_file"
else
echo "Missing the required configuration file '$orthw_config_file'. Please create that file following the "
echo "installation instructions, see https://github.com/oss-review-toolkit/orthw#3-create-your-orthw-configuration."
exit 1
fi
########################################
# Executables:
#
ort="${ort_home}/cli/build/install/ort/bin/ort"
orth="${ort_home}/helper-cli/build/install/orth/bin/orth"
########################################
# Dot directory files:
#
dot_dir=".orthw"
evaluation_md5_sum_file="$dot_dir/evaluation-md5sum.txt"
evaluation_result_file="$dot_dir/evaluation-result.json"
package_configuration_md5_sum_file="$dot_dir/package-configuration-md5sum.txt"
package_curations_md5_sum_file="$dot_dir/package-curations-md5sum.txt"
scan_result_file="$dot_dir/scan-result.json"
scan_results_storage_dir="$dot_dir/scan-results"
target_url_file="$dot_dir/target-url.txt"
temp_dir="$dot_dir/tmp"
########################################
# Configuration (repository) files:
#
ort_config_copyright_garbage_file="$configuration_home/copyright-garbage.yml"
ort_config_custom_license_texts_dir="$configuration_home/custom-license-texts"
ort_config_how_to_fix_text_provider_script="$configuration_home/reporter.how-to-fix-text-provider.kts"
ort_config_license_classifications_file="$configuration_home/license-classifications.yml"
ort_config_notice_templates_dir="$configuration_home/text-templates"
ort_config_package_configurations_dir="$configuration_home/package-configurations"
ort_config_package_curations_dir="$configuration_home/curations"
ort_config_resolutions_file="$configuration_home/resolutions.yml"
ort_config_rules_file="$configuration_home/evaluator.rules.kts"
########################################
# Exports (repository) files:
#
exports_license_finding_curations_file="$exports_home/license-finding-curations.yml"
exports_path_excludes_file="$exports_home/path-excludes.yml"
exports_vcs_url_mapping_file="$exports_home/vcs-url-mapping.yml"
########################################
# Initialized orthw directory input /
# output files:
#
copyrights_file="copyrights.txt"
copyrights_debug_file="copyrights-debug.txt"
cyclone_dx_json_report_file="cyclone-dx-report.json"
cyclone_dx_xml_report_file="cyclone-dx-report.xml"
evaluated_model_report_file="evaluated-model.json"
html_report_file="report.html"
repository_configuration_file="ort.yml"
spdx_json_report_file="report.spdx.json"
spdx_yaml_report_file="report.spdx.yml"
webapp_report_file="webapp.html"
########################################
# Helper functions:
#
usage() {
echo ""
echo "Configuration:"
echo ""
echo " configuration-home: $configuration_home"
echo " ort-home: $ort_home"
echo " orthw-home: $orthw_home"
echo " scancode-home: $scancode_home"
echo " exports-home: $exports_home"
echo ""
echo "Commands with scan context:"
echo ""
echo " clean"
echo " check-advisories"
echo " copyrights"
echo " copyrights <package-id>"
echo " export-copyright-garbage"
echo " init <target-url>"
echo " licenses <package-id>"
echo " licenses <package-id> <source-code-dir>"
echo " offending-packages"
echo " offending-licenses <package-id>"
echo " offending-licenses <package-id> <source-code-dir>"
echo " packages"
echo " packages-for-detected-licenses <license-ids-csv>"
echo " packages-non-excluded"
echo " projects"
echo " raw-licenses"
echo " report"
echo " report-cyclone-dx"
echo " report-html"
echo " report-model"
echo " report-notices"
echo " report-spdx"
echo " report-webapp"
echo " scan-issue-stats"
echo ""
echo "Commands for package configurations:"
echo ""
echo " pc-clean <package-id>"
echo " pc-create <package-id>"
echo " pc-create-all"
echo " pc-create-offending"
echo " pc-export-curations <package-id> <source-code-dir>"
echo " pc-export-path-excludes <package-id> <source-code-dir>"
echo " pc-find <package-id>"
echo " pc-format <package-id>"
echo " pc-import-curations <package-id> <source-code-dir>"
echo " pc-import-path-excludes <package-id> <source-code-dir>"
echo " pc-sort <package-id>"
echo ""
echo "Commands for repository configurations (ort.yml):"
echo ""
echo " rc-clean <source-code-dir>"
echo " rc-export-curations"
echo " rc-export-path-excludes"
echo " rc-format"
echo " rc-generate-project-excludes"
echo " rc-generate-rule-violation-resolutions"
echo " rc-generate-scope-excludes"
echo " rc-generate-timeout-error-resolutions"
echo " rc-import-curations"
echo " rc-import-curations-update-only"
echo " rc-import-path-excludes"
echo " rc-import-path-excludes-update-only"
echo " rc-sort"
echo ""
echo "Commands without scan context:"
echo ""
echo " analyze <source-code-dir>"
echo " analyze-in-docker <source-code-dir>"
echo " create-analyzer-result <package-ids-file>"
echo " delete-package-provenances <package-id>"
echo " find-license-url <license-id>"
echo " find-scans-for-package <package-id>"
echo " generate-license-classification-request <license-id>"
echo " handled-licenses"
echo " handled-licenses-by-category"
echo " package-provenances <package-id pattern>"
echo " update"
echo ""
echo "Working dir:"
echo ""
echo " target-url: $(cat $target_url_file 2> /dev/null)"
echo ""
}
analyze() {
local source_code_dir=$(realpath "$1")
ort analyze \
--input-dir $source_code_dir \
--output-dir . \
--output-formats JSON
}
analyze_in_docker() {
local project_dir=$(realpath "$1")
if [ -n "$ort_docker_registry_server" ] && \
[ -n "$ort_docker_registry_username" ] && \
[ -n "$ort_docker_registry_password" ]
then
docker login $ort_docker_registry_server \
--username $ort_docker_registry_username \
--password $ort_docker_registry_password
else
echo "Skip docker registry login, because that's not configured."
fi
docker pull $ort_docker_image
# Setup temporary directories to mount into docker:
local temp_dir=$(mktemp -d)
local mount_netrc_option=""
if [ -n "$netrc_machine" ] && \
[ -n "$netrc_login" ] && \
[ -n "$netrc_password" ]
then
local netrc_file="$temp_dir/.netrc"
touch $netrc_file
chmod 0600 $netrc_file
echo -e "machine $netrc_machine" >> $netrc_file
echo -e "login $netrc_login" >> $netrc_file
echo -e "password $netrc_password" >> $netrc_file
mount_netrc_option="-v $netrc_file:/root/.netrc"
else
echo "Skip setting up a .netrc file, because that's not configured."
fi
docker run \
-it \
$mount_netrc_option \
-v $ort_home:/ort \
-v $HOME/.ssh:/home/ort/.ssh \
-v $project_dir:/workspace \
--entrypoint /bin/bash \
$ort_docker_image
}
advise() {
mkdir -p $temp_dir
ort advise \
--advisors "$enabled_advisors" \
--output-dir $temp_dir \
--output-formats JSON \
--ort-file $scan_result_file
mv "$temp_dir/advisor-result.json" $scan_result_file > /dev/null 2>&1
rm -rf $temp_dir
}
create_package_configuration() {
local package_id=$1
orth package-configuration create \
--scan-results-storage-dir $scan_results_storage_dir \
--package-id $package_id \
--create-hierarchical-dirs \
--generate-path-excludes \
--license-classifications-file $ort_config_license_classifications_file \
--non-offending-license-categories "$non_offending_license_categories" \
--non-offending-license-ids "$non_offending_license_ids" \
--output-dir $ort_config_package_configurations_dir \
--force-overwrite
}
create_package_configurations() {
echo "Creating package configurations for $# packages..."
for (( i=1; i <= "$#"; i++ )); do
id=${!i}
echo "[$i / $#] $id"
create_package_configuration $id
done
}
get_package_configuration_dir_md5_sum() {
find $ort_config_package_configurations_dir -type f -name "*.yml" | sort | xargs md5sum | md5sum
}
get_package_curations_dir_md5_sum() {
find $ort_config_package_curations_dir -type f -name "*.yml" | sort | xargs md5sum | md5sum
}
# Checks whether the evaluator inputs changed.
check_evaluation_md5_sum() {
if [ -f $evaluation_md5_sum_file ]; then
get_package_configuration_dir_md5_sum > $package_configuration_md5_sum_file
get_package_curations_dir_md5_sum > $package_curations_md5_sum_file
md5sum -c $evaluation_md5_sum_file > /dev/null 2>&1
echo $?
rm -f $package_configuration_md5_sum_file
else
echo "2"
fi
}
# Creates or updates a file with md5sums of all evaluator input files.
update_evaluation_md5_sum() {
get_package_configuration_dir_md5_sum > $package_configuration_md5_sum_file
get_package_curations_dir_md5_sum > $package_curations_md5_sum_file
md5sum \
$package_curations_md5_sum_file \
$scan_result_file \
$repository_configuration_file \
$ort_config_rules_file \
$ort_config_license_classifications_file \
$package_configuration_md5_sum_file \
> $evaluation_md5_sum_file
rm -f $package_configuration_md5_sum_file
if [ $? -eq "1" ]; then
echo "Error creating md5 sums."
rm -f $evaluation_md5_sum_file
fi
}
evaluate() {
if [ "$(check_evaluation_md5_sum)" = "0" ]; then
# Skip evaluation as the input files haven't changed.
return
fi
mkdir -p $temp_dir
ort evaluate \
--copyright-garbage-file $ort_config_copyright_garbage_file \
--package-curations-dir $ort_config_package_curations_dir \
--output-dir $temp_dir \
--output-formats JSON \
--ort-file $scan_result_file \
--repository-configuration-file $repository_configuration_file \
--rules-file $ort_config_rules_file \
--license-classifications-file $ort_config_license_classifications_file \
--package-configurations-dir $ort_config_package_configurations_dir
if [[ $? -eq "1" ]]; then
echo "Error running the evaluator."
exit 1
fi
update_evaluation_md5_sum
mv "$temp_dir/evaluation-result.json" $evaluation_result_file
rm -rf $temp_dir
}
begins_with() { case $2 in "$1"*) true;; *) false;; esac; }
find_license_text_url() {
local license_id=$1
if begins_with "LicenseRef-scancode-" "$license_id"; then
local key=${license_id#"LicenseRef-scancode-"}
local license_file_path="src/licensedcode/data/licenses/$key.LICENSE"
if [ -e "$scancode_home/$license_file_path" ]; then
local revision=$(git -C $scancode_home rev-parse HEAD)
echo "https://github.com/nexB/scancode-toolkit/blob/$revision/$license_file_path"
fi
fi
if ! begins_with "LicenseRef-scancode-" "$license_id"; then
echo "https://spdx.org/licenses/$license_id.html"
fi
# TODO: handle custom license IDs.
}
find_package_configuration() {
local package_id=$1
orth package-configuration find \
--package-configurations-dir $ort_config_package_configurations_dir \
--package-id $package_id
}
init() {
local target_url=$1
rm -f $evaluation_md5_sum_file
rm -rf $scan_results_storage_dir
mkdir -p $dot_dir
echo "$target_url" > $target_url_file
# TODO: The below patching of GitLab URLs is HERE specific and needs to be generalized.
if [[ $target_url =~ https://$gitlab_host/oss/oss-review-toolkit/ort-gitlab-ci/-/jobs/([0-9]*)/artifacts/file/ort-results/scan-result.(json|json.xz) ]]; then
local job_id=${BASH_REMATCH[1]}
local ext=${BASH_REMATCH[2]}
target_url="https://$gitlab_host/api/v4/projects/8889/jobs/$job_id/artifacts/ort-results/scan-result.$ext"
echo "Patched URL: '$target_url'."
fi
declare -a header_options=()
if [[ $target_url == *$gitlab_host* ]]; then
header_options+=('-H' "PRIVATE-TOKEN: $gitlab_token")
echo "Added authentication header for $gitlab_host."
fi
local filename="${target_url##*/}"
local temp_scan_result_file="$dot_dir/temp-$filename"
local extension="${temp_scan_result_file//*.}"
curl -L "${header_options[@]}" $target_url > $temp_scan_result_file
if [[ "$extension" == "xz" ]]; then
xz -d -f $temp_scan_result_file
temp_scan_result_file="${temp_scan_result_file%.*}"
extension="${temp_scan_result_file//*.}"
fi
if [[ "$extension" == "json" ]]; then
mv $temp_scan_result_file $scan_result_file
elif [[ "$extension" == "yml" ]]; then
orth convert-ort-file -i $temp_scan_result_file -o $scan_result_file
else
echo "Cannot initialize with the given file '$filename'. The file extension is unexpected."
exit 1
fi
orth extract-repository-configuration \
--repository-configuration-file $repository_configuration_file \
--ort-file $scan_result_file
orth import-scan-results \
--ort-file $scan_result_file \
--scan-results-storage-dir $scan_results_storage_dir
exit 0
}
list_package_provenances() {
local package_id=$1
# The package_id is parameter to the SQL LIKE operator, see https://www.postgresqltutorial.com/postgresql-like/.
# For example to query all Sun Maven package provenances use: 'Maven:%sun%'.
local sql="SELECT ROW_NUMBER() OVER (ORDER BY identifier) as index,identifier FROM package_provenances WHERE identifier LIKE '$package_id'"
local result=$(query_scandb "$sql")
echo "$result"
}
ort() {
export ORT_OPTS="$ort_jvm_options"
$ort $ort_options "$@"
}
packages() {
orth list-packages \
--ort-file $scan_result_file \
--package-type PACKAGE
}
packages_non_excluded() {
orth list-packages \
--ort-file $scan_result_file \
--package-type PACKAGE \
--omit-excluded \
--repository-configuration-file $repository_configuration_file
}
projects() {
orth list-packages \
--ort-file $scan_result_file \
--package-type PROJECT
}
offending_packages() {
orth list-packages \
--ort-file $evaluation_result_file \
--offending-only \
--offending-severities ERROR
}
orth() {
export ORTH_OPTS="$orth_jvm_options"
$orth $orth_options "$@"
}
query_scandb() {
local sql="SET search_path TO '${scandb_schema}';$1"
require_command "psql"
export PGPASSWORD="$scandb_password"
psql -qAt -U $scandb_user -h $scandb_host -p $scandb_port -d $scandb_db -c "$sql"
}
report() {
local report_formats=$1
evaluate
mkdir -p $temp_dir
local notice_template_files=""
if [ -d $ort_config_notice_templates_dir ]; then
notice_template_files=$(find $ort_config_notice_templates_dir -name "NOTICE_*.ftl" | tr '\n' ',' | sed 's/,*\r*$//')
fi
if [ -n "$notice_template_files" ]; then
notice_template_path_option="-O PlainTextTemplate=template.path=$notice_template_files"
else
echo "No notice templates found under '$ort_config_notice_templates_dir'. Using ORT's default template(s)."
fi
ort report \
--copyright-garbage-file $ort_config_copyright_garbage_file \
--custom-license-texts-dir $ort_config_custom_license_texts_dir \
--how-to-fix-text-provider-script $ort_config_how_to_fix_text_provider_script \
--license-classifications-file $ort_config_license_classifications_file \
--package-configurations-dir $ort_config_package_configurations_dir \
--ort-file $evaluation_result_file \
--output-dir $temp_dir \
--report-formats $report_formats \
--refresh-resolutions \
--repository-configuration-file $repository_configuration_file \
--resolutions-file $ort_config_resolutions_file \
-O CycloneDX=output.file.formats=json,xml \
-O SpdxDocument=output.file.formats=json,yaml \
-O EvaluatedModel=output.file.formats=json \
-O PlainTextTemplate=project-types-as-packages="SpdxDocumentFile" \
$notice_template_path_option
mv "$temp_dir/bom.cyclonedx.xml" $cyclone_dx_xml_report_file > /dev/null 2>&1
mv "$temp_dir/bom.cyclonedx.json" $cyclone_dx_json_report_file > /dev/null 2>&1
mv "$temp_dir/bom.spdx.json" $spdx_json_report_file > /dev/null 2>&1
mv "$temp_dir/bom.spdx.yml" $spdx_yaml_report_file > /dev/null 2>&1
mv "$temp_dir/evaluated-model.json" $evaluated_model_report_file > /dev/null 2>&1
mv "$temp_dir/scan-report.html" $html_report_file > /dev/null 2>&1
mv "$temp_dir/scan-report-web-app.html" $webapp_report_file > /dev/null 2>&1
# Move notice files and turn the filename into uppercase using underscores instead of ' ' and '-'.
for file in $temp_dir/NOTICE_* ; do
local filename=$(basename -- "$file")
local target_filename=$(echo $filename | tr 'a-z' 'A-Z' | tr '-' '_' | tr ' ' '_')
mv $file ./$target_filename > /dev/null 2>&1
done
rm -rf $temp_dir
}
require_initialized() {
if [ ! -d $dot_dir ] || [ ! -f $target_url_file ] || [ ! -f $scan_result_file ]; then
echo "The working directory is not initialized. Please run 'orthw init <target-url>' first."
exit 1
fi
}
require_command() {
local command=$1
command -v $command >/dev/null 2>&1 || { echo >&2 "The command '$command' is required but not installed. Aborting."; exit 1; }
}
require_directory_configured() {
local variable_name=$1
local directory=${!variable_name}
if [ -z ${directory} ]; then
echo "The variable '$variable_name' must be defined in '$orthw_config_file'."
exit 1
fi
if [ ! -d ${directory} ]; then
echo "The variable '$variable_name' defined in '$orthw_config_file' must point to an existing directory."
exit 1
fi
}
require_docker_setup() {
require_command "docker"
}
########################################
# Check prerequisites:
#
for command in $required_commands; do
require_command $command
done
for directory in $required_directories; do
require_directory_configured $directory
done
########################################
# Parse command line options:
#
command="$1"
if [ "$command" = "analyze" ] && [ "$#" -eq 2 ]; then
project_dir=$2
analyze $project_dir
exit 0
fi
if [ "$command" = "analyze-in-docker" ] && [ "$#" -eq 2 ]; then
project_dir=$2
require_docker_setup
analyze_in_docker $project_dir
exit 0
fi
if [ "$command" = "check-advisories" ]; then
advise
exit 0
fi
if [ "$command" = "create-analyzer-result" ] && [ "$#" -eq 2 ]; then
package_ids_file=$2
orth create-analyzer-result \
--package-ids-file $package_ids_file \
--scancode-version "$scancode_version" \
-P "ort.scanner.storages.postgres.connection.url=jdbc:postgresql://$scandb_host:$scandb_port/$scandb_db" \
-P "ort.scanner.storages.postgres.connection.schema=$scandb_schema" \
-P "ort.scanner.storages.postgres.connection.username=$scandb_user" \
-P "ort.scanner.storages.postgres.connection.password=$scandb_password" \
-P "ort.scanner.storages.postgres.connection.sslmode=require" \
--ort-file ./synthetic-analyzer-result.json
exit 0
fi
if [ "$command" = "copyrights" ] && [ "$#" -eq 1 ]; then
require_initialized
orth list-copyrights \
--ort-file $scan_result_file \
--package-configurations-dir $ort_config_package_configurations_dir \
--copyright-garbage-file $ort_config_copyright_garbage_file \
> $copyrights_file
orth list-copyrights \
--ort-file $scan_result_file \
--package-configurations-dir $ort_config_package_configurations_dir \
--copyright-garbage-file $ort_config_copyright_garbage_file \
--show-raw-statements \
> $copyrights_debug_file
echo "Results written to: $copyrights_file, $copyrights_debug_file."
exit 0
fi
if [ "$command" = "copyrights" ] && [ "$#" -eq 2 ]; then
package_id=$2
require_initialized
orth list-copyrights \
--ort-file $scan_result_file \
--package-id $package_id
exit 0
fi
if [ "$command" = "clean" ] && [ "$#" -eq 1 ]; then
rm -rf $dot_dir
rm -f $repository_configuration_file
exit 0
fi
if [ "$command" = "find-scans-for-package" ] && [ "$#" -eq 2 ]; then
package_id=$2
# This command utilizes the following index:
# CREATE INDEX tbl_usr_gin_idx2
# ON oso.ossreview
# USING gin ((result->'analyzer'->'result'->'packages') jsonb_path_ops);
# Disable sequential scan to force using that index, because running `VACUUM ANALYZE`
# ensures this only temporarily (for unknown reason).
query="
SET enable_seqscan = OFF;
SELECT
CONCAT(result->'labels'->'job_parameters.SW_NAME', result->'labels'->'SW_NAME') as sw_name,
CONCAT(result->'labels'->'job_parameters.SW_VERSION', result->'labels'->'SW_VERSION') as sw_version,
(result->'analyzer'->>'start_time')::timestamp as start_time,
CONCAT(result->'labels'->'job_parameters.JENKINS_URL', result->'labels'->'JENKINS_URL') as job_url
FROM
oso.ossreview
WHERE
result->'analyzer'->'result'->'packages' @> '[{\"package\": {\"id\": \"$package_id\"}}]'
ORDER BY sw_name ASC, start_time DESC;
"
echo "Querying packages..."
result=$(query_scandb "$query")
echo "$result"
exit 0
fi
if [ "$command" = "delete-package-provenances" ] && [ "$#" -eq 2 ]; then
package_id=$2
list_package_provenances $package_id
count_sql="SELECT COUNT(*) FROM package_provenances WHERE identifier LIKE '$package_id'"
count=$(query_scandb "$count_sql")
echo "Found the above $count package provenances for query string '$package_id'."
echo "Press enter to delete them."
read -r key
delete_sql="DELETE FROM package_provenances WHERE identifier LIKE '$package_id'"
query_scandb "$delete_sql"
exit 0
fi
if [ "$command" = "export-copyright-garbage" ] && [ "$#" -eq 1 ]; then
require_initialized
echo "exporting from '$copyrights_file' to '$ort_config_copyright_garbage_file'."
mapped_copyrights_file="$temp_dir/copyrights-mapped.txt"
mkdir -p $temp_dir
orth map-copyrights\
--input-copyrights-file $copyrights_file \
--output-copyrights-file $mapped_copyrights_file \
--ort-file $scan_result_file
echo "Mapped the given processed statements to the following unprocessed ones:"
echo ""
cat "$mapped_copyrights_file"
echo ""
orth import-copyright-garbage \
--input-copyright-garbage-file $mapped_copyrights_file \
--output-copyright-garbage-file $ort_config_copyright_garbage_file
rm -rf $temp_dir
exit 0
fi
if [ "$command" = "find-license-url" ] && [ "$#" -eq 2 ]; then
license_id=$2
find_license_text_url "$license_id"
exit 0
fi
if [ "$command" = "generate-license-classification-request" ] && [ "$#" -eq 2 ]; then
license_id=$2
license_url=$(find_license_text_url "$2")
message=$license_classification_request_template
message="${message/<REPLACE_LICENSE_ID>/$license_id}"
message="${message/<REPLACE_LICENSE_URL>/$license_url}"
printf "%s" "$message" | sed "s/^\s*//g"
exit 0
fi
if [ "$command" = "handled-licenses" ] && [ "$#" -eq 1 ]; then
orth list-license-categories \
--license-classifications-file $ort_config_license_classifications_file
exit 0
fi
if [ "$command" = "handled-licenses-by-category" ] && [ "$#" -eq 1 ]; then
orth list-license-categories \
--license-classifications-file $ort_config_license_classifications_file \
--group-by-category
exit 0
fi
if [ "$command" = "init" ] && [ "$#" -eq 2 ]; then
target_url=$2
init $target_url
exit 0
fi
if [ "$command" = "licenses" ] && [ "$#" -eq 2 ]; then
package_id=$2
require_initialized
evaluate
echo "Downloading sources for $2."
orth list-licenses \
--ort-file $evaluation_result_file \
--package-id $package_id \
--repository-configuration-file $repository_configuration_file \
--package-configurations-dir $ort_config_package_configurations_dir \
--apply-license-finding-curations \
--omit-excluded
exit 0
fi
if [ "$command" = "licenses" ] && [ "$#" -eq 3 ]; then
package_id=$2
source_code_dir=$3
require_initialized
evaluate
orth list-licenses \
--ort-file $evaluation_result_file \
--package-id $package_id \
--repository-configuration-file $repository_configuration_file \
--package-configurations-dir $ort_config_package_configurations_dir \
--source-code-dir $source_code_dir \
--apply-license-finding-curations \
--omit-excluded
exit 0
fi
if [ "$command" = "offending-licenses" ] && [ "$#" -eq 2 ]; then
package_id=$2
require_initialized
evaluate
echo "Downloading sources for $2."
orth list-licenses \
--ort-file $evaluation_result_file \
--package-id $package_id \
--ignore-excluded-rule-ids "$ignore_excluded_rule_ids" \
--repository-configuration-file $repository_configuration_file \
--package-configurations-dir $ort_config_package_configurations_dir \
--apply-license-finding-curations \
--offending-only \
--offending-severities ERROR \
--omit-excluded
exit 0
fi
if [ "$command" = "offending-licenses" ] && [ "$#" -eq 3 ]; then
package_id=$2
source_code_dir=$3
require_initialized
evaluate
orth list-licenses \
--ort-file $evaluation_result_file \
--package-id $package_id \
--ignore-excluded-rule-ids "$ignore_excluded_rule_ids" \
--repository-configuration-file $repository_configuration_file \
--package-configurations-dir $ort_config_package_configurations_dir \
--source-code-dir $source_code_dir \
--apply-license-finding-curations \
--offending-only \
--offending-severities ERROR \
--omit-excluded
exit 0
fi
if [ "$command" = "packages" ] && [ "$#" -eq 1 ]; then
require_initialized
packages
exit 0
fi
if [ "$command" = "packages-non-excluded" ] && [ "$#" -eq 1 ]; then
require_initialized
packages_non_excluded
exit 0
fi
if [ "$command" = "packages-for-detected-licenses" ] && [ "$#" -eq 2 ]; then
detected_licenses=$2
require_initialized
orth list-packages \
--ort-file $scan_result_file \
--match-detected-licenses $detected_licenses
exit 0
fi
if [ "$command" = "projects" ] && [ "$#" -eq 1 ]; then
require_initialized
projects
exit 0
fi
if [ "$command" = "offending-packages" ] && [ "$#" -eq 1 ]; then
require_initialized
evaluate
offending_packages
exit 0
fi
if [ "$command" = "pc-create" ] && [ "$#" -eq 2 ]; then
require_initialized
package_id=$2
create_package_configuration $package_id
exit 0
fi
if [ "$command" = "pc-create-all" ] && [ "$#" -eq 1 ]; then
require_initialized
readarray -t ids <<<"$(packages)"
create_package_configurations ${ids[@]}
exit 0
fi
if [ "$command" = "pc-create-offending" ] && [ "$#" -eq 1 ]; then
require_initialized
evaluate
readarray -t ids <<<"$(offending_packages)"
create_package_configurations ${ids[@]}
exit 0
fi
if [ "$command" = "pc-clean" ] && [ "$#" -eq 2 ]; then
package_id=$2
package_configuration_file=$(find_package_configuration $package_id)
orth package-configuration remove-entries \
--package-configuration-file $package_configuration_file \
--ort-file $scan_result_file
exit 0
fi
if [ "$command" = "pc-export-curations" ] && [ "$#" -eq 3 ]; then
package_id=$2
source_code_dir=$3
package_configuration_file=$(find_package_configuration $package_id)
orth package-configuration export-license-finding-curations \
--package-configuration-file $package_configuration_file \
--license-finding-curations-file $exports_license_finding_curations_file \
--source-code-dir $source_code_dir \
--vcs-url-mapping-file $exports_vcs_url_mapping_file
exit 0
fi
if [ "$command" = "pc-export-path-excludes" ] && [ "$#" -eq 3 ]; then
package_id=$2
source_code_dir=$3
package_configuration_file=$(find_package_configuration $package_id)
orth package-configuration export-path-excludes \
--package-configuration-file $package_configuration_file \
--path-excludes-file $exports_path_excludes_file \
--source-code-dir $source_code_dir \
--vcs-url-mapping-file $exports_vcs_url_mapping_file
exit 0
fi
if [ "$command" = "pc-find" ] && [ "$#" -eq 2 ]; then
package_id=$2
find_package_configuration $package_id
exit 0
fi
if [ "$command" = "pc-format" ] && [ "$#" -eq 2 ]; then
package_id=$2
package_configuration_file=$(find_package_configuration $package_id)
orth package-configuration format $package_configuration_file
exit 0
fi
if [ "$command" = "pc-import-curations" ] && [ "$#" -eq 3 ]; then
package_id=$2
source_code_dir=$3
require_initialized
package_configuration_file=$(find_package_configuration $package_id)