diff --git a/scripts/pkgs-update-hook/update.secondary b/scripts/pkgs-update-hook/update.secondary new file mode 100644 index 0000000..c39e268 --- /dev/null +++ b/scripts/pkgs-update-hook/update.secondary @@ -0,0 +1,57 @@ +#!/bin/bash + +# Maximum file size in bytes +MAX_SIZE=20000 + +tmp=$(mktemp /tmp/git.update.XXXXXX) +tree=$(mktemp /tmp/git.diff-tree.XXXXXX) +bad_file_found=0 + +git diff-tree -r "$2" "$3" > $tree +while read old_mode new_mode old_sha1 new_sha1 status name; do + # skip lines showing parent commit + [[ -z "$new_sha1" ]] && continue; + + # skip deletions + [[ "$new_sha1" = "0000000000000000000000000000000000000000" ]] && continue + + # Skip files named *patch + if [[ "$name" =~ [.]patch$ ]]; then + continue + fi + + git cat-file blob $new_sha1 > $tmp + ftype="$((file "$tmp" | awk -F': ' '{print $2}') 2>/dev/null)" + fsize=$(stat -c%s "$tmp") + + if [[ $fsize -gt $MAX_SIZE ]]; then + echo "File $name - exceeds maximum permitted size $MAX_SIZE" + bad_file_found=1 + fi + + # Banned archive types + #echo $ftype + if [[ $ftype =~ "Zip archive" ]]; then + echo "File $name - please upload zip files to the lookaside instead" + bad_file_found=1 + fi + if [[ $ftype =~ "compressed data" ]]; then + echo "File $name - please upload compressed files to the lookaside instead" + bad_file_found=1 + fi + if [[ $ftype =~ "tar archive" ]]; then + echo "File $name - please upload tarballs to the lookaside instead" + bad_file_found=1 + fi + +done < $tree + +rm -f $tmp +if [[ $bad_file_found -eq 1 ]]; then + echo "====================" + echo "Your commit contained problematic files." + echo "Please see http://fedoraproject.org/wiki/foo for more information." + echo "====================" +fi + +exit $bad_file_found