This repository was archived by the owner on Aug 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-Linux.sh
More file actions
executable file
·293 lines (268 loc) · 12.4 KB
/
Copy pathInstall-Linux.sh
File metadata and controls
executable file
·293 lines (268 loc) · 12.4 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
#!/usr/bin/env bash
# Gemini Pilot Installer for Linux
# Usage: chmod +x Install-Linux.sh && ./Install-Linux.sh
cd "$(dirname "$0")" || exit 1
# ── Timing ───────────────────────────────────────────────
SECONDS=0
# ── Colors ───────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
CYAN='\033[0;36m'; BOLD='\033[1m'; RESET='\033[0m'
# ── Helpers ──────────────────────────────────────────────
info() { printf " ${CYAN}%s${RESET}\n" "$*"; }
success() { printf " ${GREEN}OK${RESET} %s\n" "$*"; }
warn() { printf " ${YELLOW}WARNING:${RESET} %s\n" "$*"; }
fail() { printf " ${RED}ERROR:${RESET} %s\n" "$*"; }
step() { printf "\n ${BOLD}> %s${RESET}\n ─────────────────────────────\n" "$1"; }
die() { fail "$1"; echo ""; echo " Installation aborted."; exit 1; }
# Use sudo only when not already root
SUDO=""
if [ "$(id -u)" -ne 0 ]; then
if command -v sudo &>/dev/null; then
SUDO="sudo"
else
warn "Not running as root and sudo is not available."
warn "Some steps may fail. Consider running as root or installing sudo."
fi
fi
# ── Banner ───────────────────────────────────────────────
clear
echo ""
echo " ╔══════════════════════════════════════════╗"
echo " ║ ║"
echo " ║ Gemini Pilot -- Auto Installer (Linux) ║"
echo " ║ ║"
echo " ║ Do not close this window! ║"
echo " ║ ║"
echo " ╚══════════════════════════════════════════╝"
echo ""
# ── Detect platform ──────────────────────────────────────
ARCH="$(uname -m)"
if [ -f /etc/os-release ]; then
# shellcheck disable=SC1091
. /etc/os-release
DISTRO_INFO="${PRETTY_NAME:-${NAME:-Linux}} (${ARCH})"
else
DISTRO_INFO="Linux $(uname -r) (${ARCH})"
fi
info "Detected: ${DISTRO_INFO}"
echo ""
TOTAL_STEPS=8
ERRORS=0
NODE_MIN_MAJOR=20
# ── Step 1: curl ─────────────────────────────────────────
step "1/${TOTAL_STEPS} Checking curl..."
if command -v curl &>/dev/null; then
success "curl found"
else
info "Installing curl..."
if command -v apt-get &>/dev/null; then
if ! $SUDO apt-get update -qq || ! $SUDO apt-get install -y curl; then
die "Failed to install curl."
fi
elif command -v dnf &>/dev/null; then
$SUDO dnf install -y curl || die "Failed to install curl."
elif command -v yum &>/dev/null; then
$SUDO yum install -y curl || die "Failed to install curl."
elif command -v zypper &>/dev/null; then
$SUDO zypper install -y curl || die "Failed to install curl."
elif command -v pacman &>/dev/null; then
$SUDO pacman -S --noconfirm curl || die "Failed to install curl."
elif command -v apk &>/dev/null; then
$SUDO apk add curl || die "Failed to install curl."
else
die "curl is required but no supported package manager was found to install it."
fi
success "curl installed"
fi
# ── Step 2: git ──────────────────────────────────────────
step "2/${TOTAL_STEPS} Checking git..."
if command -v git &>/dev/null; then
success "git $(git --version | awk '{print $3}') found"
else
info "Installing git..."
if command -v apt-get &>/dev/null; then
$SUDO apt-get install -y git || die "Failed to install git."
elif command -v dnf &>/dev/null; then
$SUDO dnf install -y git || die "Failed to install git."
elif command -v yum &>/dev/null; then
$SUDO yum install -y git || die "Failed to install git."
elif command -v zypper &>/dev/null; then
$SUDO zypper install -y git || die "Failed to install git."
elif command -v pacman &>/dev/null; then
$SUDO pacman -S --noconfirm git || die "Failed to install git."
elif command -v apk &>/dev/null; then
$SUDO apk add git || die "Failed to install git."
else
die "git is required but no supported package manager was found to install it."
fi
success "git installed"
fi
# ── Step 3: Node.js ─────────────────────────────────────
step "3/${TOTAL_STEPS} Checking Node.js..."
install_node() {
if command -v apt-get &>/dev/null; then
info "Detected apt (Debian/Ubuntu)..."
if curl -fsSL https://deb.nodesource.com/setup_22.x | $SUDO -E bash -; then
$SUDO apt-get install -y nodejs || die "Failed to install Node.js via apt."
else
fail "NodeSource setup script failed (network issue?)."
die "Install Node.js >= 20 manually: https://nodejs.org"
fi
elif command -v dnf &>/dev/null; then
info "Detected dnf (Fedora/RHEL)..."
if curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO bash -; then
$SUDO dnf install -y nodejs || die "Failed to install Node.js via dnf."
else
fail "NodeSource setup script failed (network issue?)."
die "Install Node.js >= 20 manually: https://nodejs.org"
fi
elif command -v yum &>/dev/null; then
info "Detected yum (CentOS/RHEL)..."
if curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO bash -; then
$SUDO yum install -y nodejs || die "Failed to install Node.js via yum."
else
fail "NodeSource setup script failed (network issue?)."
die "Install Node.js >= 20 manually: https://nodejs.org"
fi
elif command -v zypper &>/dev/null; then
info "Detected zypper (openSUSE)..."
if curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO bash -; then
$SUDO zypper install -y nodejs || die "Failed to install Node.js via zypper."
else
fail "NodeSource setup script failed (network issue?)."
die "Install Node.js >= 20 manually: https://nodejs.org"
fi
elif command -v pacman &>/dev/null; then
info "Detected pacman (Arch)..."
$SUDO pacman -S --noconfirm nodejs npm || die "Failed to install Node.js via pacman."
elif command -v apk &>/dev/null; then
info "Detected apk (Alpine)..."
$SUDO apk add nodejs npm || die "Failed to install Node.js via apk."
else
die "No supported package manager found. Please install Node.js >= 20 manually from https://nodejs.org"
fi
}
if command -v node &>/dev/null; then
NODE_VER="$(node --version)"
NODE_MAJOR="$(echo "$NODE_VER" | sed 's/^v//' | cut -d. -f1)"
if [ "$NODE_MAJOR" -ge "$NODE_MIN_MAJOR" ] 2>/dev/null; then
success "Node.js ${NODE_VER} found (>= v${NODE_MIN_MAJOR})"
else
warn "Node.js ${NODE_VER} is too old (need >= v${NODE_MIN_MAJOR}). Upgrading..."
install_node
success "Node.js upgraded to $(node --version)"
fi
else
info "Node.js not found. Installing..."
install_node
success "Node.js installed: $(node --version)"
fi
# ── Step 4: Gemini CLI ───────────────────────────────────
step "4/${TOTAL_STEPS} Checking Gemini CLI..."
if command -v gemini &>/dev/null; then
success "Gemini CLI already installed"
else
info "Installing Gemini CLI..."
if npm install -g @google/gemini-cli 2>/dev/null; then
success "Gemini CLI installed"
else
info "Retrying with $SUDO..."
if $SUDO npm install -g @google/gemini-cli; then
success "Gemini CLI installed (with elevated privileges)"
else
fail "Could not install Gemini CLI. You may need to install it manually."
ERRORS=$((ERRORS + 1))
fi
fi
fi
# Permanently add npm global bin to PATH in shell rc files
NPM_BIN="$(npm config get prefix)/bin"
for rc in ~/.bashrc ~/.profile ~/.zshrc; do
if [ -f "$rc" ]; then
if ! grep -q "$NPM_BIN" "$rc" 2>/dev/null; then
echo "export PATH=\"$NPM_BIN:\$PATH\"" >> "$rc"
info "Added $NPM_BIN to $rc"
fi
fi
done
export PATH="$NPM_BIN:$PATH"
# ── Step 5: Dependencies ────────────────────────────────
step "5/${TOTAL_STEPS} Installing dependencies..."
if npm install --no-fund --no-audit; then
success "Dependencies installed"
else
die "npm install failed. Check your network connection and try again."
fi
# ── Step 6: Build ────────────────────────────────────────
step "6/${TOTAL_STEPS} Building project..."
if npm run build; then
success "Build complete"
else
die "Build failed. Check the error messages above."
fi
# ── Step 7: Register gp command ──────────────────────────
step "7/${TOTAL_STEPS} Registering 'gp' command..."
if npm link 2>/dev/null; then
success "'gp' command registered globally"
elif $SUDO npm link 2>/dev/null; then
success "'gp' command registered globally (with elevated privileges)"
else
fail "'npm link' failed."
warn "Fallback: add this directory to your PATH manually:"
warn " echo 'export PATH=\"\$PATH:$(pwd)/dist/cli\"' >> ~/.bashrc && source ~/.bashrc"
warn "Or run: node $(pwd)/dist/cli/index.js directly."
ERRORS=$((ERRORS + 1))
fi
# Ensure npm link bin directory is permanently in PATH
NPM_LINK_BIN="$(npm config get prefix)/bin"
for rc in ~/.bashrc ~/.profile ~/.zshrc; do
if [ -f "$rc" ]; then
if ! grep -q "$NPM_LINK_BIN" "$rc" 2>/dev/null; then
echo "export PATH=\"$NPM_LINK_BIN:\$PATH\"" >> "$rc"
info "Added $NPM_LINK_BIN to $rc"
fi
fi
done
export PATH="$NPM_LINK_BIN:$PATH"
# ── Step 8: Setup + Doctor ───────────────────────────────
step "8/${TOTAL_STEPS} Running initial setup..."
if node dist/cli/index.js setup; then
success "Setup complete"
else
fail "Setup had issues. You can re-run: gp setup"
ERRORS=$((ERRORS + 1))
fi
# ── Doctor check ─────────────────────────────────────────
echo ""
info "Running 'gp doctor' to verify installation..."
if command -v gp &>/dev/null; then
gp doctor || warn "'gp doctor' reported issues (see above)."
else
node dist/cli/index.js doctor 2>/dev/null || warn "Could not run doctor check."
fi
# ── Done ─────────────────────────────────────────────────
ELAPSED=$SECONDS
MINS=$((ELAPSED / 60))
SECS=$((ELAPSED % 60))
echo ""
if [ "$ERRORS" -eq 0 ]; then
echo " ╔══════════════════════════════════════════╗"
echo " ║ ║"
printf ' ║ %sInstallation Complete!%s ║\n' "$GREEN" "$RESET"
echo " ║ ║"
echo " ║ Open a terminal and try: ║"
echo " ║ ║"
echo " ║ gp harness (start session) ║"
echo " ║ gp ask \"question\" (quick query) ║"
echo " ║ gp team 3 (multi-agent) ║"
echo " ║ gp doctor (check install) ║"
echo " ║ gp --help (all commands) ║"
echo " ║ ║"
echo " ╚══════════════════════════════════════════╝"
else
echo " ╔══════════════════════════════════════════╗"
printf ' ║ %sInstallation finished with %s warning(s)%s ║\n' "$YELLOW" "$ERRORS" "$RESET"
echo " ║ Review the messages above. ║"
echo " ╚══════════════════════════════════════════╝"
fi
printf "\n Completed in %dm %ds\n\n" "$MINS" "$SECS"