Skip to content

Instantly share code, notes, and snippets.

@jordiclariana
Created September 22, 2015 11:42
Show Gist options
  • Save jordiclariana/a357f676c298a430fc98 to your computer and use it in GitHub Desktop.
Save jordiclariana/a357f676c298a430fc98 to your computer and use it in GitHub Desktop.
#!/bin/bash
YAML="${1}"
[ -f "${YAML}" ] || { echo "No such file as '${YAML}'"; exit 1; }
eyaml decrypt -e "${YAML}" | awk '
{
l=$0;
getline nl;
if (nl ~ /DEC::PKCS7\[/) {
eb=1; # Encrypted block
spaces=gensub(/^( *).*/,"\\1","",nl) # Get the indentation
gsub(/DEC::PKCS7\[/, "", nl); # Get rid of the descryption header
gsub(/>/,"|",l); # subsitute > for |
# Print the blocks
print l;
print nl;
} else {
if (eb==1) { # We are into the encrypted block
if ($1 != "]!") { # Not the end of encrypted block
# Print with original identation
printf("%s%s\n", spaces, l);
printf("%s%s\n", spaces, nl);
} else { # End of encrypted block, do not print the suffix
print nl;
eb=0
}
} else { # Not in encrypted block, just print
print l;
print nl;
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment