-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
97 lines (83 loc) · 2.78 KB
/
install.sh
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
#!/bin/bash
# Set the version
VERSION="0.7.3"
# Detect the operating system and architecture
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macOS"
INSTALL_DIR="/usr/local/bin"
if [[ $(uname -m) == "arm64" ]]; then
ARCH="arm64"
else
ARCH="amd64"
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="Linux"
ARCH="x86_64"
INSTALL_DIR="/usr/local/bin"
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
OS="Windows"
ARCH="x86_64"
INSTALL_DIR="/c/Windows/System32"
else
echo "Unsupported operating system"
exit 1
fi
# Set the appropriate filename based on the OS and architecture
if [[ "$OS" == "macOS" ]]; then
FILENAME="vulncheck_${VERSION}_macOS_${ARCH}.zip"
elif [[ "$OS" == "Linux" ]]; then
FILENAME="vulncheck_${VERSION}_Linux_${ARCH}.tar.gz"
elif [[ "$OS" == "Windows" ]]; then
FILENAME="vulncheck_${VERSION}_Windows_${ARCH}.zip"
fi
# Download URL
URL="https://github.com/vulncheck-oss/cli/releases/download/v${VERSION}/${FILENAME}"
# Create a temporary directory
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
# Download the file
echo "Downloading $FILENAME..."
if [[ "$OS" == "Windows" ]]; then
powershell -Command "Invoke-WebRequest -Uri $URL -OutFile $FILENAME"
else
curl -LO "$URL"
fi
# Extract the contents
echo "Extracting..."
if [[ "$FILENAME" == *.zip ]]; then
unzip "$FILENAME"
elif [[ "$FILENAME" == *.tar.gz ]]; then
tar -xzf "$FILENAME"
fi
# Get the name of the extracted folder
EXTRACTED_FOLDER="${FILENAME%.*}"
if [[ "$FILENAME" == *.tar.gz ]]; then
EXTRACTED_FOLDER="${EXTRACTED_FOLDER%.tar}"
fi
# Explain sudo usage
if [[ "$OS" != "Windows" ]]; then
echo "To install vulncheck system-wide, we need to copy the binary to $INSTALL_DIR."
echo "This requires administrator privileges."
echo "You will be prompted for your password to perform this action."
echo "This allows all users on this system to use the vulncheck command."
echo "Press Ctrl+C to cancel the installation if you don't want to proceed."
fi
# Copy the binary to the install directory
echo "Installing vulncheck to $INSTALL_DIR..."
if [[ "$OS" == "Windows" ]]; then
mv "$EXTRACTED_FOLDER/bin/vulncheck.exe" "$INSTALL_DIR"
else
sudo mv "$EXTRACTED_FOLDER/bin/vulncheck" "$INSTALL_DIR"
fi
# Clean up
cd ..
rm -rf "$TEMP_DIR"
echo "Installation complete. You can now use 'vulncheck' command."
if [[ "$OS" != "Windows" ]]; then
echo "The vulncheck binary has been installed to $INSTALL_DIR, which is already in your system's PATH."
echo "You can run it by typing 'vulncheck' in your terminal."
else
echo "The vulncheck binary has been installed to $INSTALL_DIR."
echo "This directory should already be in your system's PATH."
echo "You can run it by typing 'vulncheck' in your command prompt or PowerShell."
fi