Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #######################################################################
- # Openvpn supports inline certs and keys
- # so you have one client script, instead of script plus 4 keys and certs
- #
- # This tool requires
- # 1) openvpn script, certs and keys are in same directory
- # 2) The names of openvpn script, certs and keys as follows
- #
- ca="ca.crt"
- cert="client1.crt"
- key="client1.key"
- tlsauth="ta.key"
- ovpndest="client1.ovpn"
- ########################################################################
- # Backup to new subdirectory, just incase
- #
- mkdir -p backup
- cp $ca $cert $key $tlsauth $ovpndest ./backup
- ########################################################################
- # Delete existing call to keys and certs
- #
- sed -i \
- -e '/ca .*'$ca'/d' \
- -e '/cert .*'$cert'/d' \
- -e '/key .*'$key'/d' \
- -e '/tls-auth .*'$tlsauth'/d' $ovpndest
- ########################################################################
- # Add keys and certs inline
- #
- echo "key-direction 1" >> $ovpndest
- echo "<ca>" >> $ovpndest
- awk /BEGIN/,/END/ < ./$ca >> $ovpndest
- echo "</ca>" >> $ovpndest
- echo "<cert>" >> $ovpndest
- awk /BEGIN/,/END/ < ./$cert >> $ovpndest
- echo "</cert>" >> $ovpndest
- echo "<key>" >> $ovpndest
- awk /BEGIN/,/END/ < ./$key >> $ovpndest
- echo "</key>" >> $ovpndest
- echo "<tls-auth>" >> $ovpndest
- awk /BEGIN/,/END/ < ./$tlsauth >> $ovpndest
- echo "</tls-auth>" >> $ovpndest
- ########################################################################
- # Delete key and cert files, backup already made hopefully
- #
- rm $ca $cert $key $tlsauth
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement