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