#!/bin/sh -e

UPSTREAM='http://nuand.com/fpga/v0.0.6/hostedx40.rbf'
CHECKSUM='85b91b0caeb64750e8d0ca8dd3358992'
RBFFILE=/usr/share/Nuand/bladeRF/hostedx40.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-hostedx40"
		again when networking is up, or copy the firmware manually
		to $RBFFILE

	EOMSG
fi

#DEBHELPER#
