-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·364 lines (324 loc) · 11.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·364 lines (324 loc) · 11.3 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
#!/bin/bash
# Akai — Unified Build & Install
#
# Builds all Akai binaries from source. Single machine, zero cloud.
#
# Usage:
# ./install.sh # Build all, install to ~/.local/bin
# ./install.sh --prefix /usr/local
# ./install.sh --check # Check dependencies only
# ./install.sh --list # List all binaries
# ./install.sh --only cms,brief,proof # Build subset
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PREFIX="${HOME}/.local"
CHECK_ONLY=0
LIST_ONLY=0
ONLY=""
# ---- OS / architecture detection ----
OS_TYPE="$(uname -s)"
ARCH="$(uname -m)"
JOBS=$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4)
case "$OS_TYPE" in
Darwin) OS_LABEL="macOS" ;;
Linux) OS_LABEL="Linux" ;;
*) OS_LABEL="$OS_TYPE" ;;
esac
# Warn Linux users that any pre-built zip contains arm64 Mach-O binaries only
if [[ "$OS_TYPE" == "Linux" ]]; then
echo ""
echo " ┌─────────────────────────────────────────────────────────────┐"
echo " │ Linux detected ($ARCH)"
echo " │ Pre-built zip binaries are Mach-O arm64 (macOS only)."
echo " │ Building from source with your local gcc instead. "
echo " │ Alternative: docker compose up -d (see README) "
echo " └─────────────────────────────────────────────────────────────┘"
echo ""
# Linux: prefer gcc explicitly, fall back to cc
if command -v gcc &>/dev/null && [[ -z "${CC:-}" ]]; then
export CC=gcc
fi
fi
# ---- All Akai binary projects (build order matters for deps) ----
# Library first, then CMS (depends on library), then everything else
PROJECTS=(
"liblambda-tensors|liblambda-tensors.a|library"
"AkaiCMS|akai-cms|infrastructure"
"AkaiCLI|akai|orchestration"
"AkaiPipeline|akai-pipeline|orchestration"
"AkaiOrchestrate|akai-orchestrate|orchestration"
"AkaiQueue|akai-queue|orchestration"
"AkaiStitch|akai-stitch|orchestration"
"AkaiSync|akai-sync|orchestration"
"AkaiIngest|akai-ingest|pipeline"
"AkaiHash|akai-hash|pipeline"
"AkaiMediaPrep|akai-media-prep|pipeline"
"AkaiTranscribe|akai-transcribe|pipeline"
"AkaiTranscriptClean|akai-transcript-clean|pipeline"
"AkaiTranscriptFamily|akai-transcript-family|pipeline"
"AkaiParagraph|akai-paragraph|pipeline"
"AkaiNarrate|akai-narrate|pipeline"
"AkaiBrief|akai-brief|pipeline"
"AkaiProof|akai-proof|pipeline"
"AkaiOffer|akai-offer|value"
"AkaiPack|akai-pack|pipeline"
"AkaiDistribute|akai-distribute|pipeline"
"AkaiCompress|akai-compress|pipeline"
"AkaiEmbed|akai-embed|pipeline"
"AkaiEmit|akai-emit|pipeline"
"AkaiRender|akai-render|pipeline"
"AkaiProject|akai-project|pipeline"
"AkaiIndex|akai-index|infrastructure"
"AkaiGate|akai-gate|value"
"AkaiMeter|akai-meter|value"
"AkaiLedger|akai-ledger|value"
"AkaiRuntime|akai-runtime|infrastructure"
"AkaiMFADict|akai-mfa-dict|pipeline"
"AkaiWeaviateIndex|akai-weaviate-index|pipeline"
"AkaiGraph|akai-graph|infrastructure"
"AkaiFinance|akai-finance|value"
"AkaiOutreach|akai-outreach|value"
"AkaiAPI|akai-api|infrastructure"
"AkaiAuth|akai-auth|infrastructure"
"AkaiPay|akai-pay|value"
)
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
log() { echo -e "${CYAN}[akai]${NC} $*"; }
ok() { echo -e "${GREEN} ✓${NC} $*"; }
warn() { echo -e "${YELLOW} ⚠${NC} $*"; }
fail() { echo -e "${RED} ✗${NC} $*"; }
# ---- Parse args ----
while [[ $# -gt 0 ]]; do
case "$1" in
--prefix) PREFIX="$2"; shift 2 ;;
--check) CHECK_ONLY=1; shift ;;
--list) LIST_ONLY=1; shift ;;
--only) ONLY="$2"; shift 2 ;;
-h|--help)
echo "Usage: $0 [--prefix DIR] [--check] [--list] [--only name,name,...]"
echo ""
echo "Options:"
echo " --prefix DIR Install prefix (default: ~/.local)"
echo " --check Check build dependencies only"
echo " --list List all binaries and exit"
echo " --only NAMES Comma-separated list of binaries to build"
exit 0
;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
# ---- List mode ----
if [[ $LIST_ONLY -eq 1 ]]; then
echo -e "${BOLD}Akai Binary Family — 39+ binaries${NC}"
echo ""
printf " %-28s %-24s %s\n" "PROJECT" "BINARY" "LAYER"
printf " %-28s %-24s %s\n" "-------" "------" "-----"
for entry in "${PROJECTS[@]}"; do
IFS='|' read -r dir binary layer <<< "$entry"
printf " %-28s %-24s %s\n" "$dir" "$binary" "$layer"
done
echo ""
echo "Layers: library → infrastructure → orchestration → pipeline → value"
exit 0
fi
# ---- Dependency check ----
log "Checking build dependencies..."
MISSING=0
check_cmd() {
if command -v "$1" &>/dev/null; then
ok "$1 $(command -v "$1")"
else
fail "$1 not found"
MISSING=$((MISSING + 1))
fi
}
check_lib() {
# Try pkg-config, fall back to header search, fall back to compile test
if pkg-config --exists "$1" 2>/dev/null; then
ok "$1 ($(pkg-config --modversion "$1"))"
elif echo "#include <$2>" | cc -fsyntax-only -x c - 2>/dev/null; then
ok "$1 (header found)"
else
fail "$1 not found — install: $3"
MISSING=$((MISSING + 1))
fi
}
check_cmd cc
check_cmd make
check_lib sqlite3 sqlite3.h "brew install sqlite3 / apt install libsqlite3-dev"
check_lib zlib zlib.h "brew install zlib / apt install zlib1g-dev"
# OpenBLAS — required for full AkaiFPQ BLAS-accelerated paths on Linux
# (macOS uses Apple Accelerate, so this check is Linux-only)
if [[ "$OS_TYPE" == "Linux" ]]; then
if pkg-config --exists openblas 2>/dev/null || \
echo "#include <cblas.h>" | ${CC:-cc} -x c -fsyntax-only - 2>/dev/null; then
ok "openblas (found — AkaiFPQ BLAS paths enabled)"
else
warn "openblas not found — AkaiFPQ will build with scalar BLAS fallback"
warn " For full performance: sudo apt-get install libopenblas-dev"
warn " All other modules unaffected."
fi
fi
echo ""
if [[ $MISSING -gt 0 ]]; then
fail "$MISSING missing dependencies"
if [[ "$OS_TYPE" == "Linux" ]]; then
echo ""
warn "On Debian/Ubuntu, install missing deps with:"
echo " sudo apt-get install -y gcc make libsqlite3-dev zlib1g-dev pkg-config libopenblas-dev"
echo ""
warn "Or skip source build and use Docker:"
echo " docker compose up -d"
elif [[ "$OS_TYPE" == "Darwin" ]]; then
warn "Install missing deps with: brew install sqlite3 zlib"
fi
exit 1
fi
ok "All dependencies satisfied"
if [[ $CHECK_ONLY -eq 1 ]]; then
exit 0
fi
# ---- Build ----
log "Building Akai binary family..."
echo ""
BUILT=0
FAILED=0
SKIPPED=0
TOTAL_SIZE=0
BINARIES=()
# Filter by --only if specified
should_build() {
if [[ -z "$ONLY" ]]; then return 0; fi
local name="$1"
local binary="$2"
IFS=',' read -ra FILTER <<< "$ONLY"
for f in "${FILTER[@]}"; do
f=$(echo "$f" | xargs) # trim
if [[ "$name" == "$f" ]] || [[ "$binary" == "$f" ]]; then
return 0
fi
done
return 1
}
for entry in "${PROJECTS[@]}"; do
IFS='|' read -r dir binary layer <<< "$entry"
if ! should_build "$dir" "$binary"; then
SKIPPED=$((SKIPPED + 1))
continue
fi
# Library lives in lib/, binaries in cmd/
if [[ "$layer" == "library" ]]; then
project_dir="${SCRIPT_DIR}/lib/${dir}"
else
project_dir="${SCRIPT_DIR}/cmd/${dir}"
fi
if [[ ! -d "$project_dir" ]]; then
fail "$dir — directory not found"
FAILED=$((FAILED + 1))
continue
fi
if [[ ! -f "$project_dir/Makefile" ]]; then
fail "$dir — no Makefile"
FAILED=$((FAILED + 1))
continue
fi
printf " %-28s " "$dir"
if make -C "$project_dir" -j"$JOBS" 2>/dev/null 1>/dev/null; then
# Find the built binary
bin_path=""
if [[ -f "$project_dir/$binary" ]]; then
bin_path="$project_dir/$binary"
elif [[ -f "$project_dir/build/$binary" ]]; then
bin_path="$project_dir/build/$binary"
fi
if [[ -n "$bin_path" ]]; then
size=$(wc -c < "$bin_path" | xargs)
size_kb=$((size / 1024))
TOTAL_SIZE=$((TOTAL_SIZE + size))
echo -e "${GREEN}✓${NC} ${binary} (${size_kb}KB)"
BINARIES+=("$project_dir|$binary|$bin_path")
BUILT=$((BUILT + 1))
else
echo -e "${YELLOW}⚠${NC} built but binary not found"
BUILT=$((BUILT + 1))
fi
else
echo -e "${RED}✗${NC} build failed"
FAILED=$((FAILED + 1))
fi
done
echo ""
log "Build complete: ${GREEN}${BUILT} built${NC}, ${RED}${FAILED} failed${NC}, ${SKIPPED} skipped"
log "Total binary size: $((TOTAL_SIZE / 1024))KB ($((TOTAL_SIZE / 1024 / 1024))MB)"
# ---- Install ----
if [[ $FAILED -gt 0 ]]; then
warn "Some builds failed. Install anyway? (y/N)"
read -r ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
exit 1
fi
fi
BIN_DIR="${PREFIX}/bin"
mkdir -p "$BIN_DIR"
log "Installing to ${BIN_DIR}..."
INSTALLED=0
for entry in "${BINARIES[@]}"; do
IFS='|' read -r _dir binary bin_path <<< "$entry"
# Skip library — not an installable binary
if [[ "$binary" == *.a ]] || [[ "$binary" == *.so ]]; then
continue
fi
if install -m 755 "$bin_path" "${BIN_DIR}/${binary}" 2>/dev/null; then
ok "$binary → ${BIN_DIR}/${binary}"
INSTALLED=$((INSTALLED + 1))
else
fail "Failed to install $binary"
fi
done
echo ""
log "${GREEN}${BOLD}${INSTALLED} binaries installed to ${BIN_DIR}${NC}"
# Check if BIN_DIR is in PATH
if [[ ":$PATH:" != *":${BIN_DIR}:"* ]]; then
warn "${BIN_DIR} is not in your PATH"
echo " Add to ~/.zshrc: export PATH=\"${BIN_DIR}:\$PATH\""
fi
echo ""
echo -e "${BOLD}Akai is ready.${NC}"
echo " Run: akai --help"
echo " CMS: akai-cms serve"
echo " Full pipeline: akai-pipeline --help"
# ---- Models (optional) ----
echo ""
log "Checking models..."
MODDIR="$HOME/.akai/models"
WHISPER_DIR="$HOME/.local/share/whisper"
mkdir -p "$MODDIR" "$WHISPER_DIR"
download_model() {
local dest="$1" url="$2" label="$3"
if [[ -f "$dest" ]]; then
ok "$label (exists)"
else
echo -n " ↓ $label ... "
if curl -fSL -o "$dest" "$url" 2>/dev/null; then
echo -e "${GREEN}✓${NC}"
else
echo -e "${RED}✗${NC}"
fi
fi
}
download_model "$WHISPER_DIR/ggml-base.en.bin" \
"https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin" \
"whisper base.en (~140MB)"
download_model "$MODDIR/lid.176.bin" \
"https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin" \
"fastText lid.176 (~125MB)"
download_model "$MODDIR/all-MiniLM-L6-v2.onnx" \
"https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/onnx/model.onnx" \
"sentence-transformer ONNX (~22MB)"
echo ""
echo -e "${BOLD}Installation complete.${NC}"