-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
267 lines (242 loc) · 10.1 KB
/
Copy pathbootstrap.sh
File metadata and controls
267 lines (242 loc) · 10.1 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
#!/usr/bin/env bash
# bootstrap.sh — Synapse_COR zero-assumption bootstrapper
#
# Runs BEFORE install.sh. Ensures all prerequisites exist on a fresh system.
# Detects OS, installs Node.js via nvm (no sudo), installs gemini-cli,
# optionally installs Ollama, then calls install.sh.
#
# Usage:
# bash bootstrap.sh # interactive
# bash bootstrap.sh --non-interactive # CI / scripted (chooses safest defaults)
# bash bootstrap.sh --with-ollama # also install Ollama + pull llama3.2
# bash bootstrap.sh --skip-node # skip Node.js / Gemini CLI install
#
# Requires: bash 3.2+, curl (for nvm/ollama installers), git (already needed to clone)
# Does NOT require: sudo, root, or any pre-existing tooling
set -euo pipefail
# ── Arg parsing ────────────────────────────────────────────────────────────────
NON_INTERACTIVE=0
WITH_OLLAMA=0
SKIP_NODE=0
for arg in "$@"; do
case "$arg" in
--non-interactive) NON_INTERACTIVE=1 ;;
--with-ollama) WITH_OLLAMA=1 ;;
--skip-node) SKIP_NODE=1 ;;
--help)
cat <<'HELP'
bootstrap.sh — Synapse_COR zero-assumption bootstrapper
Flags:
--non-interactive Skip all prompts, choose safe defaults (for CI)
--with-ollama Also install Ollama and pull llama3.2 (~2GB download)
--skip-node Skip Node.js / Gemini CLI setup entirely
--help Show this message
Installs:
1. Node.js 20 via nvm (no sudo, user-local)
2. @google/gemini-cli (free LLM access, no API key needed)
3. [optional] Ollama + llama3.2
4. Calls bash install.sh to complete Synapse_COR setup
To uninstall: rm -rf ~/.synapse-forge ~/.nvm (gemini-cli: npm uninstall -g @google/gemini-cli)
HELP
exit 0
;;
esac
done
# ── Colors ─────────────────────────────────────────────────────────────────────
CYAN='\033[0;36m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; RESET='\033[0m'
info() { printf "${CYAN}[bootstrap]${RESET} %s\n" "$*"; }
ok() { printf "${GREEN}[bootstrap] OK:${RESET} %s\n" "$*"; }
warn() { printf "${YELLOW}[bootstrap] WARN:${RESET} %s\n" "$*"; }
err() { printf "${RED}[bootstrap] ERR:${RESET} %s\n" "$*"; }
ask() { printf "${CYAN}[bootstrap] ?${RESET} %s [y/N]: " "$*"; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ── OS detection ───────────────────────────────────────────────────────────────
OS="unknown"
case "$(uname -s)" in
Darwin) OS="macos" ;;
Linux) OS="linux" ;;
MINGW*|MSYS*|CYGWIN*) OS="windows" ;;
esac
info "Detected OS: $OS"
if [[ "$OS" == "windows" ]]; then
warn "Windows detected. This script runs inside Git Bash or WSL."
warn "If you see errors, ensure you are running in Git Bash (https://git-scm.com/download/win)"
warn "or WSL (run: wsl --install in PowerShell as Admin, then reopen this script in WSL)."
fi
# ── Python check ───────────────────────────────────────────────────────────────
PYTHON=""
for py in python3 python3.12 python3.11 python3.10 python3.9 python; do
if command -v "$py" &>/dev/null && "$py" -c "import sys; sys.exit(0 if sys.version_info >= (3,9) else 1)" 2>/dev/null; then
PYTHON="$py"
break
fi
done
if [[ -z "$PYTHON" ]]; then
err "Python 3.9+ not found. Synapse_COR requires Python 3.9 or later."
echo ""
case "$OS" in
macos)
echo " Install options:"
echo " A) Homebrew: brew install python@3.12"
echo " (Install Homebrew first: /bin/bash -c \"\$(curl -fsSL https://brew.sh/install.sh)\")"
echo " B) Direct: https://www.python.org/downloads/macos/"
;;
linux)
echo " Install options:"
echo " A) Ubuntu/Debian: sudo apt install -y python3"
echo " B) Fedora/RHEL: sudo dnf install -y python3"
;;
windows)
echo " Install options:"
echo " A) Microsoft Store: search 'Python 3.12'"
echo " B) Direct: https://www.python.org/downloads/windows/"
echo " (Check 'Add Python to PATH' during install)"
;;
esac
echo ""
echo "After installing Python 3.9+, re-run: bash bootstrap.sh"
exit 1
else
ok "Python found: $($PYTHON --version 2>&1)"
fi
# ── Node.js / Gemini CLI setup ─────────────────────────────────────────────────
if [[ $SKIP_NODE -eq 0 ]]; then
NEED_NODE=0
if ! command -v node &>/dev/null; then
NEED_NODE=1
else
NODE_MAJOR=$(node --version 2>/dev/null | tr -d 'v' | cut -d. -f1 || echo "0")
if [[ "$NODE_MAJOR" -lt 18 ]]; then
warn "Node.js found but version is below 18 (found: $(node --version)). Gemini CLI requires Node 18+."
NEED_NODE=1
else
ok "Node.js found: $(node --version)"
fi
fi
if [[ $NEED_NODE -eq 1 ]]; then
INSTALL_NODE=1
if [[ $NON_INTERACTIVE -eq 0 ]]; then
ask "Install Node.js 20 via nvm (no sudo, user-local)?"
read -r CONFIRM 2>/dev/null || CONFIRM="n"
[[ "${CONFIRM,,}" == "y" ]] || INSTALL_NODE=0
fi
if [[ $INSTALL_NODE -eq 1 ]]; then
if [[ "$OS" == "windows" ]]; then
warn "On Windows, install Node.js manually: https://nodejs.org (LTS version)"
warn "Then re-run this script."
else
info "Installing nvm (Node Version Manager)..."
# Use the stable nvm release
NVM_VERSION="v0.39.7"
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh" | bash
# Load nvm in current shell session
export NVM_DIR="$HOME/.nvm"
# shellcheck disable=SC1091
[[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
info "Installing Node.js 20 LTS..."
nvm install 20
nvm use 20
ok "Node.js installed: $(node --version)"
fi
else
warn "Skipped Node.js install. Gemini CLI (free LLM path) will not be available."
warn "You can still use Ollama (local) or set an API key env var."
fi
fi
# Install Gemini CLI
if command -v node &>/dev/null; then
if command -v gemini &>/dev/null || command -v gemini-cli &>/dev/null; then
ok "Gemini CLI already installed"
else
INSTALL_GEMINI=1
if [[ $NON_INTERACTIVE -eq 0 ]]; then
ask "Install @google/gemini-cli (free LLM access, no API key needed)?"
read -r CONFIRM 2>/dev/null || CONFIRM="n"
[[ "${CONFIRM,,}" == "y" ]] || INSTALL_GEMINI=0
fi
if [[ $INSTALL_GEMINI -eq 1 ]]; then
info "Installing @google/gemini-cli..."
npm install -g @google/gemini-cli
ok "Gemini CLI installed: $(gemini --version 2>/dev/null || echo 'ok')"
echo ""
info "Gemini CLI is now available in two modes:"
echo " Free mode (no sign-in): works immediately after install"
echo " OAuth mode (1000 req/day): run 'gemini' once and sign in with a Google account"
echo ""
fi
fi
fi
fi
# ── Ollama (optional) ──────────────────────────────────────────────────────────
if [[ $WITH_OLLAMA -eq 1 ]]; then
if command -v ollama &>/dev/null; then
ok "Ollama already installed: $(ollama --version 2>/dev/null | head -1)"
else
info "Installing Ollama (local LLM runner)..."
case "$OS" in
macos|linux)
curl -fsSL https://ollama.com/install.sh | sh
ok "Ollama installed"
;;
windows)
warn "On Windows, install Ollama manually: https://ollama.com"
warn "Download the Windows installer, run it, then continue."
;;
esac
fi
if command -v ollama &>/dev/null; then
info "Pulling llama3.2 model (~2GB download — this may take a few minutes)..."
ollama pull llama3.2 && ok "llama3.2 model ready" || warn "ollama pull failed — you can retry manually: ollama pull llama3.2"
fi
elif [[ $NON_INTERACTIVE -eq 0 && $SKIP_NODE -eq 0 ]]; then
# Offer Ollama as an alternative if no Node.js
if ! command -v node &>/dev/null; then
echo ""
ask "No Node.js available. Install Ollama instead for local LLM access?"
read -r CONFIRM 2>/dev/null || CONFIRM="n"
if [[ "${CONFIRM,,}" == "y" ]]; then
case "$OS" in
macos|linux)
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3.2 || true
;;
*)
warn "Install Ollama manually: https://ollama.com"
;;
esac
fi
fi
fi
# ── Run install.sh ─────────────────────────────────────────────────────────────
echo ""
info "Prerequisites check complete. Running Synapse_COR installer..."
echo ""
INSTALL_ARGS=()
[[ $NON_INTERACTIVE -eq 1 ]] && INSTALL_ARGS+=("--non-interactive")
bash "$SCRIPT_DIR/install.sh" "${INSTALL_ARGS[@]}"
# ── Final PATH reminder ────────────────────────────────────────────────────────
echo ""
ok "Bootstrap complete."
echo ""
info "If 'synapse-cor' is not found after install, add to PATH:"
echo ""
case "$OS" in
macos)
echo " echo 'export PATH=\"\$HOME/.synapse-forge/bin:\$PATH\"' >> ~/.zshrc"
echo " source ~/.zshrc"
;;
linux)
echo " echo 'export PATH=\"\$HOME/.synapse-forge/bin:\$PATH\"' >> ~/.bashrc"
echo " source ~/.bashrc"
;;
windows)
echo " Add %USERPROFILE%\\.synapse-forge\\bin to your Windows PATH via System Settings."
;;
esac
echo ""
info "If nvm was just installed, you may also need:"
echo " source ~/.nvm/nvm.sh"
echo ""
info "Test everything works:"
echo " synapse-cor detect"
echo " synapse-cor run \"hello\""