-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscanoss.sh
More file actions
executable file
·91 lines (84 loc) · 2.9 KB
/
scanoss.sh
File metadata and controls
executable file
·91 lines (84 loc) · 2.9 KB
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
#!/bin/bash
###
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2018-2023 SCANOSS.COM
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
###
# Simulate getting file contents
if [ "$1" == "-h" ] || [ "$2" == "-h" ] || [ "$1" == "-help" ] || [ "$2" == "-help" ] ; then
echo "SCANOSS engine simulator help"
echo " command options..."
exit 0
fi
# Simulate getting file contents
if [ "$1" == "-k" ] || [ "$2" == "-k" ] || [ "$3" == "-k" ] ; then
for i in "$@"; do :; done
md5=$i
# Validate MD5 format (32 hexadecimal characters)
if [[ ! "$md5" =~ ^[a-fA-F0-9]{32}$ ]]; then
echo "Error: Invalid MD5 hash format: $md5" >&2
exit 1
fi
# Simulate large file contents (>1MB) for a specific md5
if [ "$md5" == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ]; then
head -c 1100000 /dev/zero | tr '\0' 'A'
exit 0
fi
echo "file contents: $md5"
echo "line 2"
echo "line 3"
exit 0
fi
# Simulate getting SBOM attribution
if [ "$1" == "-a" ] || [ "$2" == "-a" ] || [ "$3" == "-a" ] ; then
for i in "$@"; do :; done
sbom=$i
echo "attribution: $sbom"
echo "line 2"
echo "line 3"
exit 0
fi
# Simulate getting license details
if [ "$1" == "-l" ] || [ "$2" == "-l" ] || [ "$3" == "-l" ] ; then
for i in "$@"; do :; done
license=$i
echo "{\"$license\": {\"patent_hints\": \"yes\", \"copyleft\": \"no\", \"checklist_url\": \"https://www.osadl.org/fileadmin/checklists/unreflicenses/Apache-2.0.txt\",\"osadl_updated\": \"2022-12-12T13:47:00+00:00\"}}"
exit 0
fi
# Simulate kb name validation
for arg in "$@"; do
if [[ "$arg" == "-n" ]]; then
# -n followed by space (separate argument) is invalid - KB name should be attached
echo "Error: -n flag requires a KB name (use -n<name>)" >&2
exit 1
fi
# Check for invalid KB name (test_kb is used in tests to simulate invalid KB)
if [[ "$arg" == "-ntest_kb" ]]; then
echo "Error: KB 'test_kb' not found" >&2
exit 1
fi
done
# Simulate return a scan result
# Check if -w is present anywhere in the arguments
for arg in "$@"; do
if [[ "$arg" == "-w" ]]; then
for i in "$@"; do :; done
scf=$i
echo " {\"$scf\":[{\"id\": \"none\", \"server\": { \"kb_version\": {\"daily\": \"23.08.09\", \"monthly\": \"23.07\"}, \"version\": \"5.2.7\"}}]} "
exit 0
fi
done
# Unknown command option, respond with error
echo "Unknown command option: $*" >&2
exit 1