-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.sh
executable file
·62 lines (52 loc) · 2.18 KB
/
manage.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
#!/bin/bash
validate_requirements() {
command -v aws >/dev/null 2>&1 || { echo >&2 "Script requires aws CLI (https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)"; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "Script requires jq (https://stedolan.github.io/jq/download/)"; exit 1; }
command -v pipenv run sceptre >/dev/null 2>&1 || { echo >&2 "Run 'pipenv install'"; exit 1; }
}
get_nameservers() {
aws_region=$(grep 'region' config.yaml | cut -d ' ' -f 2)
hosted_zone_ids=$(aws cloudformation --region ${aws_region} describe-stacks --stack-name gophish-hosted-zones-stack --query 'Stacks[0].Outputs[].OutputValue' | jq -r '.[]')
printf "\nSet the following DNS nameservers for each domain:\n"
printf '=%.0s' {1..50}
for zone_id in ${hosted_zone_ids}; do
hostedzone_data=$(aws route53 get-hosted-zone --id "${zone_id}")
domain=$(echo "${hostedzone_data}" | jq -r ".HostedZone.Name")
declare -a nameservers=($(echo "${hostedzone_data}" | jq -r ".DelegationSet.NameServers[]"))
printf "\nDomain: ${domain}\n"
for ns in "${nameservers[@]}"; do
printf "\t${ns}\n"
done
done
printf '=%.0s' {1..50}
}
print_instance_ip() {
aws_region=$(grep 'region' config.yaml | cut -d ' ' -f 2)
instance_metadata=$(aws ec2 --region ${aws_region} describe-instances --filters "Name=tag:Name,Values=Gophish (gophish-platform-stack)" "Name=instance-state-name,Values=running")
ip=$(echo "${instance_metadata}" | jq -r '.Reservations[] | .Instances[] | .PublicIpAddress')
printf "\nInstance IP: ${ip}\n"
}
parse_arguments() {
CMD="${1}"
case ${CMD} in
"update_zones")
pipenv run sceptre --var-file config.yaml launch hosted-zones -y
get_nameservers
;;
"update_platform")
pipenv run sceptre --var-file config.yaml launch platform -y
echo "Waiting 30sec for instance to start..."; sleep 30
print_instance_ip
;;
*)
echo """ERROR: Please provide a valid command. Usage:
./manage.sh
update_zones
update_platform
"""
exit 99
;;
esac
}
validate_requirements
parse_arguments "$@"