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