-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·161 lines (133 loc) · 3.61 KB
/
setup.sh
File metadata and controls
executable file
·161 lines (133 loc) · 3.61 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
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
#!/usr/bin/env bash
# Setup script for CVE Scanner CLI (Linux only)
set -e
DOCKER_IMAGE="ghcr.io/debaa17/cve-scanner-cli:latest"
DOCKER_ALIAS="alias cvecli='docker run --rm -it ${DOCKER_IMAGE}'"
PATH_EXPORT='export PATH="$HOME/.local/bin:$PATH"'
INSTALL_METHOD=""
resolve_rc_file() {
local shell_name
shell_name="$(basename "${SHELL:-}")"
case "$shell_name" in
bash)
if [ -f "$HOME/.bashrc" ]; then
printf '%s\n' "$HOME/.bashrc"
else
printf '%s\n' "$HOME/.profile"
fi
;;
zsh)
printf '%s\n' "$HOME/.zshrc"
;;
*)
printf '%s\n' "$HOME/.profile"
;;
esac
}
ensure_line_in_file() {
local file_path="$1"
local line="$2"
touch "$file_path"
if ! grep -Fqx "$line" "$file_path"; then
printf '\n%s\n' "$line" >> "$file_path"
fi
}
remove_line_from_file() {
local file_path="$1"
local line="$2"
local temp_file
if [ ! -f "$file_path" ]; then
return
fi
if ! grep -Fqx "$line" "$file_path"; then
return
fi
temp_file="$(mktemp)"
grep -Fvx "$line" "$file_path" > "$temp_file" || true
mv "$temp_file" "$file_path"
}
print_reload_hint() {
local rc_file="$1"
printf "\033[0;33mOpen a new terminal or run: source %s\033[0m\n" "$rc_file"
}
install_docker() {
local rc_file
if ! command -v docker >/dev/null 2>&1; then
printf "Docker is required for the recommended install method but was not found.\n"
exit 1
fi
rc_file="$(resolve_rc_file)"
docker pull "$DOCKER_IMAGE"
ensure_line_in_file "$rc_file" "$DOCKER_ALIAS"
printf "\033[0;32mDocker install complete. Added cvecli alias to %s\033[0m\n" "$rc_file"
printf "\033[0;32mExample: cvecli --id CVE-2025-55184\033[0m\n"
print_reload_hint "$rc_file"
}
install_local() {
local rc_file
if ! command -v python3 >/dev/null 2>&1; then
printf "Python3 is required but not found. Please install Python3.\n"
exit 1
fi
rc_file="$(resolve_rc_file)"
if [ ! -d "myenv" ]; then
python3 -m venv myenv
fi
source myenv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
chmod +x cve_search_cli.py
mkdir -p "$HOME/.local/bin"
ln -sf "$PWD/cve_search_cli.py" "$HOME/.local/bin/cvecli"
ensure_line_in_file "$rc_file" "$PATH_EXPORT"
remove_line_from_file "$rc_file" "$DOCKER_ALIAS"
printf "\033[0;32mLocal install complete. Use 'cvecli' from anywhere to run the tool.\033[0m\n"
printf "\033[0;32mExample: cvecli --id CVE-2025-55184\033[0m\n"
print_reload_hint "$rc_file"
}
choose_install_method() {
printf "Choose installation method:\n"
printf "1) Docker (recommended)\n"
printf "2) Local machine\n"
printf "Enter choice [1/2]: "
read -r choice
case "$choice" in
1|"")
INSTALL_METHOD="docker"
;;
2)
INSTALL_METHOD="local"
;;
*)
printf "Invalid choice. Use 1 for Docker or 2 for local machine.\n"
exit 1
;;
esac
}
case "${1:-}" in
--docker)
INSTALL_METHOD="docker"
;;
--local)
INSTALL_METHOD="local"
;;
"")
if [ -t 0 ]; then
choose_install_method
else
INSTALL_METHOD="docker"
fi
;;
*)
printf "Usage: bash setup.sh [--docker|--local]\n"
exit 1
;;
esac
case "$INSTALL_METHOD" in
docker)
install_docker
;;
local)
install_local
;;
esac