-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·208 lines (183 loc) · 9.04 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·208 lines (183 loc) · 9.04 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
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
#!/bin/sh
set -e
REPO="NoNFake/cve-cli"
INSTALL_DIR="/usr/local/bin"
DATA_DIR="/usr/local/share/cve-cli/data"
if [ "$(id -u)" -ne 0 ] && ! command -v sudo >/dev/null 2>&1; then
INSTALL_DIR="$HOME/.local/bin"
DATA_DIR="$HOME/.local/share/cve-cli/data"
fi
SUDO=""
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
fi
echo "[*] Installing cve-cli..."
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) echo "[-] Unsupported architecture: $ARCH"; exit 1 ;;
esac
echo "[*] Detected platform: $OS ($ARCH)"
DISTRO_TAG=""
if [ "$OS" = "linux" ] && [ -f /etc/os-release ]; then
DISTRO_TAG="$(. /etc/os-release && echo "${ID}:${ID_LIKE}")"
fi
install_runtime_deps() {
echo "[*] Ensuring runtime dependencies are installed..."
case "$OS" in
linux)
case "$DISTRO_TAG" in
*arch*|*manjaro*|*endeavouros*)
if command -v pacman >/dev/null 2>&1; then
$SUDO pacman -Sy --noconfirm --needed curl openssl sqlite libmaxminddb 2>/dev/null || true
fi
;;
*alpine*)
if command -v apk >/dev/null 2>&1; then
$SUDO apk add --no-cache curl openssl sqlite-libs libmaxminddb 2>/dev/null || true
fi
;;
*fedora*|*rhel*|*centos*|*rocky*|*alma*)
if command -v dnf >/dev/null 2>&1; then
$SUDO dnf install -y -q libcurl openssl sqlite libmaxminddb 2>/dev/null || true
fi
;;
*debian*|*ubuntu*|*pop*|*mint*|*kali*)
if command -v apt-get >/dev/null 2>&1; then
$SUDO apt-get update -qq 2>/dev/null || true
$SUDO apt-get install -y -qq libcurl4 libssl3 libsqlite3-0 libmaxminddb0 2>/dev/null || \
$SUDO apt-get install -y -qq libcurl4 libssl1.1 libsqlite3-0 libmaxminddb0 2>/dev/null || true
fi
;;
*)
if command -v pacman >/dev/null 2>&1; then
$SUDO pacman -Sy --noconfirm --needed curl openssl sqlite libmaxminddb 2>/dev/null || true
elif command -v apt-get >/dev/null 2>&1; then
$SUDO apt-get update -qq 2>/dev/null || true
$SUDO apt-get install -y -qq libcurl4 libssl3 libsqlite3-0 libmaxminddb0 2>/dev/null || true
elif command -v dnf >/dev/null 2>&1; then
$SUDO dnf install -y -q libcurl openssl sqlite libmaxminddb 2>/dev/null || true
elif command -v apk >/dev/null 2>&1; then
$SUDO apk add --no-cache curl openssl sqlite-libs libmaxminddb 2>/dev/null || true
fi
;;
esac
;;
darwin)
if command -v brew >/dev/null 2>&1; then
brew install -q curl openssl@3 sqlite libmaxminddb 2>/dev/null || true
fi
;;
esac
}
DOWNLOAD_SUCCESS=0
if command -v curl >/dev/null 2>&1; then
TMP_DIR="$(mktemp -d)"
TARBALL="cve-package.tar.gz"
echo "[*] Checking for latest prebuilt release from GitHub..."
LATEST_TAG="$(curl -sSL -I "https://github.com/${REPO}/releases/latest" 2>/dev/null | awk -F'/' '/[Ll]ocation:/ {print $NF}' | tr -d '\r\n')"
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="$(curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null | grep '"tag_name":' | head -n1 | sed -E 's/.*"tag_name":\s*"([^"]+)".*/\1/')"
fi
[ -n "$LATEST_TAG" ] && echo "[*] Latest release detected: ${LATEST_TAG}"
RELEASE_URL="$(curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null | grep -i "browser_download_url.*${OS}.*${ARCH}.*\.tar\.gz" | head -n1 | cut -d '"' -f 4)"
if [ -z "$RELEASE_URL" ]; then
RELEASE_URL="$(curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null | grep -i "browser_download_url.*${ARCH}.*\.tar\.gz" | head -n1 | cut -d '"' -f 4)"
fi
if [ -z "$RELEASE_URL" ] && [ -n "$LATEST_TAG" ]; then
RELEASE_URL="https://github.com/${REPO}/releases/download/${LATEST_TAG}/cve-${LATEST_TAG}-${OS}-${ARCH}.tar.gz"
fi
[ -z "$RELEASE_URL" ] && RELEASE_URL="https://github.com/${REPO}/releases/latest/download/cve-v2.0.0-${OS}-${ARCH}.tar.gz"
echo "[*] Downloading: $RELEASE_URL"
if curl -sSL -f -o "${TMP_DIR}/${TARBALL}" "$RELEASE_URL" 2>/dev/null || \
curl -sSL -f -o "${TMP_DIR}/${TARBALL}" "https://github.com/${REPO}/releases/download/${LATEST_TAG}/cve-v2.0.0-${OS}-${ARCH}.tar.gz" 2>/dev/null || \
curl -sSL -f -o "${TMP_DIR}/${TARBALL}" "https://github.com/${REPO}/releases/latest/download/cve-v2.0.0-${OS}-${ARCH}.tar.gz" 2>/dev/null; then
echo "[+] Successfully downloaded prebuilt release."
install_runtime_deps
tar -xzf "${TMP_DIR}/${TARBALL}" -C "$TMP_DIR"
$SUDO mkdir -p "$INSTALL_DIR" "$DATA_DIR"
$SUDO cp "${TMP_DIR}/cve" "${INSTALL_DIR}/cve"
$SUDO chmod 755 "${INSTALL_DIR}/cve"
if [ -d "${TMP_DIR}/data" ]; then
$SUDO cp -r "${TMP_DIR}/data/"* "$DATA_DIR/" 2>/dev/null || true
fi
rm -rf "$TMP_DIR"
DOWNLOAD_SUCCESS=1
else
rm -rf "$TMP_DIR"
echo "[*] Prebuilt release binary not found. Falling back to source build..."
fi
fi
if [ "$DOWNLOAD_SUCCESS" -eq 0 ]; then
echo "[*] Installing dependencies for $OS..."
case "$OS" in
linux)
case "$DISTRO_TAG" in
*arch*|*manjaro*|*endeavouros*)
$SUDO pacman -Sy --noconfirm cmake clang curl openssl sqlite libmaxminddb nlohmann-json
;;
*alpine*)
$SUDO apk add --no-cache cmake make g++ clang curl-dev openssl-dev sqlite-dev libmaxminddb-dev nlohmann-json
;;
*fedora*|*rhel*|*centos*|*rocky*|*alma*)
$SUDO dnf install -y -q cmake gcc-c++ clang libcurl-devel openssl-devel sqlite-devel libmaxminddb-devel json-devel
;;
*debian*|*ubuntu*|*pop*|*mint*|*kali*)
$SUDO apt-get update -qq
$SUDO apt-get install -y -qq cmake build-essential clang libcurl4-openssl-dev libssl-dev libsqlite3-dev libmaxminddb-dev nlohmann-json3-dev
;;
*)
if command -v pacman >/dev/null 2>&1; then
$SUDO pacman -Sy --noconfirm cmake clang curl openssl sqlite libmaxminddb nlohmann-json
elif command -v apt-get >/dev/null 2>&1; then
$SUDO apt-get update -qq
$SUDO apt-get install -y -qq cmake build-essential clang libcurl4-openssl-dev libssl-dev libsqlite3-dev libmaxminddb-dev nlohmann-json3-dev
elif command -v dnf >/dev/null 2>&1; then
$SUDO dnf install -y -q cmake gcc-c++ clang libcurl-devel openssl-devel sqlite-devel libmaxminddb-devel json-devel
elif command -v apk >/dev/null 2>&1; then
$SUDO apk add --no-cache cmake make g++ clang curl-dev openssl-dev sqlite-dev libmaxminddb-dev nlohmann-json
else
echo "[-] Warning: Unknown package manager. Please ensure cmake, curl, openssl, sqlite3, and libmaxminddb are installed."
fi
;;
esac
;;
darwin)
if ! command -v brew >/dev/null 2>&1; then
echo "[-] Homebrew is required on macOS to install dependencies. Visit https://brew.sh"
exit 1
fi
brew install -q cmake curl openssl@3 sqlite libmaxminddb nlohmann-json
;;
*)
echo "[-] Unsupported operating system: $OS"
exit 1
;;
esac
if [ -f "CMakeLists.txt" ] && [ -d "src" ]; then
SRC_DIR="."
else
echo "[*] Cloning cve-cli repository..."
SRC_DIR="$(mktemp -d)/cve-cli"
git clone --depth 1 "https://github.com/${REPO}.git" "$SRC_DIR"
fi
echo "[*] Compiling cve-cli..."
cmake -B "${SRC_DIR}/build" -S "$SRC_DIR" -DCMAKE_BUILD_TYPE=Release
cmake --build "${SRC_DIR}/build" -j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
echo "[*] Installing binary to $INSTALL_DIR..."
$SUDO mkdir -p "$INSTALL_DIR"
$SUDO cp "${SRC_DIR}/build/cve" "${INSTALL_DIR}/cve"
$SUDO chmod 755 "${INSTALL_DIR}/cve"
if [ -d "${SRC_DIR}/data" ]; then
$SUDO mkdir -p "$DATA_DIR"
$SUDO cp -r "${SRC_DIR}/data/"* "$DATA_DIR/" 2>/dev/null || true
fi
fi
echo ""
echo "[+] Successfully installed cve-cli $("${INSTALL_DIR}/cve" --version 2>/dev/null || echo '2.0.0') to ${INSTALL_DIR}/cve"
echo "[*] Quick start:"
echo " cve scan <target>"
echo " cve show <target>"
echo " cve search <query>"