-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·282 lines (238 loc) · 7.64 KB
/
install.sh
File metadata and controls
executable file
·282 lines (238 loc) · 7.64 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env bash
# install.sh - Install quickctx on Linux, macOS, or Android (Termux)
# Usage: curl -fsSL https://raw.githubusercontent.com/CaddyGlow/quickctx/main/install.sh | bash
# Usage: wget -qO- https://raw.githubusercontent.com/CaddyGlow/quickctx/main/install.sh | bash
set -e
# Configuration
REPO="CaddyGlow/quickctx"
APP_NAME="quickctx"
INSTALL_DIR="${QUICKCTX_INSTALL_DIR:-$HOME/.local/bin}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
GRAY='\033[0;90m'
NC='\033[0m' # No Color
# Helper functions
info() {
echo -e "${CYAN}$1${NC}"
}
success() {
echo -e "${GREEN}✓ $1${NC}"
}
warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
error() {
echo -e "${RED}✗ Error: $1${NC}" >&2
}
# Detect OS and architecture
detect_platform() {
local os arch target
# Detect OS
case "$(uname -s)" in
Linux*)
if [ -n "$ANDROID_ROOT" ] || [ -n "$TERMUX_VERSION" ]; then
os="android"
else
os="linux"
fi
;;
Darwin*)
os="darwin"
;;
*)
error "Unsupported operating system: $(uname -s)"
exit 1
;;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64)
arch="x86_64"
;;
aarch64|arm64)
arch="aarch64"
;;
armv7l|armv7)
arch="armv7"
;;
i686|i386)
arch="i686"
;;
*)
error "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
# Construct target triple
case "$os" in
linux)
target="${arch}-unknown-linux-gnu"
# Check for musl
if ldd --version 2>&1 | grep -q musl; then
target="${arch}-unknown-linux-musl"
fi
;;
darwin)
target="${arch}-apple-darwin"
;;
android)
target="${arch}-linux-android"
;;
esac
echo "$target"
}
# Download file with fallback
download() {
local url="$1"
local output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$output"
elif command -v wget >/dev/null 2>&1; then
wget -q "$url" -O "$output"
else
error "Neither curl nor wget found. Please install one of them."
exit 1
fi
}
# Extract archive
extract_archive() {
local archive="$1"
local dest="$2"
if [[ "$archive" == *.tar.gz ]] || [[ "$archive" == *.tgz ]]; then
tar -xzf "$archive" -C "$dest"
elif [[ "$archive" == *.zip ]]; then
if command -v unzip >/dev/null 2>&1; then
unzip -q "$archive" -d "$dest"
else
error "unzip not found. Please install unzip to extract .zip archives."
exit 1
fi
else
error "Unsupported archive format: $archive"
exit 1
fi
}
# Main installation
main() {
info "Installing $APP_NAME..."
# Detect platform
local target
target=$(detect_platform)
info "Detected platform: $target"
# Fetch latest release
info "Fetching latest release from GitHub..."
local api_url="https://api.github.com/repos/$REPO/releases/latest"
local release_json
local tmp_json="/tmp/quickctx-release.json"
download "$api_url" "$tmp_json"
# Parse version
local version
version=$(grep -o '"tag_name": *"[^"]*"' "$tmp_json" | head -1 | sed 's/.*: *"\(.*\)".*/\1/')
if [ -z "$version" ]; then
error "Failed to fetch release information"
rm -f "$tmp_json"
exit 1
fi
success "Latest version: $version"
# Find the right asset
# Try to find target-specific archive first, then fall back to generic patterns
local download_url archive_name
# Extract all download URLs and names
if grep -q "\"name\": *\"$APP_NAME.*$target" "$tmp_json"; then
# Target-specific binary found
archive_name=$(grep -o "\"name\": *\"$APP_NAME[^\"]*$target[^\"]*\"" "$tmp_json" | head -1 | sed 's/.*: *"\(.*\)".*/\1/')
download_url=$(grep -B 3 "\"name\": *\"$archive_name\"" "$tmp_json" | grep browser_download_url | sed 's/.*: *"\(.*\)".*/\1/')
else
# Try platform-specific patterns
case "$target" in
*linux*)
archive_name=$(grep -o "\"name\": *\"$APP_NAME[^\"]*linux[^\"]*\"" "$tmp_json" | head -1 | sed 's/.*: *"\(.*\)".*/\1/')
;;
*darwin*)
archive_name=$(grep -o "\"name\": *\"$APP_NAME[^\"]*darwin[^\"]*\"" "$tmp_json" | head -1 | sed 's/.*: *"\(.*\)".*/\1/')
;;
*android*)
archive_name=$(grep -o "\"name\": *\"$APP_NAME[^\"]*android[^\"]*\"" "$tmp_json" | head -1 | sed 's/.*: *"\(.*\)".*/\1/')
;;
esac
if [ -n "$archive_name" ]; then
download_url=$(grep -B 3 "\"name\": *\"$archive_name\"" "$tmp_json" | grep browser_download_url | sed 's/.*: *"\(.*\)".*/\1/')
fi
fi
rm -f "$tmp_json"
if [ -z "$download_url" ]; then
error "Could not find binary for $target in release assets."
echo ""
echo -e "${YELLOW}Troubleshooting:${NC}"
echo -e "${GRAY} 1. Check available releases: https://github.com/$REPO/releases${NC}"
echo -e "${GRAY} 2. Try manual installation from releases page${NC}"
echo -e "${GRAY} 3. Your platform: $target${NC}"
exit 1
fi
info "Downloading $archive_name..."
local tmp_archive="/tmp/$archive_name"
download "$download_url" "$tmp_archive"
local archive_size
archive_size=$(du -h "$tmp_archive" | cut -f1)
success "Download complete: $archive_size"
# Create install directory
info "Installing to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"
# Extract to temporary directory
local tmp_dir="/tmp/quickctx-extract"
rm -rf "$tmp_dir"
mkdir -p "$tmp_dir"
extract_archive "$tmp_archive" "$tmp_dir"
# Find and move the binary
local binary_path
binary_path=$(find "$tmp_dir" -type f -name "$APP_NAME" | head -1)
if [ -z "$binary_path" ]; then
error "Binary not found in extracted archive"
rm -rf "$tmp_dir" "$tmp_archive"
exit 1
fi
# Install binary
local install_path="$INSTALL_DIR/$APP_NAME"
# Remove old version if exists
if [ -f "$install_path" ]; then
rm -f "$install_path"
fi
mv "$binary_path" "$install_path"
chmod +x "$install_path"
# Clean up
rm -rf "$tmp_dir" "$tmp_archive"
success "$APP_NAME $version installed successfully!"
echo -e "${GRAY} Installed to: $install_path${NC}"
# Check if in PATH
if echo "$PATH" | grep -q "$INSTALL_DIR"; then
success "Installation directory is in PATH"
else
warning "Installation directory not in PATH"
echo ""
echo "Add the following to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo -e "${CYAN} export PATH=\"\$PATH:$INSTALL_DIR\"${NC}"
echo ""
echo "Then reload your shell or run: source ~/.bashrc (or ~/.zshrc)"
fi
# Test installation
echo ""
info "Verifying installation..."
if "$install_path" --version >/dev/null 2>&1; then
success "Installation verified"
echo ""
echo -e "${CYAN}Get started with:${NC}"
echo -e "${GRAY} $APP_NAME --help${NC}"
echo -e "${GRAY} $APP_NAME update # Check for updates${NC}"
else
warning "Installation completed but verification failed"
echo "Try running: $install_path --version"
fi
}
# Trap errors
trap 'error "Installation failed"; exit 1' ERR
# Run main
main "$@"