#!/bin/sh
# v.2 set to 20 blocks if GPU is present

gpuc=$(lspci | grep -c -i --color NVIDIA)
blocks=$((gpuc * 8))

echo "$gpuc NVIDIA GPUs detected"

if [ "$blocks" -lt 6 ]; then
    echo "Using default Video blocks"
else
    if grep -q "SpectraVideoBlocks" /opt/Spectra/var/settings.xml; then
        echo "SpectraVideoBlocks Exists in settings"
    else
        if [ "$blocks" -lt 20 ]; then
            blocks=20
        fi

        sudo sed -i 's|SB_HD_ENCODER|SB_HD_ENCODER  SpectraVideoBlocks=\"'$blocks'\"|g' /opt/Spectra/var/settings.xml
        echo "SpectraVideoBlocks was added for GPUi ($blocks)"
    fi
fi
