Skip to content

Instantly share code, notes, and snippets.

@jackorp
Created July 15, 2021 20:37
Show Gist options
  • Save jackorp/f3c95fea8f4c98724d210b210916a13d to your computer and use it in GitHub Desktop.
Save jackorp/f3c95fea8f4c98724d210b210916a13d to your computer and use it in GitHub Desktop.
#!/bin/bash
file="$1"
if [ -z "$file" ]; then
file="ruby.spec"
fi
function die {
for var in "$@"
do
echo "$var" 1>&2
done
exit 1
}
sources=""
applied=""
existing=""
# Get patches that are packaged
sources=$(grep -e "^Patch[0-9]*:" $file)
# Get patches that are applied
applied=$(sed -nr 's/%patch([0-9]*).*/\1/p' $file)
# Get patches in current dir
if [ -z "$(ls $file)" ]; then
die "No specfile found... are we in the correct directory?"
else
existing=$(ls -- *.patch)
fi
if [[ "$applied" == $(echo "$sources" | cut -d':' -f 1 | sed -nr 's/Patch([0-9]*)/\1/p') ]]; then
echo "Specfile matches ✓"
else
die "Mismatch of patches in specfile \n" "$sources" "$applied"
fi
read -r -d '' RSCA << EOR
existing = "$existing".split("\n").sort
sources = "$sources".split("\n").map { |e| e.split(':') }.flatten.reject { |e| e =~ /^Patch/ }.sort.map(&:strip).sort
puts (existing == sources)
EOR
if [[ $(ruby -e "$RSCA") == "true" ]]; then
echo "Patches sources match ✓"
else
die "Mismatch of sources" "$existing" "$(echo "$sources" | cut -d' ' -f 2)"
fi
git_patches=$(git ls-files | grep ".patch")
read -r -d '' RSCB << EOR
sources = "$git_patches".split("\n").sort
existing = "$sources"
.split("\n")
.map { |e| e.split(':') }
.flatten
.reject { |e| e =~ /^Patch/ }
.map(&:strip).sort
puts (existing == sources)
EOR
if [[ $(ruby -e "$RSCB") == "true" ]]; then
echo "Git patches are used ✓"
else
die "Unused patches present in git" "$existing" "$(echo "$sources" | cut -d' ' -f 2)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment