Skip to content

Instantly share code, notes, and snippets.

@n-st
Created August 9, 2015 13:07
Show Gist options
  • Save n-st/666f7b89f5539380d010 to your computer and use it in GitHub Desktop.
Save n-st/666f7b89f5539380d010 to your computer and use it in GitHub Desktop.
Git pre-commit hook: Reject commit if a DNS zone file has been changed without changing its SOA serial. The serial needs to be on a separate line that contains ' ; serial'.
#!/bin/bash
# Check if all changed zone files have had their SOA serial incremented.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Redirect output to stderr.
exec 1>&2
fail=0
while IFS= read -r file
do
if grep ' ; serial' "$file" > /dev/null && ! (git diff --staged "$file" | grep ' ; serial' > /dev/null)
then
echo "SOA serial for zone file '$file' has not been changed!"
fail=1
fi
done < <(git diff --cached --name-only --diff-filter=M)
exit $fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment