#!/usr/bin/env bash

if [ -z $DISPLAY ]
then
    sudo tee /proc/acpi/bbswitch <<< ON
    "$@"
    rmmod nvidia_uvm
    rmmod nvidia
    sudo tee /proc/acpi/bbswitch <<< OFF
else
    PATH="/opt/cuda/bin:$PATH" LD_LIBRARY_PATH="/opt/cuda/lib64:$LD_LIBRARY_PATH" VBLANK=0 VGL_READBACK=pbo optirun -c yuv "$@"
fi