forked from infernode-os/infernode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-linux.sh
More file actions
executable file
·326 lines (286 loc) · 11.2 KB
/
setup-linux.sh
File metadata and controls
executable file
·326 lines (286 loc) · 11.2 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
#!/bin/bash
#
# InferNode Setup — Linux (Ubuntu/Debian)
#
# Configures the LLM backend that Veltro needs to operate.
# Choose between an Anthropic API key or a local Ollama instance.
#
set -e
ROOT="$(cd "$(dirname "$0")" && pwd)"
# ── Colours (if terminal supports them) ────────────────────────────
if [[ -t 1 ]]; then
BOLD="\033[1m"
DIM="\033[2m"
GREEN="\033[32m"
YELLOW="\033[33m"
RED="\033[31m"
CYAN="\033[36m"
RESET="\033[0m"
else
BOLD="" DIM="" GREEN="" YELLOW="" RED="" CYAN="" RESET=""
fi
info() { printf "${CYAN}▸${RESET} %s\n" "$*"; return 0; }
ok() { printf "${GREEN}✓${RESET} %s\n" "$*"; return 0; }
warn() { printf "${YELLOW}!${RESET} %s\n" "$*"; return 0; }
fail() { printf "${RED}✗${RESET} %s\n" "$*"; exit 1; }
# ── Banner ─────────────────────────────────────────────────────────
printf "\n"
printf "${BOLD}InferNode Setup${RESET}\n"
printf "${DIM}Configure the LLM backend for Veltro${RESET}\n"
printf "\n"
# ── Choose backend ─────────────────────────────────────────────────
printf "Veltro needs an LLM to work. Choose your backend:\n"
printf "\n"
printf " ${BOLD}1)${RESET} Anthropic API key ${DIM}(recommended — best quality)${RESET}\n"
printf " ${BOLD}2)${RESET} Local model via Ollama ${DIM}(free, private, ~2–5 GB download)${RESET}\n"
printf "\n"
while true; do
printf "Enter ${BOLD}1${RESET} or ${BOLD}2${RESET}: "
read -r choice
case "$choice" in
1) BACKEND=api; break ;;
2) BACKEND=ollama; break ;;
*) warn "Please enter 1 or 2." ;;
esac
done
printf "\n"
# ── Helper: write key file inside Inferno FS ───────────────────────
write_key() {
local svc="$1" key="$2"
mkdir -p "$ROOT/lib/veltro/keys"
printf "%s" "$key" > "$ROOT/lib/veltro/keys/$svc"
chmod 600 "$ROOT/lib/veltro/keys/$svc"
return 0
}
# ── Path 1: Anthropic API ──────────────────────────────────────────
setup_anthropic() {
info "Anthropic API setup"
printf "\n"
# Check for existing key
existing=""
if [[ -n "$ANTHROPIC_API_KEY" ]]; then
existing="$ANTHROPIC_API_KEY"
elif [[ -f "$ROOT/lib/veltro/keys/anthropic" ]]; then
existing="$(cat "$ROOT/lib/veltro/keys/anthropic" 2>/dev/null)"
fi
if [[ -n "$existing" ]]; then
masked="${existing:0:8}...${existing: -4}"
ok "Found existing API key: $masked"
printf " Use this key? [Y/n] "
read -r yn
case "$yn" in
[Nn]*) existing="" ;;
*) ;;
esac
fi
if [[ -z "$existing" ]]; then
printf " Paste your Anthropic API key (starts with sk-ant-): "
read -r apikey
if [[ -z "$apikey" ]]; then
fail "No API key provided."
fi
else
apikey="$existing"
fi
# Validate key format
case "$apikey" in
sk-ant-*) ;;
*) warn "Key doesn't start with sk-ant-. Proceeding anyway." ;;
esac
# Quick validation
info "Validating API key..."
status=$(curl -s -o /dev/null -w "%{http_code}" \
-H "x-api-key: $apikey" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"claude-haiku-4-5-20251001","max_tokens":1,"messages":[{"role":"user","content":"hi"}]}' \
"https://api.anthropic.com/v1/messages" 2>/dev/null) || status="000"
case "$status" in
200) ok "API key is valid." ;;
401) fail "API key rejected (401 Unauthorized). Check your key and try again." ;;
000) warn "Could not reach api.anthropic.com — key saved but not validated." ;;
*) warn "Unexpected status $status — key saved but check your account." ;;
esac
# Store the key
write_key "anthropic" "$apikey"
ok "Key saved to lib/veltro/keys/anthropic"
export ANTHROPIC_API_KEY="$apikey"
# Offer to add to shell profile
printf "\n"
printf " Add ANTHROPIC_API_KEY to your shell profile? [y/N] "
read -r yn
case "$yn" in
[Yy]*)
shell_rc=""
if [[ -f "$HOME/.bashrc" ]]; then
shell_rc="$HOME/.bashrc"
elif [[ -f "$HOME/.zshrc" ]]; then
shell_rc="$HOME/.zshrc"
elif [[ -f "$HOME/.profile" ]]; then
shell_rc="$HOME/.profile"
fi
if [[ -n "$shell_rc" ]]; then
if ! grep -q "ANTHROPIC_API_KEY" "$shell_rc" 2>/dev/null; then
printf '\nexport ANTHROPIC_API_KEY="%s"\n' "$apikey" >> "$shell_rc"
ok "Added to $shell_rc"
else
warn "ANTHROPIC_API_KEY already in $shell_rc — not modified."
fi
else
warn "Could not find shell profile. Set it manually:"
printf ' export ANTHROPIC_API_KEY="%s"\n' "$apikey"
fi
;;
*) ;;
esac
printf "\n"
ok "Anthropic backend configured."
printf " Model: ${BOLD}claude-sonnet-4-5${RESET} (default, configurable at runtime)\n"
return 0
}
# ── Path 2: Ollama ─────────────────────────────────────────────────
setup_ollama() {
info "Ollama setup (local LLM)"
printf "\n"
# Check if Ollama is installed
if command -v ollama &>/dev/null; then
ok "Ollama is installed: $(command -v ollama)"
ollama_version=$(ollama --version 2>/dev/null || echo "unknown")
printf " Version: %s\n" "$ollama_version"
else
info "Ollama not found. Installing..."
printf "\n"
printf " Install via official installer? (requires curl + sudo) [Y/n] "
read -r yn
case "$yn" in
[Nn]*)
info "Install manually from https://ollama.com/download and re-run this script."
exit 0
;;
*) ;;
esac
curl -fsSL https://ollama.com/install.sh | sh
if ! command -v ollama &>/dev/null; then
fail "Ollama installation failed. Install from https://ollama.com/download and re-run."
fi
ok "Ollama installed."
fi
# Ensure Ollama is running
printf "\n"
info "Checking if Ollama is running..."
if curl -s -o /dev/null -w "%{http_code}" "http://localhost:11434/api/tags" 2>/dev/null | grep -q "200"; then
ok "Ollama is running."
else
info "Starting Ollama..."
# Try systemd first (common on Ubuntu)
if command -v systemctl &>/dev/null && systemctl list-unit-files ollama.service &>/dev/null 2>&1; then
sudo systemctl start ollama 2>/dev/null || true
sleep 2
fi
# Fall back to direct launch
if ! curl -s -o /dev/null "http://localhost:11434/api/tags" 2>/dev/null; then
ollama serve &>/dev/null &
OLLAMA_PID=$!
sleep 2
fi
if curl -s -o /dev/null "http://localhost:11434/api/tags" 2>/dev/null; then
ok "Ollama is running."
else
warn "Could not start Ollama. You may need to run 'ollama serve' manually."
fi
fi
# Choose a model
printf "\n"
printf "Choose a model to download:\n"
printf "\n"
printf " ${BOLD}1)${RESET} llama3.2:3b ${DIM}(~2 GB — fast, good for most tasks)${RESET}\n"
printf " ${BOLD}2)${RESET} llama3.1:8b ${DIM}(~5 GB — better quality, needs 8+ GB RAM)${RESET}\n"
printf " ${BOLD}3)${RESET} qwen2.5:7b ${DIM}(~4 GB — strong reasoning, good tool use)${RESET}\n"
printf " ${BOLD}4)${RESET} Custom ${DIM}(enter any Ollama model name)${RESET}\n"
printf "\n"
while true; do
printf "Enter choice [1]: "
read -r mchoice
mchoice="${mchoice:-1}"
case "$mchoice" in
1) MODEL="llama3.2:3b"; break ;;
2) MODEL="llama3.1:8b"; break ;;
3) MODEL="qwen2.5:7b"; break ;;
4)
printf " Model name: "
read -r MODEL
[[ -z "$MODEL" ]] && { warn "No model name given."; continue; }
break
;;
*) warn "Enter 1–4." ;;
esac
done
# Pull the model
printf "\n"
info "Pulling $MODEL (this may take a few minutes)..."
ollama pull "$MODEL"
ok "$MODEL is ready."
# Write Ollama config for Veltro
mkdir -p "$ROOT/lib/veltro"
cat > "$ROOT/lib/veltro/llm.cfg" <<EOF
# Veltro LLM configuration — generated by setup-linux.sh
backend=openai
url=http://localhost:11434/v1
model=$MODEL
EOF
ok "Config saved to lib/veltro/llm.cfg"
printf "\n"
ok "Ollama backend configured."
printf " Model: ${BOLD}$MODEL${RESET}\n"
printf " Endpoint: ${BOLD}http://localhost:11434/v1${RESET}\n"
printf "\n"
printf "${DIM} Tip: Ollama must be running before you start InferNode.${RESET}\n"
printf "${DIM} Start it with: ollama serve (or: sudo systemctl start ollama)${RESET}\n"
return 0
}
# ── Optional: Brave Search API key ─────────────────────────────────
setup_brave_search() {
printf "\n"
printf "${DIM}─────────────────────────────────────────────────${RESET}\n"
printf "\n"
printf "Veltro can search the web using the Brave Search API (optional).\n"
printf " Get a free key at: https://brave.com/search/api/\n"
printf "\n"
printf " Paste your Brave Search API key (or press Enter to skip): "
read -r bravekey
if [[ -n "$bravekey" ]]; then
write_key "brave" "$bravekey"
ok "Brave Search key saved."
else
info "Skipped. You can add it later to lib/veltro/keys/brave"
fi
return 0
}
# ── Dispatch ───────────────────────────────────────────────────────
case "$BACKEND" in
api) setup_anthropic ;;
ollama) setup_ollama ;;
*) ;;
esac
setup_brave_search
# ── Done ───────────────────────────────────────────────────────────
printf "\n"
printf "${DIM}─────────────────────────────────────────────────${RESET}\n"
printf "\n"
printf "${GREEN}${BOLD}Setup complete!${RESET}\n"
printf "\n"
# Detect emulator
EMU=""
if [[ -x "$ROOT/emu/Linux/o.emu" ]]; then
EMU="./emu/Linux/o.emu -r."
fi
if [[ -n "$EMU" ]]; then
printf "Launch InferNode:\n"
printf " cd %s\n" "$ROOT"
printf " %s\n" "$EMU"
else
printf "Build InferNode first:\n"
printf " ./build-linux-amd64.sh ${DIM}(x86_64)${RESET}\n"
printf " ./build-linux-arm64.sh ${DIM}(ARM64)${RESET}\n"
fi
printf "\n"