#!/bin/sh -e

UPSTREAM='http://nuand.com/fpga/v0.0.6/hostedx115.rbf'
CHECKSUM='eb91ecda1d1203750f0f2b9859c9c20f'
RBFFILE=/usr/share/Nuand/bladeRF/hostedx115.rbf

checkfile () {
	md5sum --check <<- EOMD5SUM
	$CHECKSUM  $RBFFILE
	EOMD5SUM
}

# Fetch firmware if needed
if [ ! -s $RBFFILE ] || ! checkfile ; then
	echo "Downloading FPGA bitstream from nuand.com..."
	rm -f $RBFFILE
	wget -O $RBFFILE $UPSTREAM || cat <<- EOMSG 1>&2

		Warning: Failed to download FPGA bitstream for bladeRF.
		Please run "dpkg-reconfigure bladerf-fpga-hostedx115"
		again when networking is up, or copy the firmware manually
		to $RBFFILE

	EOMSG
fi

#DEBHELPER#
