systemd/debian/systemd-hack-up-the-source.hook

74 lines
1.9 KiB
Bash
Executable File

#! /bin/sh
set -e
set -x
. /usr/share/gitpkg/hooks/repo-config-helper
find -name Makefile -type l -print -delete
#rm -r src/Makefile
#. /usr/share/gitpkg/hooks/quilt-patches-deb-export-hook
patch_list=debian/source/git-patches
patch_dir=debian/patches
if [ ! -r "$patch_list" ]; then
echo "No $patch_list file, I guess you've pushed them all upstream."
echo "Good Work!"
exit 0
fi
if [ -e "$patch_dir" ]; then
echo "Uh oh. You already have a $patch_dir here."
echo "You probably don't want us to scribble on that without asking."
exit 1
fi
if [ -z "$REPO_DIR" ]; then
# support running as a free-standing script, without gitpkg
DEB_VERSION="$(dpkg-parsechangelog | sed -rne 's/^Version: ([^:]+:)?//p')"
UPSTREAM_VERSION="${DEB_VERSION%-*}"
REPO_DIR=.
fi
DEB_REF=$(sanitise_git_ref $DEB_VERSION)
UPSTREAM_REF="${DEB_REF%-*}"
do_patches (){
while read -r line
do
[ -n "$line" ] || continue
case $line in
\#*)
;;
*)
count=$(wc -l "$patch_dir/series" | cut -f1 -d' ')
if PATCHES="$(git --git-dir "$REPO_DIR/.git" diff "$line" > "$patch_dir/$line")"; then
if [ -n "$PATCHES" ]; then
echo "$PATCHES" | sed -e "s,$patch_dir/,,g" -e 's, ,\n,g' >> "$patch_dir/series"
else
echo "Warning: no patches from $line"
fi
else
echo "git --git-dir '$REPO_DIR/.git' diff '$line'"
echo "failed."
exit 1
fi
esac
done
}
mkdir -p "$patch_dir" || exit 1
echo "# $patch_list exported from git by export-hook" > "$patch_dir/series"
(sed -e "s/\$DEB_VERSION/$DEB_VERSION/g" \
-e "s/\${DEB_VERSION}/$DEB_VERSION/g" \
-e "s/\$UPSTREAM_VERSION/$UPSTREAM_VERSION/g" \
-e "s/\${UPSTREAM_VERSION}/$UPSTREAM_VERSION/g" \
-e "s/\$DEB_REF/$DEB_REF/g" \
-e "s/\${DEB_REF}/$DEB_REF/g" \
-e "s/\$UPSTREAM_REF/$UPSTREAM_REF/g" \
-e "s/\${UPSTREAM_REF}/$UPSTREAM_REF/g" \
< "$patch_list" ; echo ) | do_patches || exit 1