#! /bin/bash

set -eux

setup() {
    # Get system packages
    sudo apt-get update
    sudo xargs apt-get install -y < requirements.apt
    sudo pip install -r requirements.pip

    # Requires yt-dlp, but a very recent version (as youtube broke their API for the pip version)
    # https://stackoverflow.com/a/75504772
    python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz

    # Install device driver
    ./scripts/SDRplay_RSP_API-Linux-3.07.1.run

    # Get project dependencies
    mkdir -p ./dependencies
    pushd ./dependencies
        bash ../scripts/get_soapy.sh
        bash ../scripts/get_liquid-dsp.sh
        bash ../scripts/get_mediamtx.sh
    popd

    set +eux
    echo "Setup complete."
}

time setup