#!/bin/sh
# HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip
# f26a8 (992936) = firmware offset

SUM=`md5sum 88x_2_119_25023_WHQL.zip`
if [ "$SUM" != "6e42ab64503493ffcb8e2924ba53e255  88x_2_119_25023_WHQL.zip" ]
then
	echo "Invalid zip archive, either corrupt or incorrect version"
	exit
fi

echo "Extracting hcw88bda.sys from the windows zip file"
unzip -jo 88x_2_119_25023_WHQL.zip Driver88/hcw88bda.sys
if [ $? -ne 0 ]
then
	echo "Failed to extract file, aborting"
	exit
fi

echo "Extracting firmware as dvb-fe-cx24116.fw from hcw88bda.sys"
dd if=hcw88bda.sys of=dvb-fe-cx24116.fw skip=81768 bs=1 count=32522 >/dev/null 2>&1
if [ $? -ne 0 ]
then
	echo "Failed to extract firmware from file, aborting"
	exit
fi

SUM=`md5sum dvb-fe-cx24116.fw`
if [ "$SUM" != "417cafd3b10e207e1dba9a03ad63e405  dvb-fe-cx24116.fw" ]
then
	echo "Error extracting firmware, failed md5 check"
	exit
else
	echo "Firmware extracted successfully"
fi

echo "Removing hcw88bda.sys temporary file"
rm -f hcw88bda.sys

echo "Now manually copy dvb-fe-cx24116.fw into your firmware dir"
echo "  E.g. sudo cp dvb-fe-cx24116.fw /lib/firmware/`uname -r`"

