Blame otp-get-patches.sh

a0fe45
#!/bin/bash
a0fe45
# Usage:
a0fe45
#    ./otp-get-patches.sh /path/to/otp OTP_R14B02 fedora-R14B02
a0fe45
#
a0fe45
# otp-get-patches.sh - update erlang.spec and otp-00*.patch files
a0fe45
#
a0fe45
# otp-get-patches.sh updates the erlang.spec and otp-00*.patch
a0fe45
# files in the git index. After an otp-get-patches.sh run, you
a0fe45
# will need to review the stage git changes, possibly adapt the
a0fe45
# Release: and %changelog parts of erlang spec, and can then
a0fe45
# "git commit" everything.
a0fe45
#
a0fe45
# Caution: Leave the four special comment lines untouched in the
a0fe45
# spec file, as otp-get-patches.sh requires them and will only
a0fe45
# touch erlang.spec between the respective start/end pair:
a0fe45
#
a0fe45
# # start of autogenerated patch tag list
a0fe45
# # end of autogenerated patch tag list
a0fe45
# # start of autogenerated prep patch list
a0fe45
# # end of autogenerated prep patch list
a0fe45
#
a0fe45
# The following special comment lines in the git commit messages
a0fe45
# will be interpreted:
a0fe45
#
a0fe45
#    Fedora-Spec-Comment: This patch only applies to EL6 builds
a0fe45
#    Fedora-Spec-Before: %if 0%?el6}
a0fe45
#    Fedora-Spec-After: %endif
a0fe45
#
a0fe45
# If there is no "Fedora-Spec-Comment:" line, we will use
a0fe45
# "Fedora specific patch".
a0fe45
a0fe45
# Command line parsing
a0fe45
otp_dir="${1:?'Fatal: otp git repo dir required'}"
a0fe45
otp_upstream="${2:?'Fatal: git ref to upstream release required'}"
a0fe45
otp_fedora="${3:?'Fatal: git ref to branch with fedora patches required'}"
a0fe45
a0fe45
# Setup
a0fe45
set -e
a0fe45
# set -x
a0fe45
tmpdir="$(mktemp -d --tmpdir="$PWD")"
a0fe45
a0fe45
# Generate patch files
a0fe45
pushd "$otp_dir"
a0fe45
git format-patch -N -o "$tmpdir" "${otp_upstream}..${otp_fedora}" > "$tmpdir/patch-list.txt"
a0fe45
popd
a0fe45
a0fe45
test -s "$tmpdir/patch-list.txt"
a0fe45
a0fe45
# Process patch files
a0fe45
echo "# start of autogenerated patch tag list" > "$tmpdir/patch-list-tags.txt"
a0fe45
echo "# start of autogenerated prep patch list" > "$tmpdir/patch-list-prep.txt"
a0fe45
n=1
a0fe45
while read patch
a0fe45
do
a0fe45
	otppatch="$(dirname "$patch")/otp-$(basename "$patch")"
a0fe45
	${SED-sed} -e '1d' -e '/^-- $/,$d' "$patch" > "$otppatch"
a0fe45
	rm -f "$patch"
a0fe45
	comment="$(sed -n 's/^Fedora-Spec-Comment:\s*//p' "$otppatch")"
a0fe45
	if test "x$comment" = "x"; then comment="Fedora specific patch"; fi
a0fe45
	echo "# ${comment}" >> "$tmpdir/patch-list-tags.txt"
a0fe45
	echo "#   $(sed -n 's/^Subject: \[PATCH\] //p' "$otppatch")" >> "$tmpdir/patch-list-tags.txt"
a0fe45
	echo "Patch$n: $(basename "$otppatch")" >> "$tmpdir/patch-list-tags.txt"
a0fe45
	base="$(basename "$patch" ".patch" | sed 's/^00[0-9][0-9]-//')"
a0fe45
	backupext=".$(echo -n "$base" | tr -c -s '[:alnum:]' '_')"
a0fe45
	sed -n 's/^Fedora-Spec-Before:\s*//p' "$otppatch" >> "$tmpdir/patch-list-prep.txt"
a0fe45
	echo "%patch$n -p1 -b ${backupext}" >> "$tmpdir/patch-list-prep.txt"
a0fe45
	sed -n 's/^Fedora-Spec-After:\s*//p' "$otppatch" >> "$tmpdir/patch-list-prep.txt"
a0fe45
	n=$(($n + 1))
a0fe45
done < "$tmpdir/patch-list.txt"
a0fe45
echo "# end of autogenerated patch tag list" >> "$tmpdir/patch-list-tags.txt"
a0fe45
echo "# end of autogenerated prep patch list" >> "$tmpdir/patch-list-prep.txt"
a0fe45
a0fe45
# Create updated spec file
a0fe45
specfile="erlang.spec"
a0fe45
newspec1="${tmpdir}/${specfile}.new1"
a0fe45
newspec2="${tmpdir}/${specfile}.new2"
a0fe45
sed '/^# start of autogenerated patch tag list$/,$d' "$specfile" > "$newspec1"
a0fe45
cat "$tmpdir/patch-list-tags.txt" >> "$newspec1"
a0fe45
sed '1,/^# end of autogenerated patch tag list/d' "$specfile" >> "$newspec1"
a0fe45
sed '/^# start of autogenerated prep patch list$/,$d' "$newspec1" > "$newspec2"
a0fe45
cat "$tmpdir/patch-list-prep.txt" >> "$newspec2"
a0fe45
sed '1,/^# end of autogenerated prep patch list/d' "$newspec1" >> "$newspec2"
a0fe45
a0fe45
# Actually put all changes into git index
a0fe45
git rm -f otp-00*.patch
a0fe45
mv "$tmpdir/otp-00"*.patch .
a0fe45
git add otp-00*.patch
a0fe45
mv -f "$newspec2" "$specfile"
a0fe45
git add "$specfile"
a0fe45
a0fe45
rm -rf "$tmpdir"
a0fe45
# End of file.