File medialibrary-beta.rebase-changes.sh of Package medialibrary-beta

#!/bin/bash
set -e
unset LANG
unset ${!LC_*}
read td < <(mktemp --directory --tmpdir=/dev/shm .XXX)
trap "rm -rf '${td}'" EXIT
#
git_base='0.13.x'
#
d_extract="${td}/e"
d_old="${td}/o"
d_new="${td}/n"
#
read medialibrary_beta_pkg < <(readlink -f "$1")
read medialibrary_git < <(readlink -f "$2")
#
test -f "${medialibrary_git}/.git/config"
test -f "${medialibrary_beta_pkg}/.osc/_package"
read pkg < "$_"
test "${pkg}" = 'medialibrary-beta'
mkdir "${d_extract}" "${d_old}" "${d_new}"
pushd "${medialibrary_beta_pkg}" > /dev/null
for patch in *.patch
do
	test -f "${patch}" || continue
	sed '
	/^---[[:blank:]]/d
	/^+++[[:blank:]]/d
	/^@@[[:blank:]]/d
	' < "${patch}" > "${d_old}/${patch}"
done
pushd "${medialibrary_git}" > /dev/null
git --no-pager checkout "${git_base}"
git --no-pager pull
git --no-pager checkout medialibrary-beta
git --no-pager rebase "${git_base}"
git --no-pager format-patch --quiet --output-directory "${d_extract}" "${git_base}..HEAD"
#
sed -i -n '
: sep
n
/^---$/b stat
b sep
: stat
n
/^$/b body
b stat
: body
n
/^diff[[:blank:]]\+--git[[:blank:]]\+/b body
/^index[[:blank:]]\+[0-9a-f]\+/b body
p
b body
' "${d_extract}"/*.patch
pushd "${d_extract}" > /dev/null
for patch in *.patch
do
	o="${patch}"
	n="${patch#*-}"
	mv "${o}" "${n}"
	sed '
	/^---[[:blank:]]/d
	/^+++[[:blank:]]/d
	/^@@[[:blank:]]/d
	' < "${n}" > "${d_new}/${n}"
	if diff -u "${d_old}/${n}" "${d_new}/${n}"
	then
		rm "${n}"
	else
		mv -vit "${medialibrary_beta_pkg}" "${n}"
	fi
done