4fe40e
#!/usr/bin/bash
Harald Hoyer 126bbe
4fe40e
bash -n "$0" || exit 1
4fe40e
shopt -s extglob
4fe40e
4fe40e
patchnr() {
4fe40e
    local nr
4fe40e
    while [[ -n "$1" ]]; do
4fe40e
        nr=$(cut -d'.' -f1 <<< "$1")
4fe40e
        shift
4fe40e
        [[ $((10#$nr)) -gt 0 ]] || echo "Invalid patch number: $nr" >&2
4fe40e
        echo "$nr"
4fe40e
    done
4fe40e
}
4fe40e
4fe40e
if [[ -e "$HOME/git/dracut/$1" ]]; then
Harald Hoyer 126bbe
    srcrpm="$HOME/git/dracut/$1"
4fe40e
elif [[ -e "$HOME/dev/upstream/dracut/$1" ]]; then
4fe40e
    srcrpm="$HOME/dev/upstream/dracut/$1"
Harald Hoyer 126bbe
else
Harald Hoyer 126bbe
    srcrpm="$1"
Harald Hoyer 126bbe
fi
Harald Hoyer 126bbe
4fe40e
[[ -f $srcrpm ]] || exit 3
4fe40e
4fe40e
old_release=$(rpmspec -D "_sourcedir $(pwd)" -q --srpm --qf '%{release}' dracut.spec)
4fe40e
old_release=${old_release%%.*}
Harald Hoyer 126bbe
Harald Hoyer 126bbe
cp dracut.spec dracut.spec.old
4fe40e
4fe40e
rm *.patch; git reset --hard HEAD
4fe40e
last_patch_nr=$(patchnr *.patch | sort -n | tail -n 1)
4fe40e
last_patch_nr=${last_patch_nr:-0000}
4fe40e
#for i in *.patch; do git rm -f $i;done
Harald Hoyer 126bbe
Harald Hoyer 126bbe
if rpm -ivh --define "_srcrpmdir $PWD" --define "_specdir $PWD" --define "_sourcedir $PWD" "$srcrpm"; then
4fe40e
	  for nr in $(patchnr *.patch); do
4fe40e
	    [[ $((10#$nr)) -gt $((10#$last_patch_nr)) ]] && git add "${nr}.patch"
4fe40e
    done
4fe40e
4fe40e
    new_version=$(rpmspec -D "_sourcedir $(pwd)" -q --srpm --qf '%{version}' dracut.spec)
4fe40e
    new_release=$(rpmspec -D "_sourcedir $(pwd)" -q --srpm --qf '%{release}' dracut.spec)
4fe40e
    new_release_full=${new_release%.*}
4fe40e
    new_release=${new_release%%.*}
4fe40e
4fe40e
    do_print=""
4fe40e
    while IFS=$'\n' read -r line
4fe40e
    do
4fe40e
        if [ -z "$do_print" ] && [ "$line" = "%changelog" ]; then
4fe40e
            do_print="yes"
4fe40e
            echo "* $(LANG='C' date '+%a %b %d %Y') $(git config user.name) <$(git config user.email)> - ${new_version}-${new_release_full}"
4fe40e
4fe40e
            for ((i=old_release; i
4fe40e
                subject=$(grep '^Subject: ' +(0)$i.patch | head -1)
4fe40e
                if [ -n "$subject" ]; then
4fe40e
                    echo "-${subject#*\[PATCH\]}"
4fe40e
                fi
4fe40e
            done
4fe40e
4fe40e
            echo
4fe40e
4fe40e
        elif [ -n "$do_print" ]; then
4fe40e
            echo "$line"
4fe40e
        fi
4fe40e
    done < dracut.spec.old >> dracut.spec
4fe40e
4fe40e
    # Patch list:
4fe40e
    # ls *.patch | tr -s ' ' '\n' | cut -d'.' -f1 | xargs -i zsh -c "nr=\$((10#{})); echo \"Patch\${nr}: {}.patch\""
4fe40e
4fe40e
    git add dracut.spec
4fe40e
4fe40e
    msg="Resolves: $(
4fe40e
    for ((i=old_release; i
4fe40e
        resolves=$(grep '^Resolves: ' +(0)$i.patch | head -1)
4fe40e
        if [ -n "$resolves" ]; then
4fe40e
            echo "${resolves#Resolves: }"
4fe40e
        fi
4fe40e
    done | sed -e 's/rhbz#/#/g' | sort -u | tr -s '\n' ',')"
4fe40e
4fe40e
    git commit -m "$(echo -e "dracut-${new_version}-${new_release_full}\n\n${msg%,}")"
4fe40e
Harald Hoyer 126bbe
fi