-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
234 lines (197 loc) · 6.88 KB
/
install.sh
File metadata and controls
234 lines (197 loc) · 6.88 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
#!/bin/bash
# PersistenceAI Web Installer (Bash)
# This script can be downloaded and executed via:
# curl -fsSL https://persistenceai.com/install | bash
# wget -qO- https://persistenceai.com/install | bash
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m' # No Color
info() { echo -e "${CYAN}ℹ️ $1${NC}"; }
success() { echo -e "${GREEN}✅ $1${NC}"; }
error() { echo -e "${RED}❌ $1${NC}"; }
warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
echo ""
echo -e "${MAGENTA}╔════════════════════════════════════════╗${NC}"
echo -e "${MAGENTA}║ PersistenceAI Installer ║${NC}"
echo -e "${MAGENTA}╚════════════════════════════════════════╝${NC}"
echo ""
# Configuration
BASE_URL="https://persistence-ai.github.io/Landing"
APP_NAME="persistenceai"
INSTALL_DIR="$HOME/.persistenceai/bin"
TEMP_DIR=$(mktemp -d)
# Cleanup function
cleanup() {
rm -rf "$TEMP_DIR"
}
trap cleanup EXIT
# Detect platform and architecture
OS="unknown"
ARCH="unknown"
case "$(uname -s)" in
Linux*) OS="linux" ;;
Darwin*) OS="darwin" ;;
*) error "Unsupported operating system: $(uname -s)"; exit 1 ;;
esac
case "$(uname -m)" in
x86_64) ARCH="x64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) error "Unsupported architecture: $(uname -m)"; exit 1 ;;
esac
PLATFORM="$OS-$ARCH"
ZIP_NAME="$APP_NAME-$PLATFORM.zip"
# Check for musl (Alpine Linux)
if [ "$OS" = "linux" ] && ldd /bin/sh 2>&1 | grep -q musl; then
PLATFORM="$OS-$ARCH-musl"
ZIP_NAME="$APP_NAME-$PLATFORM.zip"
fi
info "Detected platform: $PLATFORM"
# Determine version
VERSION="${1:-latest}"
if [ "$VERSION" = "latest" ]; then
info "Fetching latest version..."
# Try website API first
VERSION=$(curl -s "$BASE_URL/api/latest" 2>/dev/null | grep -o '"version":"[^"]*"' | cut -d'"' -f4 || echo "")
# Fallback: GitHub API
if [ -z "$VERSION" ]; then
VERSION=$(curl -s "https://api.github.com/repos/Persistence-AI/Landing/releases/latest" 2>/dev/null | grep -o '"tag_name":"[^"]*"' | cut -d'"' -f4 | sed 's/^v//' || echo "")
fi
if [ -z "$VERSION" ]; then
warning "Could not fetch latest version, using 'latest'"
VERSION="latest"
else
info "Latest version: $VERSION"
fi
else
info "Installing version: $VERSION"
fi
# Build download URL - direct from GitHub Releases (like OpenCode)
info "Finding asset in GitHub Releases..."
# Query GitHub API to find the actual asset filename
if [ "$VERSION" = "latest" ]; then
RELEASE_URL="https://api.github.com/repos/Persistence-AI/Landing/releases/latest"
else
RELEASE_URL="https://api.github.com/repos/Persistence-AI/Landing/releases/tags/v$VERSION"
fi
# Try to get asset URL from GitHub API
ASSET_URL=$(curl -s "$RELEASE_URL" 2>/dev/null | \
grep -o '"browser_download_url":"[^"]*' | \
grep -i "$PLATFORM.*\.zip" | \
head -n1 | \
cut -d'"' -f4 || echo "")
if [ -n "$ASSET_URL" ]; then
DOWNLOAD_URL="$ASSET_URL"
info "Found asset via GitHub API"
else
# Fallback to standard URL pattern
if [ "$VERSION" = "latest" ]; then
DOWNLOAD_URL="https://github.com/Persistence-AI/Landing/releases/latest/download/persistenceai-$PLATFORM.zip"
else
DOWNLOAD_URL="https://github.com/Persistence-AI/Landing/releases/download/v$VERSION/persistenceai-$PLATFORM-v$VERSION.zip"
fi
warning "Could not find asset via API, using standard URL pattern"
fi
# Check if already installed
if command -v "$APP_NAME" >/dev/null 2>&1; then
EXISTING_PATH=$(command -v "$APP_NAME")
info "PersistenceAI is already installed at: $EXISTING_PATH"
CURRENT_VERSION=$("$APP_NAME" --version 2>/dev/null | head -n1 || echo "unknown")
info "Current version: $CURRENT_VERSION"
if [ "$VERSION" != "latest" ] && [ "$CURRENT_VERSION" = "$VERSION" ]; then
success "Version $VERSION is already installed!"
exit 0
fi
read -p "Upgrade now? (y/N): " UPGRADE
if [ "$UPGRADE" != "y" ] && [ "$UPGRADE" != "Y" ]; then
exit 0
fi
fi
# Create installation directory
info "Creating installation directory: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
# Download
info "Downloading PersistenceAI from: $DOWNLOAD_URL"
ZIP_PATH="$TEMP_DIR/$ZIP_NAME"
if ! curl -fsSL -o "$ZIP_PATH" "$DOWNLOAD_URL"; then
error "Download failed from: $DOWNLOAD_URL"
error ""
error "Please check:"
error "1. The version exists in GitHub Releases: https://github.com/Persistence-AI/Landing/releases"
error "2. The file name matches: persistenceai-$PLATFORM-v$VERSION.zip (or similar)"
error "3. Your internet connection is working"
exit 1
fi
success "Download completed"
# Verify download
if [ ! -f "$ZIP_PATH" ]; then
error "Downloaded file not found"
exit 1
fi
# Extract
info "Extracting archive..."
cd "$TEMP_DIR"
unzip -q "$ZIP_PATH" || tar -xzf "$ZIP_PATH" 2>/dev/null || {
error "Failed to extract archive. Please ensure unzip or tar is installed."
exit 1
}
# Find executable (could be in bin/ subdirectory or root)
EXE_PATH=""
if [ -f "bin/$APP_NAME" ]; then
EXE_PATH="bin/$APP_NAME"
elif [ -f "$APP_NAME" ]; then
EXE_PATH="$APP_NAME"
else
error "Executable not found in archive"
ls -la "$TEMP_DIR"
exit 1
fi
# Move to install directory
TARGET_PATH="$INSTALL_DIR/$APP_NAME"
mv "$EXE_PATH" "$TARGET_PATH"
chmod +x "$TARGET_PATH"
success "Extraction completed"
# Add to PATH
SHELL_RC=""
case "$SHELL" in
*/zsh) SHELL_RC="$HOME/.zshrc" ;;
*/bash) SHELL_RC="$HOME/.bashrc" ;;
*) SHELL_RC="$HOME/.profile" ;;
esac
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
info "Adding PersistenceAI to PATH in $SHELL_RC"
# Add export if not already present
if ! grep -q "$INSTALL_DIR" "$SHELL_RC" 2>/dev/null; then
echo "" >> "$SHELL_RC"
echo "# PersistenceAI" >> "$SHELL_RC"
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >> "$SHELL_RC"
fi
# Add to current session
export PATH="$PATH:$INSTALL_DIR"
success "Added to PATH"
else
info "PersistenceAI is already in PATH"
fi
# Verify installation
info "Verifying installation..."
if [ -f "$TARGET_PATH" ]; then
VERSION_OUTPUT=$("$TARGET_PATH" --version 2>/dev/null | head -n1 || echo "unknown")
echo ""
success "Installation successful!"
echo ""
info "PersistenceAI version: $VERSION_OUTPUT"
info "Installation location: $INSTALL_DIR"
echo ""
warning "Note: You may need to restart your terminal or run 'source $SHELL_RC' for PATH changes to take effect."
echo ""
info "To use PersistenceAI, open a new terminal and run: $APP_NAME"
info "For more information, visit: $BASE_URL/docs"
echo ""
else
error "Installation verification failed: executable not found"
exit 1
fi