Skip to content

Commit af35e1b

Browse files
committed
add download.sh
1 parent 5b1f1e6 commit af35e1b

2 files changed

Lines changed: 179 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ A command-line tool for Binance API developed based on the Go language, supporti
44
## Installation and Configuration
55

66
### Installation
7-
// TODO
7+
```shell
8+
curl -sSL https://raw.githubusercontent.com/UnipayFI/binance-cli/refs/heads/main/download.sh | bash
9+
```
810

911
### Environment variables
1012
Before using, you need to set the Binance API key:

download.sh

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#!/bin/bash
2+
3+
# Binance CLI Installer
4+
# This script automatically downloads and installs the latest release for your platform
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
BLUE='\033[0;34m'
13+
NC='\033[0m' # No Color
14+
15+
# GitHub repository info
16+
REPO="UnipayFI/binance-cli"
17+
BINARY_NAME="binance-cli"
18+
19+
# Function to print colored output
20+
print_info() {
21+
echo -e "${BLUE}[INFO]${NC} $1"
22+
}
23+
24+
print_success() {
25+
echo -e "${GREEN}[SUCCESS]${NC} $1"
26+
}
27+
28+
print_warning() {
29+
echo -e "${YELLOW}[WARNING]${NC} $1"
30+
}
31+
32+
print_error() {
33+
echo -e "${RED}[ERROR]${NC} $1"
34+
}
35+
36+
# Function to detect platform and architecture
37+
detect_platform() {
38+
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
39+
local arch=$(uname -m)
40+
41+
case "$os" in
42+
linux*)
43+
PLATFORM="linux"
44+
;;
45+
darwin*)
46+
PLATFORM="macos"
47+
;;
48+
cygwin*|mingw*|msys*)
49+
PLATFORM="windows"
50+
;;
51+
*)
52+
print_error "Unsupported operating system: $os"
53+
exit 1
54+
;;
55+
esac
56+
57+
case "$arch" in
58+
x86_64|amd64)
59+
ARCH="x86_64"
60+
;;
61+
arm64|aarch64)
62+
ARCH="arm64"
63+
;;
64+
*)
65+
print_error "Unsupported architecture: $arch"
66+
exit 1
67+
;;
68+
esac
69+
70+
print_info "Detected platform: $PLATFORM-$ARCH"
71+
}
72+
73+
# Function to get latest release tag
74+
get_latest_release() {
75+
print_info "Getting latest release information..."
76+
77+
if command -v curl >/dev/null 2>&1; then
78+
LATEST_TAG=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
79+
elif command -v wget >/dev/null 2>&1; then
80+
LATEST_TAG=$(wget -qO- "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
81+
else
82+
print_error "Neither curl nor wget is available. Please install one of them."
83+
exit 1
84+
fi
85+
86+
if [ -z "$LATEST_TAG" ]; then
87+
print_error "Failed to get latest release information"
88+
exit 1
89+
fi
90+
91+
print_info "Latest release: $LATEST_TAG"
92+
}
93+
94+
# Function to download and extract
95+
download_and_extract() {
96+
local filename="$BINARY_NAME-$PLATFORM-$ARCH.tar.gz"
97+
local download_url="https://github.com/$REPO/releases/download/$LATEST_TAG/$filename"
98+
99+
print_info "Downloading $filename..."
100+
101+
# Download file
102+
if command -v curl >/dev/null 2>&1; then
103+
curl -L -o "$filename" "$download_url"
104+
elif command -v wget >/dev/null 2>&1; then
105+
wget -O "$filename" "$download_url"
106+
else
107+
print_error "Neither curl nor wget is available"
108+
exit 1
109+
fi
110+
111+
# Check if download was successful
112+
if [ ! -f "$filename" ]; then
113+
print_error "Failed to download $filename"
114+
exit 1
115+
fi
116+
117+
print_info "Extracting $filename..."
118+
119+
# Extract archive
120+
tar -xzf "$filename"
121+
122+
# Clean up archive
123+
rm "$filename"
124+
125+
# Make binary executable (for Unix-like systems)
126+
if [ "$PLATFORM" != "windows" ]; then
127+
chmod +x "$BINARY_NAME"
128+
fi
129+
130+
print_success "Installation completed!"
131+
print_info "Binary location: $(pwd)/$BINARY_NAME"
132+
}
133+
134+
# Function to show usage instructions
135+
show_usage() {
136+
echo
137+
print_info "Usage instructions:"
138+
echo "1. Set up your environment variables:"
139+
echo " export API_KEY=\"your_api_key\""
140+
echo " export API_SECRET=\"your_api_secret\""
141+
echo
142+
echo "2. Run the binary:"
143+
echo " ./$BINARY_NAME --help"
144+
echo
145+
if [ "$PLATFORM" != "windows" ]; then
146+
echo "3. (Optional) Move to a directory in your PATH:"
147+
echo " sudo mv $BINARY_NAME /usr/local/bin/"
148+
fi
149+
}
150+
151+
# Main execution
152+
main() {
153+
print_info "Starting Binance CLI installation..."
154+
155+
# Check if we're running as root (warn user)
156+
if [ "$EUID" -eq 0 ]; then
157+
print_warning "Running as root. Consider running as a regular user."
158+
fi
159+
160+
# Detect platform and architecture
161+
detect_platform
162+
163+
# Get latest release
164+
get_latest_release
165+
166+
# Download and extract
167+
download_and_extract
168+
169+
# Show usage instructions
170+
show_usage
171+
172+
print_success "Binance CLI has been successfully installed!"
173+
}
174+
175+
# Run main function
176+
main "$@"

0 commit comments

Comments
 (0)