-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·233 lines (198 loc) · 6.49 KB
/
install.sh
File metadata and controls
executable file
·233 lines (198 loc) · 6.49 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env bash
# dust installer script
# Usage: curl -sSfL https://raw.githubusercontent.com/bootandy/dust/main/install.sh | sh
set -e
REPO="bootandy/dust"
BINARY_NAME="dust"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Linux*) OS="linux" ;;
Darwin*) OS="darwin" ;;
MINGW*|MSYS*|CYGWIN*) OS="windows" ;;
*) error "Unsupported operating system: $(uname -s)" ;;
esac
}
# Detect architecture
detect_arch() {
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
armv7l) ARCH="arm" ;;
i686|i386) ARCH="i686" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
}
# Get the latest release version
get_latest_version() {
info "Fetching latest version..."
# Try using curl
if command -v curl >/dev/null 2>&1; then
VERSION=$(curl -sSf "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/')
# Try using wget
elif command -v wget >/dev/null 2>&1; then
VERSION=$(wget -qO- "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/')
else
error "Neither curl nor wget is available. Please install one of them."
fi
if [ -z "$VERSION" ]; then
error "Failed to fetch latest version"
fi
info "Latest version: v$VERSION"
}
# Determine target triple
get_target() {
if [ "$OS" = "linux" ]; then
if [ "$ARCH" = "x86_64" ]; then
TARGET="x86_64-unknown-linux-musl"
elif [ "$ARCH" = "aarch64" ]; then
TARGET="aarch64-unknown-linux-musl"
elif [ "$ARCH" = "arm" ]; then
TARGET="arm-unknown-linux-musleabi"
elif [ "$ARCH" = "i686" ]; then
TARGET="i686-unknown-linux-musl"
else
error "Unsupported Linux architecture: $ARCH"
fi
elif [ "$OS" = "darwin" ]; then
if [ "$ARCH" = "x86_64" ]; then
TARGET="x86_64-apple-darwin"
elif [ "$ARCH" = "aarch64" ]; then
# For Apple Silicon, use x86_64 with Rosetta if native build not available
TARGET="x86_64-apple-darwin"
warn "Using x86_64 binary (will run via Rosetta 2 on Apple Silicon)"
else
error "Unsupported macOS architecture: $ARCH"
fi
elif [ "$OS" = "windows" ]; then
if [ "$ARCH" = "x86_64" ]; then
TARGET="x86_64-pc-windows-msvc"
elif [ "$ARCH" = "i686" ]; then
TARGET="i686-pc-windows-msvc"
else
error "Unsupported Windows architecture: $ARCH"
fi
else
error "Unsupported OS: $OS"
fi
info "Target platform: $TARGET"
}
# Download and extract
download_and_install() {
# Construct download URL
if [ "$OS" = "windows" ]; then
ARCHIVE_NAME="dust-v${VERSION}-${TARGET}.zip"
ARCHIVE_EXT="zip"
else
ARCHIVE_NAME="dust-v${VERSION}-${TARGET}.tar.gz"
ARCHIVE_EXT="tar.gz"
fi
DOWNLOAD_URL="https://github.com/$REPO/releases/download/v${VERSION}/${ARCHIVE_NAME}"
info "Downloading from: $DOWNLOAD_URL"
# Create temporary directory
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
# Download
if command -v curl >/dev/null 2>&1; then
curl -sSfL "$DOWNLOAD_URL" -o "$ARCHIVE_NAME" || error "Download failed"
elif command -v wget >/dev/null 2>&1; then
wget -q "$DOWNLOAD_URL" -O "$ARCHIVE_NAME" || error "Download failed"
fi
# Extract
info "Extracting archive..."
if [ "$ARCHIVE_EXT" = "tar.gz" ]; then
tar -xzf "$ARCHIVE_NAME" || error "Extraction failed"
elif [ "$ARCHIVE_EXT" = "zip" ]; then
unzip -q "$ARCHIVE_NAME" || error "Extraction failed"
fi
# Find the binary (it might be in a subdirectory)
if [ "$OS" = "windows" ]; then
BINARY_PATH=$(find . -name "${BINARY_NAME}.exe" | head -n 1)
else
BINARY_PATH=$(find . -name "$BINARY_NAME" -type f | head -n 1)
fi
if [ -z "$BINARY_PATH" ]; then
error "Binary not found in archive"
fi
# Determine installation directory
if [ -n "$DUST_INSTALL" ]; then
INSTALL_DIR="$DUST_INSTALL"
elif [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
elif [ -w "$HOME/.local/bin" ]; then
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
else
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
# Install binary
info "Installing to $INSTALL_DIR..."
if [ -w "$INSTALL_DIR" ]; then
cp "$BINARY_PATH" "$INSTALL_DIR/" || error "Installation failed"
chmod +x "$INSTALL_DIR/$BINARY_NAME" || true
else
# Try with sudo
warn "Installing with sudo (requires administrator privileges)..."
sudo cp "$BINARY_PATH" "$INSTALL_DIR/" || error "Installation failed"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME" || true
fi
# Clean up
cd - > /dev/null
rm -rf "$TMP_DIR"
info "${GREEN}✓${NC} dust v$VERSION installed successfully!"
# Check if install directory is in PATH
case ":$PATH:" in
*:$INSTALL_DIR:*)
;;
*)
warn "⚠️ $INSTALL_DIR is not in your PATH"
warn " Add the following to your shell config (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
echo ""
;;
esac
# Show version
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
info "Version check:"
"$BINARY_NAME" --version || true
fi
}
# Main execution
main() {
info "dust installer"
echo ""
# Check for required tools
if ! command -v tar >/dev/null 2>&1 && ! command -v unzip >/dev/null 2>&1; then
error "Neither tar nor unzip is available. Please install one of them."
fi
detect_os
detect_arch
get_latest_version
get_target
download_and_install
echo ""
info "Installation complete! Try running: ${GREEN}dust${NC}"
}
# Allow version to be specified via environment variable
if [ -n "$DUST_VERSION" ]; then
VERSION="$DUST_VERSION"
fi
main