Created
          April 21, 2018 23:55 
        
      - 
      
- 
        Save azat/62f54b27fbe6e8d86d0e82b8ad2f041d to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/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