-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·174 lines (142 loc) · 6.54 KB
/
setup.sh
File metadata and controls
executable file
·174 lines (142 loc) · 6.54 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
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────
# ClipFeed – interactive .env bootstrap script
# Generates cryptographic secrets and writes a ready-to-use
# .env file so you can `make up` immediately.
# ─────────────────────────────────────────────────────────
set -euo pipefail
ENV_FILE=".env"
EXAMPLE_FILE=".env.example"
# ── helpers ──────────────────────────────────────────────
rand_secret() { openssl rand -base64 32 | tr -d '\n'; }
rand_password() { openssl rand -base64 18 | tr -d '\n/+='; }
green() { printf '\033[1;32m%s\033[0m\n' "$*"; }
yellow() { printf '\033[1;33m%s\033[0m\n' "$*"; }
cyan() { printf '\033[1;36m%s\033[0m\n' "$*"; }
red() { printf '\033[1;31m%s\033[0m\n' "$*"; }
ask() {
# ask PROMPT DEFAULT → prints answer
local prompt="$1" default="$2"
local answer
if [[ -n "$default" ]]; then
read -rp "$(cyan "$prompt") [${default}]: " answer
echo "${answer:-$default}"
else
read -rp "$(cyan "$prompt"): " answer
echo "$answer"
fi
}
# ── pre-flight ───────────────────────────────────────────
if ! command -v openssl &>/dev/null; then
red "Error: openssl is required but not found. Install it and re-run."
exit 1
fi
echo ""
green "╔══════════════════════════════════════════╗"
green "║ ClipFeed – Environment Setup ║"
green "╚══════════════════════════════════════════╝"
echo ""
if [[ -f "$ENV_FILE" ]]; then
yellow "An existing .env file was found."
read -rp "$(yellow 'Overwrite it? (y/N): ')" overwrite
if [[ ! "$overwrite" =~ ^[Yy]$ ]]; then
echo "Aborted – existing .env left untouched."
exit 0
fi
cp "$ENV_FILE" "${ENV_FILE}.bak"
yellow "Backup saved to ${ENV_FILE}.bak"
echo ""
fi
# ── auto-generate secrets ────────────────────────────────
JWT_SECRET="$(rand_secret)"
ADMIN_JWT_SECRET="$(rand_secret)"
COOKIE_SECRET="$(rand_secret)"
WORKER_SECRET="$(rand_secret)"
MINIO_PASSWORD="$(rand_password)"
ADMIN_PASSWORD="$(rand_password)"
# ── interactive prompts (all have sane defaults) ─────────
echo "Press Enter to accept the default shown in brackets."
echo ""
ADMIN_USERNAME="$(ask 'Admin username' 'admin')"
echo ""
yellow "── Compose Profiles ──"
echo " (empty) = base stack, no AI"
echo " ai = + scout (cloud LLM)"
echo " ai,ollama = + scout + local Ollama"
COMPOSE_PROFILES="$(ask 'Compose profiles' '')"
echo ""
yellow "── Processing ──"
PROCESSING_MODE="$(ask 'Processing mode (transcode / copy)' 'transcode')"
MAX_WORKERS="$(ask 'Max concurrent worker jobs' '4')"
WHISPER_MODEL="$(ask 'Whisper model (tiny/base/small/medium/large)' 'medium')"
echo ""
yellow "── Storage ──"
STORAGE_LIMIT_GB="$(ask 'Storage limit (GB)' '50')"
CLIP_TTL_DAYS="$(ask 'Clip TTL (days)' '30')"
echo ""
yellow "── LLM (only relevant if using AI profiles) ──"
LLM_PROVIDER="$(ask 'LLM provider (ollama/openai/anthropic)' 'ollama')"
LLM_API_KEY="$(ask 'LLM API key (leave empty for local Ollama)' '')"
LLM_MODEL="$(ask 'LLM model name (empty for default)' '')"
OLLAMA_MODEL="$(ask 'Ollama model (when using local Ollama)' 'llama3.2:3b')"
# ── write .env ───────────────────────────────────────────
cat > "$ENV_FILE" <<EOF
# ┌──────────────────────────────────────────────────────┐
# │ Generated by setup.sh on $(date -Iseconds) │
# └──────────────────────────────────────────────────────┘
# --- Docker Compose profiles ---
COMPOSE_PROFILES=${COMPOSE_PROFILES}
# For GPU support, uncomment (requires NVIDIA Container Toolkit):
# COMPOSE_FILE=docker-compose.yml:docker-compose.gpu.yml
# --- Secrets (auto-generated) ---
JWT_SECRET=${JWT_SECRET}
ADMIN_JWT_SECRET=${ADMIN_JWT_SECRET}
COOKIE_SECRET=${COOKIE_SECRET}
WORKER_SECRET=${WORKER_SECRET}
# --- MinIO ---
MINIO_USER=clipfeed
MINIO_PASSWORD=${MINIO_PASSWORD}
# --- Admin ---
ADMIN_USERNAME=${ADMIN_USERNAME}
ADMIN_PASSWORD=${ADMIN_PASSWORD}
# --- Processing ---
PROCESSING_MODE=${PROCESSING_MODE}
MAX_WORKERS=${MAX_WORKERS}
WHISPER_MODEL=${WHISPER_MODEL}
MAX_VIDEO_DURATION=3600
MAX_DOWNLOAD_SIZE_MB=2048
MIN_CLIP_SECONDS=15
MAX_CLIP_SECONDS=90
TARGET_CLIP_SECONDS=45
# --- Storage ---
STORAGE_LIMIT_GB=${STORAGE_LIMIT_GB}
CLIP_TTL_DAYS=${CLIP_TTL_DAYS}
# --- Score Updater ---
SCORE_UPDATE_INTERVAL=900
# --- LLM ---
LLM_PROVIDER=${LLM_PROVIDER}
LLM_BASE_URL=
LLM_API_KEY=${LLM_API_KEY}
LLM_MODEL=${LLM_MODEL}
OLLAMA_MODEL=${OLLAMA_MODEL}
EOF
echo ""
green "✓ .env written successfully!"
echo ""
# ── summary ──────────────────────────────────────────────
echo "┌─────────────────────────────────────────────┐"
echo "│ Generated credentials (save these!) │"
echo "├─────────────────────────────────────────────┤"
printf "│ Admin user: %-26s│\n" "$ADMIN_USERNAME"
printf "│ Admin password: %-26s│\n" "$ADMIN_PASSWORD"
printf "│ MinIO password: %-26s│\n" "$MINIO_PASSWORD"
echo "├─────────────────────────────────────────────┤"
echo "│ JWT, cookie & worker secrets were generated │"
echo "│ automatically -- see .env for full values. │"
echo "└─────────────────────────────────────────────┘"
echo ""
green "Next steps:"
echo " 1. Review .env and tweak if needed"
echo " 2. Run: make up"
echo " 3. Open: http://localhost"
echo ""