#!/bin/bash # # A hook script to verify what is about to be committed. # Called by "git commit" with no arguments. The hook should # exit with non-zero status after issuing an appropriate message if # it wants to stop the commit. # # This script checks if all files to be committed fit the needs for # a valid fastd-keyfile so it can be pulled to all Freifu9nk gateways # and used as public key # Redirect output to stderr. exec 1>&2 while read keyfile file; do if [ $keyfile != ".gitmodules" ]; then # sanitize last linebreak: tail -c1 "$keyfile" | read -r _ || echo >> "$keyfile" diffstr=$(cat "$keyfile" | grep -v -E "^\s*key\s+\"\w{64}\";\s*(#.*)*$" \ | grep -v -E "(^\s*#|^\s*remote|^$)") if [ "$diffstr" != "" ] ; then echo "$keyfile: you have a malformed key in your changes , you can't commit until it has been corrected:" echo "$diffstr" exit 1 fi fi done < <(git diff --cached --name-status --diff-filter=ACM | cut -f2) # check for double keys: doublekeys="$(cat *|grep key|sed -e 's/#.*$//g; s/ \+/ /g; s/^ //g; s/ $//g'|sort|uniq -c|sort|tail \ | grep -v "1 key"|cut -d" " -f 9|sed -e 's/[";]//g' \ | while read key; do \ grep -H $key *; \ done)" if [ "$doublekeys" != "" ] ; then echo "those keys are in more than one files:" echo "$doublekeys" echo "each key is only allowed in one file" exit 1 fi # optionally rename all uppercase letters with : #for f in *; do NEW="$(echo $f | tr '[A-Z]' '[a-z]')"; if [ "$f" != "$NEW" ]; then git mv -v $f $NEW; fi; done; # if you use a README file, add this too: #git mv -v _readme _README