#!/bin/sh

DEST=bcm963xx_router

test -d $DEST/ ||
{
	mkdir $DEST/
	tar --exclude=CVS --exclude="*~" --exclude="*.bak" --exclude=tmp1 --exclude=Thumbs.db\
		-C $DEST/ -xvzf bcm963xx_targa.0.13v1l.300l01.v27_consumer.tar.gz
	chmod -R o-w $DEST/
	for i in \
		config.bin \
		hcti_netzwerk_lan.htm_orig \
		hcti_netzwerk_wan.htm_orig \
		hcti_startseite_test.htm \
		js_fade.js \
		js_menu.js \
		kuwa.c \
		*.jpg \
		*.gif;
	do
		rm -v $DEST/userapps/broadcom/cfm/html_t_online_fra/$i
	done
	# Remove MSDOS CR-LFs
	sed -i -e's/\r\+$//' \
		$DEST/userapps/broadcom/cfm/html_t_online_fra/*.css \
		$DEST/userapps/broadcom/cfm/html_t_online_fra/*.txt \
		$DEST/userapps/broadcom/cfm/html_t_online_fra/*.htm*
	tar  -C $DEST/ -xvzf mod500/mod500-addons.tgz
	patch -d $DEST/ -p1 < mod500/mod500-addons.patch
	if true; then
		# Telekom Images
		tar -C $DEST/userapps/broadcom/cfm/html_t_online_fra -xvzf mod500/images-tcom.tgz
		patch -d $DEST/userapps/broadcom/cfm/html_t_online_fra/ -p1 < mod500/mod500-webui-tcom.patch
	else
		# Lidl/Targa Images
		tar -C $DEST/userapps/broadcom/cfm/html_t_online_fra -xvzf mod500/images-lidl.tgz
		patch -d $DEST/userapps/broadcom/cfm/html_t_online_fra/ -p1 < mod500/mod500-webui-lidl.patch
	fi
	patch -d $DEST/userapps/broadcom/cfm/html_t_online_fra/ -p1 < mod500/sven-ola-webui.patch
	cp -a $DEST $DEST.orig
	patch -d $DEST/ -p1 < mod500/sven-ola-addons.patch
}

cd $DEST/
make PROFILE=96348GWV_DT
