-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathinstall.sh
More file actions
335 lines (279 loc) · 10.3 KB
/
Copy pathinstall.sh
File metadata and controls
335 lines (279 loc) · 10.3 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/usr/bin/env bash
# Antigravity Tools Install Script (Linux + macOS)
# Usage: curl -fsSL https://raw.githubusercontent.com/lbjlaq/Antigravity-Manager/main/install.sh | bash
#
# Environment variables:
# VERSION - Install specific version (e.g., "4.1.20"), default: latest
# DRY_RUN - Set to "1" to print commands without executing
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
REPO="lbjlaq/Antigravity-Manager"
APP_NAME="Antigravity Tools"
APP_ID="com.lbjlaq.antigravity-tools"
GITHUB_API="https://api.github.com/repos/${REPO}/releases"
# Helper functions
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[OK]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; exit 1; }
run() {
if [[ "${DRY_RUN:-0}" == "1" ]]; then
echo -e "${YELLOW}[DRY-RUN]${NC} $*"
else
"$@"
fi
}
# Show help
show_help() {
cat << EOF
${APP_NAME} Install Script
Usage:
curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | bash
# Install specific version
curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | VERSION=4.3.3 bash
Options:
--help Show this help message
--version Show script version
Environment Variables:
VERSION Install specific version (default: latest)
DRY_RUN Set to "1" to preview commands without executing
Supported Platforms:
- Linux x86_64: .deb (Debian/Ubuntu), .rpm (Fedora/RHEL), .AppImage (Universal)
- Linux aarch64: .deb (Debian/Ubuntu), .rpm (Fedora/RHEL), .AppImage (Universal)
- macOS x86_64: .dmg
- macOS arm64: .dmg
EOF
exit 0
}
# Detect OS and architecture
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) PLATFORM="linux" ;;
Darwin) PLATFORM="macos" ;;
*) error "Unsupported OS: $OS. Use install.ps1 for Windows." ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH_LABEL="x86_64"; DEB_ARCH="amd64"; RPM_ARCH="x86_64" ;;
aarch64|arm64) ARCH_LABEL="aarch64"; DEB_ARCH="arm64"; RPM_ARCH="aarch64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
info "Detected: $PLATFORM ($ARCH_LABEL)"
}
# Detect Linux package manager
detect_linux_distro() {
if [[ "$PLATFORM" != "linux" ]]; then
return
fi
if command -v apt-get &>/dev/null; then
PKG_MANAGER="apt"
PKG_EXT="deb"
elif command -v dnf &>/dev/null; then
PKG_MANAGER="dnf"
PKG_EXT="rpm"
elif command -v yum &>/dev/null; then
PKG_MANAGER="yum"
PKG_EXT="rpm"
else
PKG_MANAGER="appimage"
PKG_EXT="AppImage"
warn "No supported package manager found, using AppImage"
fi
info "Package manager: $PKG_MANAGER ($PKG_EXT)"
}
# Get latest or specific version
get_version() {
if [[ -n "${VERSION:-}" ]]; then
RELEASE_VERSION="$VERSION"
info "Using specified version: v$RELEASE_VERSION"
return
fi
info "Fetching latest version..."
# Method 1: Try GitHub API
local response
if response=$(curl -fsSL -H "User-Agent: Antigravity-Installer" "${GITHUB_API}/latest" 2>/dev/null); then
RELEASE_VERSION=$(echo "$response" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/')
if [[ -n "$RELEASE_VERSION" ]]; then
info "Latest version: v$RELEASE_VERSION"
return
fi
fi
# Method 2: Fallback - parse from redirect URL (no rate limit)
info "API rate limited, using fallback method..."
local redirect_url
redirect_url=$(curl -fsSI "https://github.com/${REPO}/releases/latest" 2>/dev/null | grep -i "^location:" | tr -d '\r' | awk '{print $2}')
if [[ -n "$redirect_url" ]]; then
RELEASE_VERSION=$(echo "$redirect_url" | sed -E 's|.*/tag/v||')
fi
if [[ -z "${RELEASE_VERSION:-}" ]]; then
error "Failed to fetch latest version. Try specifying VERSION=x.x.x"
fi
info "Latest version: v$RELEASE_VERSION"
}
# Build download URL based on platform and package manager
build_download_url() {
local base_url="https://github.com/${REPO}/releases/download/v${RELEASE_VERSION}"
case "$PLATFORM" in
linux)
case "$PKG_EXT" in
deb)
# Antigravity.Tools_4.3.0_amd64.deb or _arm64.deb
DOWNLOAD_URL="${base_url}/Antigravity.Tools_${RELEASE_VERSION}_${DEB_ARCH}.deb"
FILENAME="Antigravity.Tools_${RELEASE_VERSION}_${DEB_ARCH}.deb"
;;
rpm)
# Antigravity.Tools-4.3.0-1.x86_64.rpm or -1.aarch64.rpm
DOWNLOAD_URL="${base_url}/Antigravity.Tools-${RELEASE_VERSION}-1.${RPM_ARCH}.rpm"
FILENAME="Antigravity.Tools-${RELEASE_VERSION}-1.${RPM_ARCH}.rpm"
;;
AppImage)
# Antigravity.Tools_4.3.0_amd64.AppImage or _aarch64.AppImage
local appimage_arch
if [[ "$ARCH_LABEL" == "x86_64" ]]; then
appimage_arch="amd64"
else
appimage_arch="aarch64"
fi
DOWNLOAD_URL="${base_url}/Antigravity.Tools_${RELEASE_VERSION}_${appimage_arch}.AppImage"
FILENAME="Antigravity.Tools_${RELEASE_VERSION}_${appimage_arch}.AppImage"
;;
esac
;;
macos)
local mac_arch
if [[ "$ARCH_LABEL" == "x86_64" ]]; then
mac_arch="x64"
else
mac_arch="aarch64"
fi
DOWNLOAD_URL="${base_url}/Antigravity.Tools_${RELEASE_VERSION}_${mac_arch}.dmg"
FILENAME="Antigravity.Tools_${RELEASE_VERSION}_${mac_arch}.dmg"
;;
esac
info "Download URL: $DOWNLOAD_URL"
}
# Download installer
download_installer() {
TEMP_DIR=$(mktemp -d)
DOWNLOAD_PATH="${TEMP_DIR}/${FILENAME}"
info "Downloading ${APP_NAME} v${RELEASE_VERSION}..."
run curl -fSL --progress-bar -o "$DOWNLOAD_PATH" "$DOWNLOAD_URL"
if [[ "${DRY_RUN:-0}" != "1" ]] && [[ ! -f "$DOWNLOAD_PATH" ]]; then
error "Download failed. Check your network or try a different version."
fi
success "Downloaded to $DOWNLOAD_PATH"
}
# Install on Linux
install_linux() {
info "Installing ${APP_NAME}..."
case "$PKG_MANAGER" in
apt)
run sudo dpkg -i "$DOWNLOAD_PATH"
run sudo apt-get install -f -y # Fix dependencies if needed
;;
dnf)
run sudo dnf install -y "$DOWNLOAD_PATH"
;;
yum)
run sudo yum install -y "$DOWNLOAD_PATH"
;;
appimage)
local install_dir="${HOME}/.local/bin"
run mkdir -p "$install_dir"
run chmod +x "$DOWNLOAD_PATH"
run cp "$DOWNLOAD_PATH" "${install_dir}/antigravity-tools"
if [[ ":$PATH:" != *":${install_dir}:"* ]]; then
warn "Add ${install_dir} to your PATH to run antigravity-tools from anywhere"
local shell_name rc_file export_line
shell_name="$(basename "${SHELL:-/bin/bash}")"
case "$shell_name" in
zsh) rc_file="$HOME/.zshrc" ;;
fish) rc_file="$HOME/.config/fish/config.fish" ;;
*) rc_file="$HOME/.bashrc" ;;
esac
export_line="export PATH=\"${install_dir}:\$PATH\""
[[ "$shell_name" == "fish" ]] && export_line="fish_add_path ${install_dir}"
if [[ -f "$rc_file" ]] && grep -qF "$install_dir" "$rc_file" 2>/dev/null; then
info "PATH entry already in $rc_file"
else
run echo "$export_line" >> "$rc_file"
info "Added ${install_dir} to PATH in $rc_file"
warn "Run: source $rc_file (or restart terminal)"
fi
fi
;;
esac
success "${APP_NAME} installed successfully!"
}
# Install on macOS
install_macos() {
info "Installing ${APP_NAME}..."
if [[ "${DRY_RUN:-0}" == "1" ]]; then
echo -e "${YELLOW}[DRY-RUN]${NC} hdiutil attach $DOWNLOAD_PATH -nobrowse -noautoopen"
echo -e "${YELLOW}[DRY-RUN]${NC} cp -R <mount>/${APP_NAME}.app /Applications/"
echo -e "${YELLOW}[DRY-RUN]${NC} hdiutil detach <mount>"
echo -e "${YELLOW}[DRY-RUN]${NC} sudo xattr -rd com.apple.quarantine /Applications/${APP_NAME}.app"
return
fi
# Mount DMG
local mount_output mount_point
mount_output=$(hdiutil attach "$DOWNLOAD_PATH" -nobrowse -noautoopen 2>&1)
mount_point=$(echo "$mount_output" | grep -o '/Volumes/.*' | head -n1)
if [[ -z "$mount_point" ]]; then
error "Failed to mount DMG. Output: $mount_output"
fi
# Copy app to /Applications
if [[ -d "/Applications/${APP_NAME}.app" ]]; then
info "Removing existing installation..."
rm -rf "/Applications/${APP_NAME}.app"
fi
cp -R "${mount_point}/${APP_NAME}.app" /Applications/
# Unmount DMG
hdiutil detach "$mount_point" -quiet 2>/dev/null || true
# Remove quarantine attribute to avoid "app is damaged" error
info "Removing quarantine attribute..."
sudo xattr -rd com.apple.quarantine "/Applications/${APP_NAME}.app" 2>/dev/null || true
success "${APP_NAME} installed to /Applications!"
}
# Cleanup
cleanup() {
if [[ -n "${TEMP_DIR:-}" ]] && [[ -d "$TEMP_DIR" ]]; then
rm -rf "$TEMP_DIR"
fi
}
# Main
main() {
for arg in "$@"; do
case "$arg" in
--help|-h) show_help ;;
--version|-v) echo "install.sh v1.0.0"; exit 0 ;;
esac
done
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} ${APP_NAME} Installer${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
trap cleanup EXIT
detect_platform
detect_linux_distro
get_version
build_download_url
download_installer
case "$PLATFORM" in
linux) install_linux ;;
macos) install_macos ;;
esac
echo ""
success "Installation complete!"
echo ""
info "Launch '${APP_NAME}' from your application menu or launcher."
echo ""
}
main "$@"