sharkcz / rpms / gnuradio

Forked from rpms/gnuradio 3 years ago
Clone
Blob Blame History Raw
#!/usr/bin/bash

#
# No patents, no problems
#

# Indicate the problems
PROBLEMS=(
	'gr-dtv'
	'gr-atsc'
)

# Indicate the source
URL=$(spectool -S -l ./gnuradio.spec | sed -E 's/Source0:\s+//g')

# Meta variables
SOURCE=$(basename $URL)
COMPRESSION=${SOURCE##*.}
TAR=${SOURCE%.*}

# check if $SOURCE exists
if [ ! -f $SOURCE ]; then
	# It does not, so we download it
	echo "DOWNLOADING \"$SOURCE\" FROM \"$URL\""
	curl -L -O "$URL"
fi

echo "UNCOMPRESS \"$SOURCE\" TO \"$TAR\""
if [ "gz" = "$COMPRESSION" ]; then
	COMPRESSION="gzip"
fi
$COMPRESSION -d $SOURCE

# Getting the base DIR inside the tar
TAR_BASE=$(tar tf $TAR | head -n1 | sed 's/\/$//')
for PROBLEM in ${PROBLEMS[@]};
do
	echo "REMOVING \"$PROBLEM\" FROM \"$TAR\""
	tar -vf $TAR --delete "${TAR_BASE}/${PROBLEM}"
	tar -vf $TAR --strip=1 -x "${TAR_BASE}/CMakeLists.txt"
	tar -vf $TAR --delete "${TAR_BASE}/CMakeLists.txt"
	sed -i "/^add_subdirectory(${PROBLEM})$/ d" CMakeLists.txt
	tar -vf $TAR --append CMakeLists.txt --transform="s|CMakeLists.txt|${TAR_BASE}/CMakeLists.txt|"
done
rm -f CMakeLists.txt

echo "RECOMPRESS \"$TAR\" TO \"$SOURCE\""
$COMPRESSION $TAR