X-Git-Url: https://iankelling.org/git/?p=vpn-setup;a=blobdiff_plain;f=vpn-mk-client-cert;h=f480d02b8e4cf7bbcac1ac400d99253ca41bf381;hp=bd946dd88341a8ba8197f056bf2f26a767bd02ca;hb=dfbfe58ae8f9e2a80fde7279fc1608ef6e32c6fa;hpb=45b747be876918d04c2013b9ba519a2770b61cd0 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 <