Advertisement
Guest User

Bash script to add openvpn keys and certs inline

a guest
Sep 17th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. #   Define names of certs and keys and client ovpn script
  4. #
  5. ca="capi.crt"
  6. cert="clientpi.crt"
  7. key="clientpi.key"
  8. tlsauth="tapi.key"
  9. ovpndest="raspberry.ovpn"
  10.  
  11. #   Delete existing call to keys and certs
  12. #
  13.     sed -i \
  14.     -e '/ca '$ca'/d'  \
  15.     -e '/cert '$cert'/d' \
  16.     -e '/key '$key'/d' \
  17.     -e '/tls-auth '$tlsauth'/d' $ovpndest
  18.  
  19. #   Add keys and certs inline
  20. #
  21. echo "key-direction 1" >> $ovpndest
  22.  
  23. echo "<ca>" >> $ovpndest
  24. awk /BEGIN/,/END/ < ./$ca >> $ovpndest
  25. echo "</ca>" >> $ovpndest
  26.  
  27. echo "<cert>" >> $ovpndest
  28. awk /BEGIN/,/END/ < ./$cert >> $ovpndest
  29. echo "</cert>" >> $ovpndest
  30.  
  31. echo "<key>" >> $ovpndest
  32. awk /BEGIN/,/END/ < ./$key >> $ovpndest
  33. echo "</key>" >> $ovpndest
  34.  
  35. echo "<tls-auth>" >> $ovpndest
  36. awk /BEGIN/,/END/ < ./$tlsauth >> $ovpndest
  37. echo "</tls-auth>" >> $ovpndest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement