0
Fork 0
mirror of https://codeberg.org/librewolf/source.git synced 2024-12-22 05:33:03 -05:00
LibreWolf/scripts/fix-patch.sh

49 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2023-03-15 06:00:26 -05:00
#!/usr/bin/bash
set -eu
if [ $# -ne 1 ]; then
echo "Usage: $0 <path to patch>"
exit 1
fi
if [ "$1" == "${1%.patch}" ]; then
echo "Error: '$1' does not seem to be a patch."
exit 1
fi
cd "$(dirname "$0")/.."
version="$(cat version)"
if [ -d "firefox-$version" ]; then
echo "-> Removing old 'firefox-$version'"
rm -rf "firefox-$version"
fi
echo "-> Extracting 'firefox-$version.source.tar.xz'"
make "firefox-$version.source.tar.xz"
tar xf "firefox-$version.source.tar.xz"
cd "firefox-$version"
2023-03-15 06:25:17 -05:00
echo "-> Setting up git"
2023-03-15 06:00:26 -05:00
git init
files="$(cat ../$1 | grep '+++ b/' | sed 's/\+\+\+ b\///')"
echo "$files" | xargs touch
echo "$files" | xargs git add
2023-03-15 06:25:17 -05:00
echo "-> Trying to apply patch"
2023-03-15 07:13:40 -05:00
rejects="$(patch -p1 -i "../$1" | tee /dev/stderr | sed -r --quiet 's/^.*saving rejects to file (.*\.rej)$/\1/p')"
2023-03-15 06:25:17 -05:00
2023-03-15 07:13:40 -05:00
echo "-> Done. You can now fix the patch. If you are done, press enter to"
echo " update the patch with your changes or Ctrl+C to abort."
echo "$rejects" | xargs code &
2023-03-15 06:25:17 -05:00
read
echo "-> Updating patch"
2023-03-15 07:13:40 -05:00
sed -i '/^[^#]/d' "../$1"
2023-03-15 09:06:17 -05:00
git diff | sed '/^diff --git /,+1 d' >>"../$1"
2023-03-15 07:13:40 -05:00
sed -i '1{/^$/d}' "../$1"
2023-03-15 06:25:17 -05:00
echo "-> Cleaning up"
cd ..
rm -rf "firefox-$version"