-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.shared.bash
101 lines (97 loc) · 3.7 KB
/
.shared.bash
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
HOST_IP="$(curl -s http://whatismyip.akamai.com/)"
AWS_USE_PROFILE=${AWS_USE_PROFILE:-true}
AWS_CRED_FILE_LOCATION="${AWS_CRED_FILE_LOCATION:-"${HOME}/.aws/credentials"}"
AWS_BUILD_CLOUD_MAC_INSTANCE_TYPE="${AWS_BUILD_CLOUD_MAC_INSTANCE_TYPE:-""}"
EXTRA_CONTAINS="| [?contains(Name,\\\`arm64\\\`) == \\\`false\\\`]"
if [[ -z "${AWS_BUILD_CLOUD_MAC_INSTANCE_TYPE}" ]]; then
AWS_BUILD_CLOUD_MAC_INSTANCE_TYPE="mac1.metal"
fi
if [[ "${AWS_BUILD_CLOUD_MAC_INSTANCE_TYPE}" == "mac2.metal" ]]; then
EXTRA_CONTAINS="| [?contains(Name,\\\`arm64\\\`) == \\\`true\\\`]"
fi
AWS_BUILD_CLOUD_INSTANCE_TYPE="${AWS_BUILD_CLOUD_INSTANCE_TYPE:-"t2.small"}"
AWS_BUILD_CLOUD_UNIQUE_LABEL="${AWS_BUILD_CLOUD_UNIQUE_LABEL:-"anka-build-demo-cloud"}"
AWS_ANKA_NODE_UNIQUE_LABEL="${AWS_ANKA_NODE_UNIQUE_LABEL:-"anka-build-demo-node"}"
AWS_ANKA_NODE_UNIQUE_LABEL_PURPOSE="${AWS_ANKA_NODE_UNIQUE_LABEL_PURPOSE:-"${AWS_ANKA_NODE_UNIQUE_LABEL}"}"
AWS_NONUNIQUE_LABEL="${AWS_NONUNIQUE_LABEL:-"anka-build-demo"}"
AWS_AUTHORIZE_CIDR="${AWS_AUTHORIZE_CIDR:-"${HOST_IP}/32"}"
aws_execute() {
VERBOSE=true
CAPTURE_RETURN=false
if [ $# -ne 0 ]; then
unset opt OPTARG OPTIND
while getopts "sr" opt; do
case "${opt}" in
s )
VERBOSE=false
;;
r )
CAPTURE_RETURN=true
;;
: ) echo "Invalid Option: -${OPTARG} requires an argument." 1>&2;;
* ) echo "test" ;;
esac
done
fi
shift $((OPTIND-1))
$AWS_USE_PROFILE && [[ -z "${AWS_PROFILE}" ]] && error "Unable to find AWS_PROFILE environment variable... Must be set."
RETURNED="$(
eval "$VERBOSE && set -x; aws $*;" || ({ RC=$?; set +x; } 2>/dev/null; echo $RC; )
)"
[[ "$RETURNED" =~ ^-?[0-9]+$ ]] && exit $RETURNED
$CAPTURE_RETURN && echo "${RETURNED}" || true
}
aws_obtain_profile() {
if [[ ! -z "${AWS_PROFILE}" ]] && [ $(grep -c ^\\[${AWS_PROFILE}\\] $AWS_CRED_FILE_LOCATION) -lt 1 ]; then
echo "${COLOR_YELLOW}Profile \"${AWS_PROFILE}\" not found...${COLOR_NC}"
unset AWS_PROFILE
fi
if [[ -z "${AWS_PROFILE}" ]]; then
while true; do
read -p "Which AWS profile would you like to use? (type the full name from the ~/.aws/credentials file): " AWS_PROFILE
case "${AWS_PROFILE}" in
"" ) echo "${COLOR_RED}Please type the name of the profile to use...${COLOR_NC}";;
* )
if [ $(grep -c ^\[${AWS_PROFILE}\] $AWS_CRED_FILE_LOCATION) -lt 1 ]; then
echo "${COLOR_YELLOW}Profile \"${AWS_PROFILE}\" not found...${COLOR_NC}"
else
break
fi
;;
esac
echo ""
done
fi
echo "] AWS Profile: ${COLOR_GREEN}${AWS_PROFILE}${COLOR_NC}";
}
aws_obtain_region() {
if [[ -z "${AWS_REGION}" ]]; then
while true; do
read -p "Which AWS region would you like to use?: " AWS_REGION
case "${AWS_REGION}" in
"" ) echo "${COLOR_YELLOW}Please type the name of the region to use...${COLOR_NC}";;
* ) break;;
esac
echo ""
done
fi
echo "] AWS Region: ${COLOR_GREEN}${AWS_REGION}${COLOR_NC}";
}
aws_obtain_key_pair() {
if [[ -z "${AWS_KEY_PAIR_NAME}" ]]; then
while true; do
read -p "Which AWS key pair would you like to use when creating the instance?: " AWS_KEY_PAIR_NAME
case "${AWS_KEY_PAIR_NAME}" in
"" ) echo "${COLOR_YELLOW}Please type the name of the key pair to use...${COLOR_NC}";;
* ) break;;
esac
echo ""
done
fi
AWS_KEY_PATH="${AWS_KEY_PATH:-"${HOME}/.ssh/${AWS_KEY_PAIR_NAME}.pem"}"
if [[ ! -e "${AWS_KEY_PATH}" ]]; then
error "Unable to find ${AWS_KEY_PATH} (You can change the location of the ssh key by setting the AWS_KEY_PATH env variable)"
exit 10
fi
echo "] AWS Key Pair: ${COLOR_GREEN}${AWS_KEY_PAIR_NAME}${COLOR_NC}";
}