f7e3a07
#!/usr/bin/bash
f7e3a07
f7e3a07
#
f7e3a07
# No patents, no problems
f7e3a07
#
f7e3a07
f7e3a07
# Indicate the problems
f7e3a07
PROBLEMS=(
cd0a4a8
	'gr-dtv'
cd0a4a8
	'gr-atsc'
f7e3a07
)
f7e3a07
f7e3a07
# Indicate the source
f7e3a07
URL=$(spectool -S -l ./gnuradio.spec | sed -E 's/Source0:\s+//g')
f7e3a07
f7e3a07
# Meta variables
f7e3a07
SOURCE=$(basename $URL)
f7e3a07
COMPRESSION=${SOURCE##*.}
f7e3a07
TAR=${SOURCE%.*}
f7e3a07
f7e3a07
# check if $SOURCE exists
f7e3a07
if [ ! -f $SOURCE ]; then
f7e3a07
	# It does not, so we download it
f7e3a07
	echo "DOWNLOADING \"$SOURCE\" FROM \"$URL\""
f7e3a07
	curl -L -O "$URL"
f7e3a07
fi
f7e3a07
f7e3a07
echo "UNCOMPRESS \"$SOURCE\" TO \"$TAR\""
f7e3a07
if [ "gz" = "$COMPRESSION" ]; then
f7e3a07
	COMPRESSION="gzip"
f7e3a07
fi
f7e3a07
$COMPRESSION -d $SOURCE
f7e3a07
f7e3a07
# Getting the base DIR inside the tar
f7e3a07
TAR_BASE=$(tar tf $TAR | head -n1 | sed 's/\/$//')
f7e3a07
for PROBLEM in ${PROBLEMS[@]};
f7e3a07
do
f7e3a07
	echo "REMOVING \"$PROBLEM\" FROM \"$TAR\""
f7e3a07
	tar -vf $TAR --delete "${TAR_BASE}/${PROBLEM}"
cd0a4a8
	tar -vf $TAR --strip=1 -x "${TAR_BASE}/CMakeLists.txt"
cd0a4a8
	tar -vf $TAR --delete "${TAR_BASE}/CMakeLists.txt"
cd0a4a8
	sed -i "/^add_subdirectory(${PROBLEM})$/ d" CMakeLists.txt
cd0a4a8
	tar -vf $TAR --append CMakeLists.txt --transform="s|CMakeLists.txt|${TAR_BASE}/CMakeLists.txt|"
f7e3a07
done
cd0a4a8
rm -f CMakeLists.txt
f7e3a07
f7e3a07
echo "RECOMPRESS \"$TAR\" TO \"$SOURCE\""
f7e3a07
$COMPRESSION $TAR