-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·192 lines (161 loc) · 4.93 KB
/
install.sh
File metadata and controls
executable file
·192 lines (161 loc) · 4.93 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
#!/bin/bash
set -e
# GPTCode CLI Installer
# Downloads the latest pre-built binary from GitHub releases
VERSION="${GPTCODE_VERSION:-latest}"
INSTALL_DIR="${GPTCODE_INSTALL_DIR:-$HOME/.local/bin}"
RELEASES_REPO="gptcode-cloud/cli-releases"
# Detect if we're being served as HTML (Jekyll fallback)
if [[ "$0" == *"sh"* ]] && [[ ! "$BASH_SOURCE" ]]; then
# Being sourced, try to download real script
SCRIPT_URL="https://raw.githubusercontent.com/${RELEASES_REPO%/*}/cli/main/install.sh"
if command -v curl &> /dev/null; then
exec curl -sSL "$SCRIPT_URL" | bash
elif command -v wget &> /dev/null; then
exec wget -qO- "$SCRIPT_URL" | bash
fi
fi
echo "🚀 GPTCode CLI Installer"
echo ""
# Detect OS and Architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
*)
echo "❌ Unsupported architecture: $ARCH"
exit 1
;;
esac
case "$OS" in
linux) OS="linux" ;;
darwin) OS="darwin" ;;
mingw*|msys*|cygwin*)
OS="windows"
;;
*)
echo "❌ Unsupported OS: $OS"
exit 1
;;
esac
echo "📦 Detected: $OS/$ARCH"
# Get latest version if not specified
if [ "$VERSION" = "latest" ]; then
echo "🔍 Fetching latest version..."
VERSION=$(curl -sSL "https://raw.githubusercontent.com/${RELEASES_REPO}/main/LATEST" 2>/dev/null || echo "")
if [ -z "$VERSION" ]; then
# Fallback to GitHub API
VERSION=$(curl -sSL "https://api.github.com/repos/${RELEASES_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$VERSION" ]; then
echo "❌ Could not determine latest version"
exit 1
fi
fi
echo "📥 Downloading GPTCode $VERSION..."
# Construct download URL
VERSION_NUM="${VERSION#v}"
if [ "$OS" = "windows" ]; then
ARCHIVE="gptcode_${VERSION_NUM}_${OS}_${ARCH}.zip"
else
ARCHIVE="gptcode_${VERSION_NUM}_${OS}_${ARCH}.tar.gz"
fi
DOWNLOAD_URL="https://github.com/${RELEASES_REPO}/releases/download/${VERSION}/${ARCHIVE}"
# Create temp directory
TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT
# Download archive
echo " URL: $DOWNLOAD_URL"
curl -sSL "$DOWNLOAD_URL" -o "$TMP_DIR/$ARCHIVE"
if [ ! -s "$TMP_DIR/$ARCHIVE" ]; then
echo "❌ Download failed or file is empty"
exit 1
fi
# Extract
echo "📂 Extracting..."
cd "$TMP_DIR"
if [ "$OS" = "windows" ]; then
unzip -q "$ARCHIVE"
else
tar -xzf "$ARCHIVE"
fi
# Find binary
BINARY=$(find . -name 'gptcode*' -type f ! -name '*.tar.gz' ! -name '*.zip' | head -1)
if [ -z "$BINARY" ]; then
echo "❌ Binary not found in archive"
exit 1
fi
# Install
echo "📁 Installing to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"
chmod +x "$BINARY"
mv "$BINARY" "$INSTALL_DIR/gptcode"
# Create gt alias (symlink)
ln -sf "$INSTALL_DIR/gptcode" "$INSTALL_DIR/gt"
# Auto-configure PATH if needed
add_to_path() {
local shell_config="$1"
local path_line="export PATH=\"\$PATH:$INSTALL_DIR\""
if [ -f "$shell_config" ]; then
if ! grep -q "$INSTALL_DIR" "$shell_config" 2>/dev/null; then
echo "" >> "$shell_config"
echo "# Added by GPTCode installer" >> "$shell_config"
echo "$path_line" >> "$shell_config"
echo " ✓ Added to $shell_config"
return 0
fi
fi
return 1
}
# Verify installation
if [ -x "$INSTALL_DIR/gptcode" ]; then
echo ""
echo "✅ GPTCode installed successfully!"
echo ""
echo " Location: $INSTALL_DIR/gptcode"
echo " Alias: $INSTALL_DIR/gt"
echo ""
# Auto-configure PATH if not already set
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
echo "📝 Configuring PATH..."
# Try to add to the appropriate shell config
added=false
# Detect current shell and add to config
if [ -n "$ZSH_VERSION" ] || [ "$SHELL" = "/bin/zsh" ] || [ "$SHELL" = "/usr/bin/zsh" ]; then
add_to_path "$HOME/.zshrc" && added=true
elif [ -n "$BASH_VERSION" ] || [ "$SHELL" = "/bin/bash" ] || [ "$SHELL" = "/usr/bin/bash" ]; then
add_to_path "$HOME/.bashrc" && added=true
fi
# Fallback to .profile if nothing else worked
if [ "$added" = false ]; then
add_to_path "$HOME/.profile" && added=true
fi
if [ "$added" = true ]; then
echo ""
echo " ⚠️ Restart your terminal or run:"
echo ""
echo " source ~/.zshrc # or ~/.bashrc"
echo ""
fi
fi
echo "🎉 Installation complete!"
echo ""
echo " gt --help # Show help"
echo ""
echo " Quick start (recommended):"
echo " gt setup -y # Quick setup with defaults"
echo " gt key openrouter # Add your API key"
echo " gt run \"hello\" # Test it works"
echo ""
echo " Optional - Enable web search:"
echo " gt key tavily # Get key from https://tavily.com"
echo " gt key exa # Get key from https://exa.ai"
echo ""
echo " Or use interactive setup:"
echo " gt setup # Guided setup"
else
echo "❌ Installation failed"
exit 1
fi