Blame otp-get-patches.sh

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