Skip to content

Instantly share code, notes, and snippets.

@marzocchi
Created October 24, 2019 13:11
Show Gist options
  • Save marzocchi/421f8b13a5a260a9683f3d68e302e0d6 to your computer and use it in GitHub Desktop.
Save marzocchi/421f8b13a5a260a9683f3d68e302e0d6 to your computer and use it in GitHub Desktop.
Recover files that ended up being double-encrypted while using git-crypt
#!/bin/sh
set -e
hash() {
if [[ $# != 1 ]]; then
echo "usage: hash FILE" >&2
return 1
fi
shasum "$1" | cut -f1 -d' '
}
file $(git-crypt status -e | cut -f 2- -d':') | grep -v 'ASCII text' | cut -d: -f1 | while read f
do
tmp=$(mktemp)
cat "$f" | git-crypt smudge > "$tmp"
if [[ $(hash "$f") == $(hash "$tmp") ]]; then
echo "file $f did not change after smudge, check results in $tmp" >&2
exit 1
else
mv "$f" "$f".bkp
echo "$f" is now "$f".bkp >&2
mv "$tmp" "$f"
echo "$f" is now decrypted >&2
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment