forked from arozumenko/wikis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·403 lines (351 loc) · 14 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·403 lines (351 loc) · 14 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/env bash
#
# Wikis — one-command installer
# Usage: curl -fsSL https://raw.githubusercontent.com/arozumenko/wikis/main/install.sh | bash
#
set -euo pipefail
RAW_URL="https://raw.githubusercontent.com/arozumenko/wikis/main"
INSTALL_DIR="${WIKIS_DIR:-./wikis}"
# ── Colors ──────────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m'
info() { echo -e "${CYAN}▸${NC} $1"; }
ok() { echo -e "${GREEN}✓${NC} $1"; }
warn() { echo -e "${YELLOW}!${NC} $1"; }
err() { echo -e "${RED}✗${NC} $1" >&2; }
header(){ echo -e "\n${BOLD}$1${NC}"; }
# ── Ensure we can read user input (works when piped via curl) ─────
if [ -t 0 ]; then
INPUT_FD=0
else
if ! exec 3</dev/tty 2>/dev/null; then
err "Cannot open terminal for input. Run with: bash <(curl -fsSL URL)"
exit 1
fi
INPUT_FD=3
fi
prompt() {
local _prompt="$1" _var="$2"
printf "%s" "$_prompt"
IFS= read -r "$_var" <&${INPUT_FD}
}
prompt_secret() {
local _prompt="$1" _var="$2"
printf "%s" "$_prompt"
IFS= read -rs "$_var" <&${INPUT_FD}
echo ""
}
# ── Preflight ───────────────────────────────────────────────────────
header "🔍 Checking prerequisites..."
for cmd in docker openssl curl; do
if ! command -v "$cmd" &>/dev/null; then
err "$cmd is required but not installed."
exit 1
fi
done
if ! docker compose version &>/dev/null; then
err "docker compose (v2) is required. Install Docker Desktop or the compose plugin."
exit 1
fi
if ! docker info &>/dev/null; then
err "Docker daemon is not running."
case "$(uname -s)" in
Darwin) err "Start Docker Desktop: open -a Docker" ;;
Linux) err "Start the daemon: sudo systemctl start docker" ;;
*) err "Please start the Docker daemon before running this installer." ;;
esac
exit 1
fi
ok "All prerequisites found"
# ── Create install directory ──────────────────────────────────────
header "📦 Setting up Wikis..."
if [ -d "$INSTALL_DIR" ]; then
warn "Directory $INSTALL_DIR already exists."
prompt " Overwrite? [y/N] " overwrite
if [[ ! "$overwrite" =~ ^[Yy]$ ]]; then
echo "Aborted."; exit 0
fi
rm -rf "$INSTALL_DIR"
fi
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
info "Downloading docker-compose.yml..."
curl -fsSL "$RAW_URL/docker-compose.yml" -o docker-compose.yml
ok "Setup directory ready at $INSTALL_DIR"
# ── Port Configuration ────────────────────────────────────────────
header "🌐 Port Configuration"
echo ""
prompt "Web app port [3000]: " WEB_PORT
WEB_PORT="${WEB_PORT:-3000}"
prompt "Backend API port [8000]: " API_PORT
API_PORT="${API_PORT:-8000}"
if ! [[ "$WEB_PORT" =~ ^[0-9]+$ ]] || ! [[ "$API_PORT" =~ ^[0-9]+$ ]]; then
err "Ports must be numbers."
exit 1
fi
if [ "$WEB_PORT" -lt 1 ] || [ "$WEB_PORT" -gt 65535 ] || [ "$API_PORT" -lt 1 ] || [ "$API_PORT" -gt 65535 ]; then
err "Ports must be between 1 and 65535."
exit 1
fi
if lsof -i :"$WEB_PORT" &>/dev/null; then
warn "Port $WEB_PORT is already in use."
prompt " Continue anyway? [y/N] " port_continue
if [[ ! "$port_continue" =~ ^[Yy]$ ]]; then
echo "Aborted. Re-run and choose a different port."; exit 0
fi
fi
if lsof -i :"$API_PORT" &>/dev/null; then
warn "Port $API_PORT is already in use."
prompt " Continue anyway? [y/N] " port_continue
if [[ ! "$port_continue" =~ ^[Yy]$ ]]; then
echo "Aborted. Re-run and choose a different port."; exit 0
fi
fi
ok "Ports: web=$WEB_PORT, api=$API_PORT"
# ── Public URL ────────────────────────────────────────────────────
header "🌍 Public URL"
echo ""
echo " The URL users will open in their browser."
echo " Examples: http://localhost:${WEB_PORT}, http://192.168.1.50:${WEB_PORT}, https://wikis.example.com"
echo ""
prompt "Public URL [http://localhost:${WEB_PORT}]: " PUBLIC_URL
PUBLIC_URL="${PUBLIC_URL:-http://localhost:${WEB_PORT}}"
# Strip trailing slash
PUBLIC_URL="${PUBLIC_URL%/}"
# Extract scheme and host (without port) for constructing other URLs
PUBLIC_SCHEME="${PUBLIC_URL%%://*}"
PUBLIC_HOST_PORT="${PUBLIC_URL#*://}"
PUBLIC_HOST="${PUBLIC_HOST_PORT%%:*}"
ok "Public URL: $PUBLIC_URL"
# ── LLM Provider ───────────────────────────────────────────────────
header "🤖 LLM Provider Configuration"
echo ""
echo " 1) OpenAI (gpt-4o-mini, gpt-4o)"
echo " 2) Anthropic (claude-sonnet-4-6, claude-haiku-4-5)"
echo " 3) Google Gemini (gemini-2.5-pro, gemini-2.0-flash)"
echo " 4) AWS Bedrock (Claude, Titan — uses IAM or access keys)"
echo " 5) Azure OpenAI (OpenAI-compatible endpoint)"
echo " 6) Ollama (local, no API key needed)"
echo " 7) Skip (configure later in .env)"
echo ""
prompt "Choose provider [1-7, default: 7]: " provider_choice
LLM_PROVIDER=""
LLM_API_KEY=""
LLM_MODEL=""
LLM_MODEL_LOW=""
EMBEDDING_MODEL=""
AWS_REGION=""
AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
LLM_API_BASE=""
# Helper: prompt for model names with defaults
prompt_models() {
local default_model="$1" default_low="$2" default_embed="$3"
echo ""
prompt "LLM model [${default_model}]: " LLM_MODEL
LLM_MODEL="${LLM_MODEL:-$default_model}"
prompt "LLM model low tier (quality checks) [${default_low}]: " LLM_MODEL_LOW
LLM_MODEL_LOW="${LLM_MODEL_LOW:-$default_low}"
prompt "Embedding model [${default_embed}]: " EMBEDDING_MODEL
EMBEDDING_MODEL="${EMBEDDING_MODEL:-$default_embed}"
}
case "${provider_choice:-7}" in
1)
LLM_PROVIDER="openai"
prompt_secret "OpenAI API key: " LLM_API_KEY
if [ -z "$LLM_API_KEY" ]; then
warn "No API key provided. Edit .env later to add it."
fi
prompt_models "gpt-4o-mini" "gpt-4o-mini" "text-embedding-3-large"
;;
2)
LLM_PROVIDER="anthropic"
prompt_secret "Anthropic API key: " LLM_API_KEY
if [ -z "$LLM_API_KEY" ]; then
warn "No API key provided. Edit .env later to add it."
fi
warn "Anthropic doesn't provide embeddings — set OPENAI_API_KEY in .env for embeddings, or use Ollama."
prompt_models "claude-sonnet-4-6" "claude-haiku-4-5" "text-embedding-3-large"
;;
3)
LLM_PROVIDER="gemini"
prompt_secret "Google AI API key: " LLM_API_KEY
if [ -z "$LLM_API_KEY" ]; then
warn "No API key provided. Edit .env later to add it."
fi
prompt_models "gemini-2.5-pro" "gemini-2.0-flash" "models/text-embedding-004"
;;
4)
LLM_PROVIDER="bedrock"
LLM_API_KEY="not-needed"
prompt "AWS region [us-east-1]: " AWS_REGION
AWS_REGION="${AWS_REGION:-us-east-1}"
echo ""
info "Bedrock can use IAM roles, instance profiles, or explicit keys."
prompt "AWS access key ID (leave empty for IAM role): " AWS_ACCESS_KEY_ID
if [ -n "$AWS_ACCESS_KEY_ID" ]; then
prompt_secret "AWS secret access key: " AWS_SECRET_ACCESS_KEY
else
info "Using default AWS credential chain (IAM role, env vars, ~/.aws/credentials)."
fi
# Use region-appropriate model prefix (us/eu/ap)
BEDROCK_PREFIX="us"
case "$AWS_REGION" in
eu-*) BEDROCK_PREFIX="eu" ;;
ap-*) BEDROCK_PREFIX="ap" ;;
esac
prompt_models "${BEDROCK_PREFIX}.anthropic.claude-sonnet-4-6-20250514-v1:0" "${BEDROCK_PREFIX}.anthropic.claude-haiku-4-5-20251001-v1:0" "amazon.titan-embed-text-v2:0"
;;
5)
LLM_PROVIDER="custom"
echo ""
info "Azure OpenAI uses an OpenAI-compatible endpoint."
prompt "Azure OpenAI endpoint (e.g. https://YOUR.openai.azure.com/openai/deployments/YOUR-DEPLOYMENT/): " LLM_API_BASE
prompt_secret "Azure OpenAI API key: " LLM_API_KEY
if [ -z "$LLM_API_BASE" ] || [ -z "$LLM_API_KEY" ]; then
warn "Missing endpoint or key. Edit .env later to complete setup."
fi
prompt_models "gpt-4o-mini" "gpt-4o-mini" "text-embedding-3-large"
;;
6)
LLM_PROVIDER="ollama"
LLM_API_KEY="not-needed"
info "Make sure Ollama is running: ollama pull <model>"
prompt_models "llama3.2" "llama3.2" "nomic-embed-text"
;;
7|"")
info "Skipping LLM config — edit .env before generating wikis."
;;
*)
warn "Invalid choice, skipping LLM config — edit .env later."
;;
esac
# ── LLM Concurrency ──────────────────────────────────────────────
if [ -n "$LLM_PROVIDER" ]; then
if [ "$LLM_PROVIDER" = "ollama" ]; then
DEFAULT_CONCURRENCY=2
else
DEFAULT_CONCURRENCY=4
fi
echo ""
prompt "Max parallel LLM requests [${DEFAULT_CONCURRENCY}]: " LLM_MAX_CONCURRENCY
LLM_MAX_CONCURRENCY="${LLM_MAX_CONCURRENCY:-$DEFAULT_CONCURRENCY}"
fi
# ── Generate JWT keys ──────────────────────────────────────────────
header "🔐 Generating authentication keys..."
KEYS_DIR="$(pwd)/.keys"
mkdir -p "$KEYS_DIR"
openssl genrsa -out "$KEYS_DIR/private.pem" 2048 2>/dev/null
openssl rsa -in "$KEYS_DIR/private.pem" -pubout -out "$KEYS_DIR/public.pem" 2>/dev/null
JWT_PRIVATE_KEY=$(cat "$KEYS_DIR/private.pem")
JWT_PUBLIC_KEY=$(cat "$KEYS_DIR/public.pem")
AUTH_SECRET=$(openssl rand -hex 32)
ok "RS256 key pair generated"
# ── Patch docker-compose ports if non-default ─────────────────────
if [ "$WEB_PORT" != "3000" ] || [ "$API_PORT" != "8000" ]; then
info "Updating docker-compose.yml with custom ports..."
if [ "$API_PORT" != "8000" ]; then
sed -i.bak "s/\"8000:8000\"/\"${API_PORT}:8000\"/" docker-compose.yml
fi
if [ "$WEB_PORT" != "3000" ]; then
sed -i.bak "s/\"3000:3000\"/\"${WEB_PORT}:3000\"/" docker-compose.yml
fi
rm -f docker-compose.yml.bak
fi
# ── Write .env ─────────────────────────────────────────────────────
header "📝 Writing configuration..."
cat > .env <<ENVFILE
# ═══════════════════════════════════════════════════════════════════
# Wikis Configuration — generated by install.sh
# ═══════════════════════════════════════════════════════════════════
# LLM
LLM_PROVIDER=${LLM_PROVIDER}
LLM_API_KEY=${LLM_API_KEY}
LLM_MODEL=${LLM_MODEL}
LLM_MODEL_LOW=${LLM_MODEL_LOW}
EMBEDDING_MODEL=${EMBEDDING_MODEL}
ENVFILE
# Conditional provider-specific vars
if [ -n "$LLM_MAX_CONCURRENCY" ]; then
echo "LLM_MAX_CONCURRENCY=${LLM_MAX_CONCURRENCY}" >> .env
fi
if [ -n "$LLM_API_BASE" ]; then
echo "LLM_API_BASE=${LLM_API_BASE}" >> .env
fi
if [ "$LLM_PROVIDER" = "bedrock" ]; then
cat >> .env <<ENVFILE
# AWS (Bedrock)
AWS_REGION=${AWS_REGION}
AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ENVFILE
fi
cat >> .env <<ENVFILE
# Storage
STORAGE_BACKEND=local
STORAGE_PATH=/app/data/artifacts
CACHE_DIR=/app/data/cache
# Auth
BETTER_AUTH_URL=${PUBLIC_URL}
FRONTEND_URL=${PUBLIC_URL}
AUTH_SECRET=${AUTH_SECRET}
# Uncomment to enable OAuth:
# GITHUB_CLIENT_ID=
# GITHUB_CLIENT_SECRET=
# GOOGLE_CLIENT_ID=
# GOOGLE_CLIENT_SECRET=
# JWT (cross-service auth)
JWT_PRIVATE_KEY="${JWT_PRIVATE_KEY}"
JWT_PUBLIC_KEY="${JWT_PUBLIC_KEY}"
# Internal
BACKEND_URL=http://backend:8000
WIKIS_BACKEND_URL=${PUBLIC_SCHEME}://${PUBLIC_HOST}:${API_PORT}
LOG_LEVEL=INFO
NODE_ENV=production
ENVFILE
chmod 600 .env
ok "Configuration written to .env"
# ── Start services ─────────────────────────────────────────────────
header "🚀 Starting Wikis..."
if ! docker compose pull; then
warn "Failed to pull one or more images. This may fail if no cached images exist."
prompt " Continue with cached images? [y/N] " pull_continue
if [[ ! "$pull_continue" =~ ^[Yy]$ ]]; then
echo "Aborted. Check your internet connection and try again."; exit 1
fi
fi
if ! docker compose up -d; then
err "Failed to start services. Run 'docker compose up' in $INSTALL_DIR for details."
exit 1
fi
info "Waiting for services to be healthy..."
attempt=0
max_attempts=30
while [ $attempt -lt $max_attempts ]; do
if curl -sf http://localhost:${WEB_PORT} >/dev/null 2>&1; then
break
fi
attempt=$((attempt + 1))
sleep 2
done
if [ $attempt -eq $max_attempts ]; then
warn "Services are still starting. Check: docker compose ps"
else
ok "Services are running"
fi
# ── Done ────────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}${BOLD}═══════════════════════════════════════════════${NC}"
echo -e "${GREEN}${BOLD} Wikis is ready!${NC}"
echo -e "${GREEN}${BOLD}═══════════════════════════════════════════════${NC}"
echo ""
echo -e " ${BOLD}App:${NC} ${PUBLIC_URL}"
echo -e " ${BOLD}API docs:${NC} ${PUBLIC_SCHEME}://${PUBLIC_HOST}:${API_PORT}/docs"
echo -e " ${BOLD}Login:${NC} admin@wikis.dev / changeme123"
echo ""
echo -e " ${YELLOW}Change the default password in Settings > Account after first login.${NC}"
echo ""
echo -e " Manage: cd $INSTALL_DIR"
echo -e " docker compose ps # status"
echo -e " docker compose logs -f # logs"
echo -e " docker compose down # stop"
echo ""