a0fe45f
#!/bin/bash
a0fe45f
# Usage:
a0fe45f
#    ./otp-get-patches.sh /path/to/otp OTP_R14B02 fedora-R14B02
a0fe45f
#
a0fe45f
# otp-get-patches.sh - update erlang.spec and otp-00*.patch files
a0fe45f
#
a0fe45f
# otp-get-patches.sh updates the erlang.spec and otp-00*.patch
a0fe45f
# files in the git index. After an otp-get-patches.sh run, you
Hans Ulrich Niedermann e7421b9
# will need to review the staged git changes, possibly adapt the
Hans Ulrich Niedermann e7421b9
# 'Release:' and '%changelog' parts of erlang.spec, and can then
a0fe45f
# "git commit" everything.
a0fe45f
#
a0fe45f
# Caution: Leave the four special comment lines untouched in the
a0fe45f
# spec file, as otp-get-patches.sh requires them and will only
Hans Ulrich Niedermann e7421b9
# touch the parts of erlang.spec between the respective start/end
Hans Ulrich Niedermann e7421b9
# comment pair:
a0fe45f
#
a0fe45f
# # start of autogenerated patch tag list
a0fe45f
# # end of autogenerated patch tag list
a0fe45f
a0fe45f
# Command line parsing
a0fe45f
otp_dir="${1:?'Fatal: otp git repo dir required'}"
a0fe45f
otp_upstream="${2:?'Fatal: git ref to upstream release required'}"
a0fe45f
otp_fedora="${3:?'Fatal: git ref to branch with fedora patches required'}"
a0fe45f
a0fe45f
# Setup
a0fe45f
set -e
a0fe45f
# set -x
a0fe45f
tmpdir="$(mktemp -d --tmpdir="$PWD")"
a0fe45f
a0fe45f
# Generate patch files
a0fe45f
pushd "$otp_dir"
2845f91
git format-patch -N --no-signature --no-stat -o "$tmpdir" "${otp_upstream}..${otp_fedora}" > "$tmpdir/patch-list.txt"
a0fe45f
popd
a0fe45f
a0fe45f
test -s "$tmpdir/patch-list.txt"
a0fe45f
a0fe45f
# Process patch files
a0fe45f
echo "# start of autogenerated patch tag list" > "$tmpdir/patch-list-tags.txt"
a0fe45f
n=1
a0fe45f
while read patch
a0fe45f
do
a0fe45f
	otppatch="$(dirname "$patch")/otp-$(basename "$patch")"
a0fe45f
	${SED-sed} -e '1d' -e '/^-- $/,$d' "$patch" > "$otppatch"
a0fe45f
	rm -f "$patch"
a0fe45f
	echo "Patch$n: $(basename "$otppatch")" >> "$tmpdir/patch-list-tags.txt"
a0fe45f
	n=$(($n + 1))
a0fe45f
done < "$tmpdir/patch-list.txt"
a0fe45f
echo "# end of autogenerated patch tag list" >> "$tmpdir/patch-list-tags.txt"
a0fe45f
a0fe45f
# Create updated spec file
a0fe45f
specfile="erlang.spec"
a0fe45f
newspec1="${tmpdir}/${specfile}.new1"
a0fe45f
sed '/^# start of autogenerated patch tag list$/,$d' "$specfile" > "$newspec1"
a0fe45f
cat "$tmpdir/patch-list-tags.txt" >> "$newspec1"
a0fe45f
sed '1,/^# end of autogenerated patch tag list/d' "$specfile" >> "$newspec1"
a0fe45f
a0fe45f
# Actually put all changes into git index
a0fe45f
git rm -f otp-00*.patch
a0fe45f
mv "$tmpdir/otp-00"*.patch .
a0fe45f
git add otp-00*.patch
2ee53c8
mv -f "$newspec1" "$specfile"
a0fe45f
git add "$specfile"
a0fe45f
a0fe45f
rm -rf "$tmpdir"
a0fe45f
# End of file.