add more vpn support things
[awsible] / createVPNAccount.sh
diff --git a/createVPNAccount.sh b/createVPNAccount.sh
new file mode 100755 (executable)
index 0000000..276d9c1
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+set -e
+
+DIR_SUFFIX="_ca"
+ME=`basename "${0}"`
+RED='\033[0;31m'
+NC='\033[0m'
+
+echo "${ME} - Create VPN Configs"
+echo ""
+
+allDone()
+{
+       echo -e "     ${RED}-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-${NC}"
+       echo -e "     ${RED}L O O K  A T  W H A T  T O  D O${NC}"
+       echo -e "     ${RED}-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-${NC}"
+       echo ""
+       echo "Assuming no failures were output above, here's what you should have:"
+       echo "  VPNConfigs/${1}-${2}.ovpn"
+       echo ""
+       echo "For Windows users, you should rename this to ${1}.ovpn and put it into the configurations directory"
+       echo "as described on the confluence page."
+       echo ""
+       echo "For Mac users (running tunnelblick) you should create a directory named ${1}.tblk and put"
+       echo "VPNConfigs/${1}-${2}.ovpn into it. Once you have that on your Mac, you should just be able"
+       echo "to double click on it."
+       echo ""
+       echo "...magics..."
+}
+
+usage(){
+       local i
+       cat<<EOF
+Usage:
+       ${ME} environment user
+Example:
+       ${ME} userStage test.user@samsung.com
+---------------------
+Currently defined environments:
+EOF
+       for i in $(ls -d1 *${DIR_SUFFIX})
+       do
+               echo " - ${i%${DIR_SUFFIX}}"
+       done
+       exit
+}
+
+genConfiguration(){
+       local environment="$1"
+       local user="$2"
+
+       userManagementTemplates/"${environment}".sh "${environment}" "${user}" > "VPNConfigs/${environment}-${user}.ovpn"
+}
+
+if  [ -z $2 ] || [ "$1" == "-h" ]  ; then
+       usage;
+fi
+if [ ! -d "${1}${DIR_SUFFIX}" ] || [ ! -e "userManagementTemplates/${1}.sh" ] ; then
+       echo "Invalid configuration profile: ${1}"
+       echo ""
+       usage
+fi
+
+if [ -e ${1}${DIR_SUFFIX}/pki/issued/${2}.crt ]; then
+       echo "${2} already has a certificate..."
+       echo ""
+       genConfiguration "${1}" "${2}"
+else
+       echo "Well, you didn't ask for help, and you provided a valid profile, and the user doesn't already exist..."
+       echo ""
+       echo -e "${RED}**************************************************************************${NC}"
+       echo -e "${RED}***                                                                    ***${NC}"
+       echo -e "${RED}*** ${NC}The next step will ask you for a password, this is the CA password ${RED}***${NC}"
+       echo -e "${RED}***                                                                    ***${NC}"
+       echo -e "${RED}**************************************************************************${NC}"
+
+       pushd "${1}${DIR_SUFFIX}" >/dev/null
+       ./easyrsa build-client-full "${2}" nopass
+       popd >/dev/null
+       genConfiguration "${1}" "${2}"
+fi
+
+allDone "${1}" "${2}"