File download_binary-addons.sh of Package kodi.binary-addons

#!/bin/bash 

DOWNLOAD_DIR=build/download
VERSION_NAME=Leia
REPO_BINARY_ADDONS=repo-binary-addons-$VERSION_NAME
mkdir -p $REPO_BINARY_ADDONS-file
mkdir -p $DOWNLOAD_DIR
mkdir -p tmp

curl -L "https://github.com/xbmc/repo-binary-addons/archive/$VERSION_NAME.tar.gz" | tar zxf -
if [ ! -x $REPO_BINARY_ADDONS ]; then
	exit 1
fi

# Removing disabled binary addons
if [ -e $REPO_BINARY_ADDONS-disabled.txt ]; then
	for addon in $(awk -F'-' '{print $1}' repo-binary-addons-$VERSION_NAME-disabled.txt); do
		echo "Removing disabled addon $addon"
		rm -rf $REPO_BINARY_ADDONS/$addon
	done
fi

#
rm -f spec.packages.in spec.files.in
rm -f kodi.binary-addons.spec.packages.inc kodi.binary-addons.spec.files.inc

#JSONCPP_PATCH="pvr.argustv pvr.filmon pvr.hdhomerun pvr.pctv pvr.stalker pvr.sledovanitv.cz"
JSONCPP_PATCH=""

for addon in $(ls -1 $REPO_BINARY_ADDONS); do
    echo "Downloading $addon"
	ADDON=$(cat $REPO_BINARY_ADDONS/$addon/$addon.txt)
	IFS=' ' read -a SPLIT_ADDON <<< "$ADDON"
	NAME=${SPLIT_ADDON[0]}
	URL=${SPLIT_ADDON[1]}
	DL_BRANCH=${SPLIT_ADDON[2]}
	BRANCH=$(echo ${SPLIT_ADDON[2]} | sed -e 's#^v##')
	curl --progress-bar -L "$URL/archive/$DL_BRANCH.tar.gz" -o $DOWNLOAD_DIR/$NAME-$BRANCH.tar.gz	
	
	mkdir -p $REPO_BINARY_ADDONS-file/$addon
	echo "$NAME file://$DOWNLOAD_DIR/$NAME-$BRANCH.tar.gz $BRANCH" > $REPO_BINARY_ADDONS-file/$addon/$addon.txt

	if [[ $JSONCPP_PATCH =~ (^|[[:space:]])"$NAME"($|[[:space:]]) ]]; then
		echo "Patching $addon"
		tar -C tmp -xf $DOWNLOAD_DIR/$NAME-$BRANCH.tar.gz 
		patch -d tmp/$NAME-$BRANCH -t < FindJsonCpp.cmake.patch
		tar -C tmp -zcf $DOWNLOAD_DIR/$NAME-$BRANCH.tar.gz $NAME-$BRANCH
	fi

	cat << EOF >> kodi.binary-addons.spec.packages.inc
%package $addon
Summary:        Kodi $addon binary addon
Group:          Productivity/Multimedia/Video/Players
Requires:       kodi = %{version}

%description $addon
Kodi $addon binary addon

EOF

	cat << EOF >> kodi.binary-addons.spec.files.inc
%files $addon
%defattr(-,root,root)
%dir %{_libdir}/kodi/addons
%dir %{_libdir}/kodi/addons/$addon
%dir %{_kodi_addons_dir}/$addon
%{_libdir}/kodi/addons/$addon/*
%{_kodi_addons_dir}/$addon/*

EOF

done

tar cf kodi.binary-addons.tar $DOWNLOAD_DIR
echo "kodi.binary-addons.tar was created"

tar cjf repo-binary-addons.$VERSION_NAME.tar.bz2 $REPO_BINARY_ADDONS-file
echo "repo-binary-addons.$VERSION_NAME.tar.bz2 was created"

# cleanup
rm -rf tmp $(dirname $DOWNLOAD_DIR) $REPO_BINARY_ADDONS $REPO_BINARY_ADDONS-file