Skip to content

Instantly share code, notes, and snippets.

@azat
Created April 21, 2018 23:55
Show Gist options
  • Save azat/62f54b27fbe6e8d86d0e82b8ad2f041d to your computer and use it in GitHub Desktop.
Save azat/62f54b27fbe6e8d86d0e82b8ad2f041d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function match()
{
local f="$1" && shift
[[ "$f" =~ [^/]*\.conf$ ]] && {
local o=(
'^cert '
'^key '
'^tls-auth '
'^ca '
)
eval egrep -v $(printf -- "-e %s " "${o[@]}") "$f"
echo
return
}
[[ "$f" =~ /ta\.[^/]*$ ]] && {
echo
echo "<tls-auth>"
cat "$f"
echo "</tls-auth>"
echo "key-direction 1"
return
}
[[ "$f" =~ /ca\.[^/]*$ ]] && {
echo
echo "<ca>"
cat "$f"
echo "</ca>"
return
}
[[ "$f" =~ [^/]*\.crt ]] && {
echo
echo "<cert>"
cat "$f"
echo "</cert>"
return
}
[[ "$f" =~ [^/]*\.key ]] && {
echo
echo "<key>"
cat "$f"
echo "</key>"
return
}
}
function main()
{
local dir="$(readlink -f "$1")"
shift
local f
for f in "$dir"/*; do
match "$f"
done
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment