-
Notifications
You must be signed in to change notification settings - Fork 0
/
EC-Delete-LandingZone.sh
149 lines (112 loc) · 3.55 KB
/
EC-Delete-LandingZone.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# --------------------------------------------------------
#
# Landing Zone delete init script:
RED=`tput setaf 1`
GREEN=`tput setaf 2`
NC=`tput sgr0`
EL=`tput el`
venv='.venv'
# --------------------
# Parameters
# --------------------
account=${account:-}
seclog=${seclog:-}
# Parameter parsing
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
fi
shift
done
# ---------------------
# The command line help
# ---------------------
display_help() {
echo "Usage: $0 <params>"
echo ""
echo " Provide "
echo " --account : The account profile of the Linked account to be moved as configured in your AWS profile"
echo " --seclog : The account profile of the source SECLOG account as configured in your AWS profile"
echo ""
exit 1
}
# ---------------------
# Environment setup
# ---------------------
delete() {
echo ""
echo "#######"
echo "####### AWS Landing Zone delete script environment configuration"
echo "####### Checking environment..."
echo ""
#installing python 3
if [[ "$(python3 -V)" =~ "Python 3" ]] ; then
echo "Python 3 installed [${GREEN}OK${NC}]"
else
echo "Python 3 installed [${RED}FAIL${NC}]"
echo "Exiting..."
exit 1
fi
#installing pip3
if [[ "$(pip3 -V)" =~ "pip" ]] ; then
echo "PIP 3 installed [${GREEN}OK${NC}]"
else
echo "PIP 3 installed [${RED}FAIL${NC}]"
echo "Exiting..."
exit 1
fi
#setting up venv
if [[ "$(env |grep VIRTUAL_ENV |wc -l)" == '1' ]] ; then
echo "Python running on venv [${GREEN}OK${NC}]"
else
echo -ne "Virtual virtual environment installing... \033[0K\r"
python3 -m venv $venv &> /dev/null
source $venv/bin/activate
if [[ "$(env |grep VIRTUAL_ENV |wc -l)" == '1' ]] ; then
echo "${EL}Virtual environment configured [${GREEN}OK${NC}]"
else
echo "${EL}Virtual environment configured [${RED}FAIL${NC}]"
echo "Exiting..."
exit
fi
fi
DEPENDENCIES=(boto3 botocore time json colorama zipfile shlex cursor pyyaml cfn_flip signal)
#installing python dependencies
for dep in "${DEPENDENCIES[@]}"
do
idep=$dep
if [[ $idep == "pyyaml" ]] ; then
idep='yaml'
fi
#if [[ "$(python3 -c 'import sys, pkgutil; print(True) if pkgutil.find_loader(sys.argv[1]) else print(False)' $idep)" == "True" ]] ; then
# echo "$dep installed [${GREEN}OK${NC}]"
#else
echo -ne "Installing $dep... \033[0K\r"
pip3 install -U $dep &> /dev/null;
if [[ "$(python3 -c 'import sys, pkgutil; print(True) if pkgutil.find_loader(sys.argv[1]) else print(False)' $idep)" == "True" ]] ; then
echo ${EL}"$dep installed [${GREEN}OK${NC}]"
else
echo "${EL}$dep installed [${RED}FAIL${NC}]"
echo "Exiting..."
exit 1
fi
#fi
done
#run python delete landing zone script
echo ""
echo "####### Environment is in good shape. Starting delete script..."
echo "#######"
echo ""
params="-a $account -s $seclog"
python3 ./EC-Delete-LandingZone.py $params
#deactivating pyton runtime environment
deactivate
}
# Check to validate number of parameters entered
if [ -z "$account" ] || [ -z "$seclog" ] ; then
display_help
exit 0
fi
delete