Automate nordix openvpn user config files
[infra/tools.git] / infra / openvpn_automation / generate-user-ovpn / files / make_config.sh
diff --git a/infra/openvpn_automation/generate-user-ovpn/files/make_config.sh b/infra/openvpn_automation/generate-user-ovpn/files/make_config.sh
new file mode 100644 (file)
index 0000000..24ba4b5
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# First argument: Client identifier
+if [ -z "$1" ]
+  then
+    echo "Please provide the client identifier."
+    echo "   example: $0 jsmith.xerces.onap"
+    exit 1
+fi
+
+KEY_DIR=~/OpenVPN/client-configs/keys
+OUTPUT_DIR=~/OpenVPN/client-configs/files
+BASE_CONFIG=~/OpenVPN/client-configs/base.conf
+
+cat ${BASE_CONFIG} \
+    <(echo -e '<ca>') \
+    ${KEY_DIR}/ca.crt \
+    <(echo -e '</ca>\n<cert>') \
+    ${KEY_DIR}/${1}.crt \
+    <(echo -e '</cert>\n<key>') \
+    ${KEY_DIR}/${1}.key \
+    <(echo -e '</key>\n<tls-auth>') \
+    ${KEY_DIR}/ta.key \
+    <(echo -e '</tls-auth>') \
+    > ${OUTPUT_DIR}/${1}.ovpn
+