Skip to content

Instantly share code, notes, and snippets.

@e2thenegpii
Created October 19, 2016 01:18
Show Gist options
  • Save e2thenegpii/196838306b5e901bf682e84b8d0dba49 to your computer and use it in GitHub Desktop.
Save e2thenegpii/196838306b5e901bf682e84b8d0dba49 to your computer and use it in GitHub Desktop.
git pre-commit hook to make sure all files with a given filename are encrypted with ansible-vault
#!/bin/bash
encryptedIndicator="$ANSIBLE_VAULT"
encryptedFilename="encrypted.yml"
sbe=`find $PWD -name $encryptedFilename | sort -u`
encrypted=`find $PWD -name $encryptedFilename -exec grep "$encryptedIndicator" {} -l \;| sort -u`
shouldbe=`comm -3 <(printf '%s\n' "${sbe[@]}") <(printf '%s\n' "${encrypted[@]}")`
if [ ! -z "$shouldbe" -a "$shouldbe" != " " ]; then
echo "Please check that the following files are properly encrypted"
echo "'$shouldbe'"
exit -1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment