From: Ian Kelling Date: Mon, 26 Jun 2017 21:27:15 +0000 (-0700) Subject: stop using uuid always X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=dfbfe58ae8f9e2a80fde7279fc1608ef6e32c6fa;p=vpn-setup stop using uuid always --- diff --git a/vpn-mk-client-cert b/vpn-mk-client-cert index bd946dd..f480d02 100755 --- a/vpn-mk-client-cert +++ b/vpn-mk-client-cert @@ -13,11 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# usage: $0 SERVER_HOST [DEST_HOST] -# ssh to SERVER_HOST, create a cert & client config, put it on -# DEST_HOST, or localhost by default. Assumes server was setup -# by the other script in this dir. - set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR @@ -27,51 +22,91 @@ usage() { cat </dev/null -# uuidgen because common name must be unique -{ echo -e '\n\n\n\n\n'\$(uuidgen)'\n\n\n\n\n'; sleep 2; echo -e 'y\ny\n'; } | ./build-key $name &>/dev/null +exists=true +for x in /etc/openvpn/easy-rsa/keys/{$name.{crt,key},ca.crt}; do + if [[ ! -e \$x ]]; then + exists=false + break + fi +done + +if ! \$exists; then + cd /etc/openvpn/easy-rsa + source vars >/dev/null + + { echo -e '\n\n\n\n\n'$common_name'\n\n\n\n\n'; sleep 2; echo -e 'y\ny\n'; } | ./build-key $name &>/dev/null +fi d=\$(mktemp -d) cp /etc/openvpn/easy-rsa/keys/ca.crt \$d/$name-ca.crt -mv /etc/openvpn/easy-rsa/keys/$name.{crt,key} \$d +cp /etc/openvpn/easy-rsa/keys/$name.{crt,key} \$d tar cz -C \$d . rm -rf \$d EOF -cat > /etc/openvpn/client/$name.conf <