#!/bin/bash
# Install audio dependencies for DryBox

echo "Installing audio dependencies for DryBox..."
echo

# Detect OS
if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$ID
    VER=$VERSION_ID
else
    echo "Cannot detect OS. Please install manually."
    exit 1
fi

case $OS in
    fedora)
        echo "Detected Fedora $VER"
        echo "Installing python3-devel and portaudio-devel..."
        sudo dnf install -y python3-devel portaudio-devel
        ;;
    
    ubuntu|debian)
        echo "Detected $OS $VER"
        echo "Installing python3-dev and portaudio19-dev..."
        sudo apt-get update
        sudo apt-get install -y python3-dev portaudio19-dev
        ;;
    
    *)
        echo "Unsupported OS: $OS"
        echo "Please install manually:"
        echo "  - Python development headers"
        echo "  - PortAudio development libraries"
        exit 1
        ;;
esac

if [ $? -eq 0 ]; then
    echo
    echo "System dependencies installed successfully!"
    echo "Now installing PyAudio..."
    pip install pyaudio
    
    if [ $? -eq 0 ]; then
        echo
        echo "✅ Audio dependencies installed successfully!"
        echo "You can now use real-time audio playback in DryBox."
    else
        echo
        echo "❌ Failed to install PyAudio"
        echo "Try: pip install --user pyaudio"
    fi
else
    echo
    echo "❌ Failed to install system dependencies"
fi