Skip to content

Instantly share code, notes, and snippets.

@emptyset
Created July 12, 2013 03:53
Show Gist options
  • Save emptyset/5981276 to your computer and use it in GitHub Desktop.
Save emptyset/5981276 to your computer and use it in GitHub Desktop.
This is probably an over-engineered shell script that can be used to modify .ovpn files from vpngate.net so that they can be easily imported into the openvpn GUI that is included with stock Ubuntu installations.
FILE=$1
FILENAME=${FILE%%.*}
# extract the keys and certificates
sed -n "/<ca>/,/<\/ca>/p" $FILE > $FILENAME.ca.crt-tmp
sed -n "/<cert>/,/<\/cert>/p" $FILE > $FILENAME.crt-tmp
sed -n "/<key>/,/<\/key>/p" $FILE > $FILENAME.key-tmp
# modify the keys and certificates
sed '/ca>/d' $FILENAME.ca.crt-tmp > $FILENAME.ca.crt
sed '/cert>/d' $FILENAME.crt-tmp > $FILENAME.crt
sed '/key>/d' $FILENAME.key-tmp > $FILENAME.key
# modify the ovpn file
sed "/<ca>/,/<\/ca>/d" $FILE > $FILENAME.modified.ovpn.1-tmp
sed "/<cert>/,/<\/cert>/d" $FILENAME.modified.ovpn.1-tmp > $FILENAME.modified.ovpn.2-tmp
sed "/<key>/,/<\/key>/d" $FILENAME.modified.ovpn.2-tmp > $FILENAME.modified.ovpn.3-tmp
sed '/key-direction/d' $FILENAME.modified.ovpn.3-tmp > $FILENAME.modified.ovpn
echo "ca $FILENAME.ca.crt" >> $FILENAME.modified.ovpn
echo "cert $FILENAME.crt" >> $FILENAME.modified.ovpn
echo "key $FILENAME.key" >> $FILENAME.modified.ovpn
echo "remote-cert-tls server" >> $FILENAME.modified.ovpn
# clean up temp files
rm *-tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment