forked from dumrauf/openvpn-terraform-install
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset_me_up.sh
executable file
·81 lines (69 loc) · 1.75 KB
/
set_me_up.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
usage()
{
echo "usage: set_me_up.sh -r us-east-1 -c ~/.aws/credentials -p default -u userOne,userTwo"
echo "-r : REGION: aws region, e.g. aws-east-1"
echo "-c : AWS_CREDENTIALS: aws credentials, usually under ~/.aws/credentials"
echo "-p : AWS_PROFILE: aws profile, specify your aws profile to use"
echo "-u : OVPN_USER_PROFILES: comma seperated list of ovpn user settings to crate, e.g. userOne,userTwo"
}
populate_settings()
{
cat << EOF > settings/custom_settings.tfvars
##############
# AWS Settings
##############
aws_region = "${REGION}"
shared_credentials_file = "${CREDS}"
profile = "${PROFILE}"
ovpn_users = [${USERS}]
EOF
}
execute_setup()
{
echo "Setting up terraform"
./terraform-bootstrap.sh
./terraform-apply.sh custom_settings
}
###########################################
############# MAIN #################
###########################################
unset option
while getopts r:c:p:u:h option
do
case ${option} in
r)
REGION=${OPTARG}
;;
c)
CREDS=${OPTARG}
;;
p)
PROFILE=${OPTARG}
;;
u)
USERS=${OPTARG}
certNumber=$(echo ${USERS} | tr -cd , | wc -c)
certNumber=$((certNumber+1))
certString=""
for i in $(seq "$certNumber")
do
extra=$(echo $USERS | cut -d"," -f${i})
certString+=\"$extra\",
echo $extra
done
USERS=$(echo $certString | sed 's/,$//')
;;
*)
usage
exit 1
;;
esac
done
if [ ! "$REGION" ] || [ ! "$CREDS" ] || [ ! "$PROFILE" ] || [ ! "$USERS" ]
then
usage
exit 1
fi
populate_settings
execute_setup