scramblevpn

merge raspberrypi ovpn

Mar 27th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.82 KB | None | 0 0
  1. #!/bin/bash
  2. #######################################################################
  3. #       Latest versions of 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 assumes
  7. #       1) Openvpn script and certs plus keys are in same directory
  8. #       2) Certs are usually specified in Openvpn script like
  9. #          ca ca.crt
  10. #             or
  11. #          ca /etc/local/openvpn/ca.crt
  12. ########################################################################
  13. #  Name of certs and keys and client ovpn script
  14. #
  15.  
  16. ca="ca.crt"
  17. cert="client1.crt"
  18. key="client1.key"
  19. tlsauth="ta.key"
  20. ovpndest="raspberrypi.ovpn"
  21.  
  22. ########################################################################
  23. #   Backup to new subdirectory, just incase
  24. #
  25. mkdir -p backup
  26. cp $ca $cert $key $tlsauth $ovpndest ./backup
  27.  
  28. ########################################################################
  29. #   Delete existing call to keys and certs
  30. #
  31.     sed -i \
  32.     -e '/ca .*'$ca'/d'  \
  33.     -e '/cert .*'$cert'/d' \
  34.     -e '/key .*'$key'/d' \
  35.     -e '/tls-auth .*'$tlsauth'/d' $ovpndest
  36.  
  37. ########################################################################
  38. #   Add keys and certs inline
  39. #
  40. echo "key-direction 1" >> $ovpndest
  41.  
  42. echo "<ca>" >> $ovpndest
  43. awk /BEGIN/,/END/ < ./$ca >> $ovpndest
  44. echo "</ca>" >> $ovpndest
  45.  
  46. echo "<cert>" >> $ovpndest
  47. awk /BEGIN/,/END/ < ./$cert >> $ovpndest
  48. echo "</cert>" >> $ovpndest
  49.  
  50. echo "<key>" >> $ovpndest
  51. awk /BEGIN/,/END/ < ./$key >> $ovpndest
  52. echo "</key>" >> $ovpndest
  53.  
  54. echo "<tls-auth>" >> $ovpndest
  55. awk /BEGIN/,/END/ < ./$tlsauth >> $ovpndest
  56. echo "</tls-auth>" >> $ovpndest
  57.  
  58. ########################################################################
  59. #   Delete key and cert files, backup already made hopefully
  60. #
  61. rm $ca $cert $key $tlsauth
Add Comment
Please, Sign In to add comment