Advertisement
scramblevpn

merge client1 ovpn

Mar 15th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.59 KB | None | 0 0
  1. #!/bin/bash
  2. #######################################################################
  3. #       Openvpn supports inline certs and keys
  4. #       so you have one client script, instead of script plus 4 keys and certs
  5. #
  6. #       This tool requires
  7. #       1) openvpn script, certs and keys are in same directory
  8. #       2) The names of openvpn script, certs and keys as follows
  9. #
  10.  
  11. ca="ca.crt"
  12. cert="client1.crt"
  13. key="client1.key"
  14. tlsauth="ta.key"
  15. ovpndest="client1.ovpn"
  16.  
  17. ########################################################################
  18. #   Backup to new subdirectory, just incase
  19. #
  20. mkdir -p backup
  21. cp $ca $cert $key $tlsauth $ovpndest ./backup
  22.  
  23. ########################################################################
  24. #   Delete existing call to keys and certs
  25. #
  26.     sed -i \
  27.     -e '/ca .*'$ca'/d'  \
  28.     -e '/cert .*'$cert'/d' \
  29.     -e '/key .*'$key'/d' \
  30.     -e '/tls-auth .*'$tlsauth'/d' $ovpndest
  31.  
  32. ########################################################################
  33. #   Add keys and certs inline
  34. #
  35. echo "key-direction 1" >> $ovpndest
  36.  
  37. echo "<ca>" >> $ovpndest
  38. awk /BEGIN/,/END/ < ./$ca >> $ovpndest
  39. echo "</ca>" >> $ovpndest
  40.  
  41. echo "<cert>" >> $ovpndest
  42. awk /BEGIN/,/END/ < ./$cert >> $ovpndest
  43. echo "</cert>" >> $ovpndest
  44.  
  45. echo "<key>" >> $ovpndest
  46. awk /BEGIN/,/END/ < ./$key >> $ovpndest
  47. echo "</key>" >> $ovpndest
  48.  
  49. echo "<tls-auth>" >> $ovpndest
  50. awk /BEGIN/,/END/ < ./$tlsauth >> $ovpndest
  51. echo "</tls-auth>" >> $ovpndest
  52.  
  53. ########################################################################
  54. #   Delete key and cert files, backup already made hopefully
  55. #
  56. rm $ca $cert $key $tlsauth
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement