File size: 13,417 Bytes
94004a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/sh
# OmniVoice Studio β€” universal installer.
#
# Works on macOS (ARM + Intel), Linux (Debian/Ubuntu, Fedora, Arch), and WSL.
# Run once, then `./run.sh` each time you want to use the app.
#
# Usage:
#   curl -fsSL https://raw.githubusercontent.com/debpalash/OmniVoice-Studio/main/install.sh | sh
#   # or locally:
#   sh install.sh
#   sh install.sh --verbose        # show all subcommand output
#   sh install.sh --python 3.12    # override Python version
set -e

# ── Output style ────────────────────────────────────────────────────────────
RULE=""
_rule_i=0
while [ "$_rule_i" -lt 56 ]; do
    RULE="${RULE}─"
    _rule_i=$((_rule_i + 1))
done

if [ -n "${NO_COLOR:-}" ]; then
    C_TITLE="" C_DIM="" C_OK="" C_WARN="" C_ERR="" C_RST=""
elif [ -t 1 ] || [ -n "${FORCE_COLOR:-}" ]; then
    _ESC="$(printf '\033')"
    C_TITLE="${_ESC}[1;38;5;141m"   # bold purple
    C_DIM="${_ESC}[38;5;245m"
    C_OK="${_ESC}[38;5;108m"        # green
    C_WARN="${_ESC}[38;5;136m"      # yellow
    C_ERR="${_ESC}[91m"             # red
    C_RST="${_ESC}[0m"
else
    C_TITLE="" C_DIM="" C_OK="" C_WARN="" C_ERR="" C_RST=""
fi

step()  { printf "  ${C_DIM}%-18.18s${C_RST}${3:-$C_OK}%s${C_RST}\n" "$1" "$2"; }
note()  { printf "  ${C_DIM}%-18s${2:-$C_DIM}%s${C_RST}\n" "" "$1"; }
warn()  { printf "  ${C_WARN}⚠  %s${C_RST}\n" "$1"; }
die()   { printf "  ${C_ERR}βœ—  %s${C_RST}\n" "$1" >&2; exit 1; }
have()  { command -v "$1" >/dev/null 2>&1; }

# ── Parse flags ─────────────────────────────────────────────────────────────
_VERBOSE=false
_USER_PYTHON=""
_next_is_python=false
for arg in "$@"; do
    if [ "$_next_is_python" = true ]; then
        _USER_PYTHON="$arg"
        _next_is_python=false
        continue
    fi
    case "$arg" in
        --verbose|-v) _VERBOSE=true ;;
        --python)     _next_is_python=true ;;
    esac
done
if [ "$_next_is_python" = true ]; then
    die "--python requires a version argument (e.g. --python 3.12)"
fi

run_quiet() {
    if [ "$_VERBOSE" = true ]; then
        "$@"
    else
        "$@" > /dev/null 2>&1
    fi
}

# ── Helper: download (curl or wget) ────────────────────────────────────────
download() {
    if have curl; then
        curl -LsSf "$1" -o "$2"
    elif have wget; then
        wget -qO "$2" "$1"
    else
        die "Neither curl nor wget found. Install one and re-run."
    fi
}

# ── Helper: open browser (cross-platform) ──────────────────────────────────
open_browser() {
    _url="$1"
    if [ "$(uname)" = "Darwin" ] && have open; then
        open "$_url"
    elif grep -qi microsoft /proc/version 2>/dev/null; then
        # WSL: use Windows browser
        if have powershell.exe; then
            powershell.exe -NoProfile -Command "Start-Process '$_url'" >/dev/null 2>&1 &
        elif have cmd.exe; then
            cmd.exe /c start "" "$_url" >/dev/null 2>&1 &
        elif have xdg-open; then
            xdg-open "$_url" >/dev/null 2>&1 &
        else
            echo "  Open in your browser: $_url"
        fi
    elif have xdg-open; then
        xdg-open "$_url" >/dev/null 2>&1 &
    else
        echo "  Open in your browser: $_url"
    fi
}

# ── Detect platform ────────────────────────────────────────────────────────
OS="linux"
if [ "$(uname)" = "Darwin" ]; then
    OS="macos"
elif grep -qi microsoft /proc/version 2>/dev/null; then
    OS="wsl"
fi
ARCH=$(uname -m)

echo ""
printf "  ${C_TITLE}%s${C_RST}\n" "πŸŽ™ OmniVoice Studio Installer"
printf "  ${C_DIM}%s${C_RST}\n" "$RULE"
echo ""

step "platform" "$OS ($ARCH)"

# Detect Rosetta on macOS
if [ "$OS" = "macos" ] && [ "$ARCH" = "x86_64" ]; then
    if [ "$(sysctl -in hw.optional.arm64 2>/dev/null || echo 0)" = "1" ]; then
        warn "Apple Silicon detected running under Rosetta (x86_64)."
        note "Re-run from a native arm64 terminal for full MLX support."
    fi
fi

# ── Resolve script directory (for local installs) ──────────────────────────
SCRIPT_DIR=""
if [ -n "${0:-}" ] && [ -f "$0" ]; then
    SCRIPT_DIR=$(cd "$(dirname "$0")" 2>/dev/null && pwd) || true
fi
if [ -z "$SCRIPT_DIR" ]; then
    SCRIPT_DIR=$(pwd)
fi

# If run via curl pipe, clone the repo first
if [ ! -f "$SCRIPT_DIR/pyproject.toml" ]; then
    step "clone" "downloading OmniVoice Studio..."
    INSTALL_DIR="$HOME/OmniVoice"
    if [ -d "$INSTALL_DIR/.git" ]; then
        note "Updating existing clone at $INSTALL_DIR"
        (cd "$INSTALL_DIR" && git pull --ff-only 2>/dev/null || true)
    else
        if have git; then
            git clone --depth 1 https://github.com/debpalash/OmniVoice-Studio.git "$INSTALL_DIR"
        else
            die "git is required. Install git and re-run."
        fi
    fi
    SCRIPT_DIR="$INSTALL_DIR"
fi

cd "$SCRIPT_DIR"

# ── Python version ──────────────────────────────────────────────────────────
if [ -n "$_USER_PYTHON" ]; then
    PYTHON_VERSION="$_USER_PYTHON"
    note "Using user-specified Python $PYTHON_VERSION"
else
    PYTHON_VERSION="3.11"
fi

# ── System dependencies ────────────────────────────────────────────────────

# Helper: install system packages with the right package manager
_install_sys_pkgs() {
    case "$OS" in
        macos)
            if ! have brew; then
                note "Installing Homebrew..."
                /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" </dev/null
                if [ -x /opt/homebrew/bin/brew ]; then
                    eval "$(/opt/homebrew/bin/brew shellenv)"
                elif [ -x /usr/local/bin/brew ]; then
                    eval "$(/usr/local/bin/brew shellenv)"
                fi
            fi
            brew install "$@" </dev/null 2>/dev/null || true
            ;;
        linux|wsl)
            if have apt-get; then
                # Try without sudo first, then escalate
                apt-get update -y </dev/null >/dev/null 2>&1 || true
                apt-get install -y "$@" </dev/null >/dev/null 2>&1 || {
                    if have sudo; then
                        echo ""
                        echo "  Need elevated permissions to install: $*"
                        sudo apt-get update -y </dev/null
                        sudo apt-get install -y "$@" </dev/null
                    else
                        die "Cannot install $*. Run as root or install manually."
                    fi
                }
            elif have dnf; then
                sudo dnf install -y "$@" </dev/null 2>/dev/null || true
            elif have yum; then
                sudo yum install -y "$@" </dev/null 2>/dev/null || true
            elif have pacman; then
                sudo pacman -S --noconfirm "$@" 2>/dev/null || true
            else
                warn "No supported package manager found. Please install manually: $*"
            fi
            ;;
    esac
}

# Xcode CLT (macOS only)
if [ "$OS" = "macos" ]; then
    step "xcode" "checking..."
    if ! xcode-select -p >/dev/null 2>&1; then
        note "Installing Xcode Command Line Tools..."
        xcode-select --install </dev/null 2>/dev/null || true
        until xcode-select -p >/dev/null 2>&1; do
            note "Waiting for Xcode CLT install..."
            sleep 10
        done
    fi
    step "xcode" "$(xcode-select -p)"
fi

# ffmpeg (required for audio/video processing)
step "ffmpeg" "checking..."
if ! have ffmpeg; then
    note "Installing ffmpeg..."
    case "$OS" in
        macos)  _install_sys_pkgs ffmpeg ;;
        linux|wsl)
            if have apt-get; then
                _install_sys_pkgs ffmpeg
            elif have dnf; then
                _install_sys_pkgs ffmpeg-free  # Fedora
            elif have pacman; then
                _install_sys_pkgs ffmpeg
            else
                warn "Please install ffmpeg manually."
            fi
            ;;
    esac
fi
if have ffmpeg; then
    step "ffmpeg" "$(ffmpeg -version 2>/dev/null | head -n1 | cut -d' ' -f1-3)"
else
    warn "ffmpeg not found β€” some features will be unavailable."
fi

# ── Install uv ──────────────────────────────────────────────────────────────
step "uv" "checking..."
UV_MIN_VERSION="0.7.0"

_version_ge() {
    # Returns 0 if $1 >= $2 (dotted version comparison)
    _a=$1; _b=$2
    while [ -n "$_a" ] || [ -n "$_b" ]; do
        _a_part=${_a%%.*}; _b_part=${_b%%.*}
        [ "$_a" = "$_a_part" ] && _a="" || _a=${_a#*.}
        [ "$_b" = "$_b_part" ] && _b="" || _b=${_b#*.}
        [ -z "$_a_part" ] && _a_part=0
        [ -z "$_b_part" ] && _b_part=0
        if [ "$_a_part" -gt "$_b_part" ] 2>/dev/null; then return 0; fi
        if [ "$_a_part" -lt "$_b_part" ] 2>/dev/null; then return 1; fi
    done
    return 0
}

_uv_ok() {
    have uv || return 1
    _raw=$(uv --version 2>/dev/null | awk '{print $2}') || return 1
    [ -n "$_raw" ] || return 1
    _ver=${_raw%%[-+]*}
    _version_ge "$_ver" "$UV_MIN_VERSION"
}

if ! _uv_ok; then
    note "Installing uv package manager..."
    _uv_tmp=$(mktemp)
    download "https://astral.sh/uv/install.sh" "$_uv_tmp"
    run_quiet sh "$_uv_tmp" </dev/null
    rm -f "$_uv_tmp"
    # Source env if uv's installer created it
    if [ -f "$HOME/.local/bin/env" ]; then
        . "$HOME/.local/bin/env"
    fi
    export PATH="$HOME/.local/bin:$PATH"
fi
step "uv" "$(uv --version 2>/dev/null)"

# ── Install bun (JS runtime for frontend) ──────────────────────────────────
step "bun" "checking..."
if ! have bun; then
    note "Installing bun..."
    if have curl; then
        curl -fsSL https://bun.sh/install | sh </dev/null
    else
        die "curl is required to install bun."
    fi
    export PATH="$HOME/.bun/bin:$PATH"
fi
step "bun" "bun $(bun --version 2>/dev/null)"

# ── GPU detection (informational) ──────────────────────────────────────────
step "gpu" "detecting..."
GPU_INFO="CPU only"
if [ "$OS" = "macos" ] && [ "$ARCH" = "arm64" ]; then
    GPU_INFO="Apple Silicon (Metal/MPS)"
elif have nvidia-smi; then
    _gpu_name=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1)
    _cuda_ver=$(nvidia-smi 2>/dev/null | sed -n 's/.*CUDA Version:[[:space:]]*\([0-9]*\.[0-9]*\).*/\1/p' | head -1)
    if [ -n "$_gpu_name" ]; then
        GPU_INFO="NVIDIA $_gpu_name (CUDA $_cuda_ver)"
    fi
elif have rocminfo; then
    _amd_name=$(rocminfo 2>/dev/null | awk '/Marketing Name:/{$1=$2=""; print; exit}' | sed 's/^ *//')
    if [ -n "$_amd_name" ]; then
        GPU_INFO="AMD $_amd_name (ROCm)"
    fi
fi
step "gpu" "$GPU_INFO"

# ── Python dependencies via uv ──────────────────────────────────────────────
step "python" "syncing dependencies..."
note "This can take 5–10 min the first time (torch + torchaudio + demucs...)"

# Create venv with the target Python version if it doesn't exist
if [ ! -d .venv ]; then
    uv venv --python "$PYTHON_VERSION"
fi

# Sync all deps from pyproject.toml + uv.lock
uv sync

step "python" "OK β€” virtualenv at .venv/"

# ── Frontend deps + build ──────────────────────────────────────────────────
step "frontend" "installing dependencies..."
(cd frontend && bun install)
step "frontend" "OK"

step "frontend" "building bundle..."
(cd frontend && bun run build)
step "frontend" "OK β€” output at frontend/dist/"

# ── Log directory ──────────────────────────────────────────────────────────
case "$OS" in
    macos) LOG_DIR="$HOME/Library/Application Support/OmniVoice" ;;
    *)     LOG_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/OmniVoice" ;;
esac
mkdir -p "$LOG_DIR"

# ── Done ────────────────────────────────────────────────────────────────────
echo ""
printf "  ${C_TITLE}%s${C_RST}\n" "βœ“ Install complete!"
printf "  ${C_DIM}%s${C_RST}\n" "$RULE"
echo ""
step "next" "Run ./run.sh to start OmniVoice Studio"
echo ""
note "First launch downloads ~5 GB of ML model weights (OmniVoice TTS + Whisper)."
note "After that, launches are instant."
echo ""
note "GPU: $GPU_INFO"
note "Logs: $LOG_DIR/omnivoice.log"
echo ""