ignore amazon-linux ami release-candidate versions
[awsible] / createVPNAccount.sh
1 #!/bin/bash
2
3 set -e
4
5 DIR_SUFFIX="_ca"
6 ME=`basename "${0}"`
7 RED='\033[0;31m'
8 NC='\033[0m'
9
10 echo "${ME} - Create VPN Configs"
11 echo ""
12
13 allDone()
14 {
15 echo -e " ${RED}-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-${NC}"
16 echo -e " ${RED}L O O K A T W H A T T O D O${NC}"
17 echo -e " ${RED}-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-${NC}"
18 echo ""
19 echo "Assuming no failures were output above, here's what you should have:"
20 echo " VPNConfigs/${1}-${2}.ovpn"
21 echo ""
22 echo "For Windows users, you should rename this to ${1}.ovpn and put it into the configurations directory"
23 echo "as described on the confluence page."
24 echo ""
25 echo "For Mac users (running tunnelblick) you should create a directory named ${1}.tblk and put"
26 echo "VPNConfigs/${1}-${2}.ovpn into it. Once you have that on your Mac, you should just be able"
27 echo "to double click on it."
28 echo ""
29 echo "...magics..."
30 }
31
32 usage(){
33 local i
34 cat<<EOF
35 Usage:
36 ${ME} environment user
37 Example:
38 ${ME} userStage test.user@samsung.com
39 ---------------------
40 Currently defined environments:
41 EOF
42 for i in $(ls -d1 *${DIR_SUFFIX})
43 do
44 echo " - ${i%${DIR_SUFFIX}}"
45 done
46 exit
47 }
48
49 genConfiguration(){
50 local environment="$1"
51 local user="$2"
52
53 userManagementTemplates/"${environment}".sh "${environment}" "${user}" > "VPNConfigs/${environment}-${user}.ovpn"
54 }
55
56 if [ -z $2 ] || [ "$1" == "-h" ] ; then
57 usage;
58 fi
59 if [ ! -d "${1}${DIR_SUFFIX}" ] || [ ! -e "userManagementTemplates/${1}.sh" ] ; then
60 echo "Invalid configuration profile: ${1}"
61 echo ""
62 usage
63 fi
64
65 if [ -e ${1}${DIR_SUFFIX}/pki/issued/${2}.crt ]; then
66 echo "${2} already has a certificate..."
67 echo ""
68 genConfiguration "${1}" "${2}"
69 else
70 echo "Well, you didn't ask for help, and you provided a valid profile, and the user doesn't already exist..."
71 echo ""
72 echo -e "${RED}**************************************************************************${NC}"
73 echo -e "${RED}*** ***${NC}"
74 echo -e "${RED}*** ${NC}The next step will ask you for a password, this is the CA password ${RED}***${NC}"
75 echo -e "${RED}*** ***${NC}"
76 echo -e "${RED}**************************************************************************${NC}"
77
78 pushd "${1}${DIR_SUFFIX}" >/dev/null
79 ./easyrsa build-client-full "${2}" nopass
80 popd >/dev/null
81 genConfiguration "${1}" "${2}"
82 fi
83
84 allDone "${1}" "${2}"