-
Notifications
You must be signed in to change notification settings - Fork 4
/
deregisterImages.sh
executable file
·39 lines (27 loc) · 1012 Bytes
/
deregisterImages.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
#!/bin/bash
# Deregisters (removes) AMI images used to create new instances.
# and docker again.
IMAGE_IDS_FILE="IMAGE_IDS.txt"
[[ -f ${IMAGE_IDS_FILE} ]] || exit 1
source ${IMAGE_IDS_FILE}
main(){
[[ -f ${IMAGE_IDS_FILE} ]] &&
source ${IMAGE_IDS_FILE} &&
[[ ! -z ${STOCKHOLM_TEMPLATE_IMAGE} ]] &&
[[ ! -z ${FRANKFURT_TEMPLATE_IMAGE} ]] &&
aws ec2 deregister-image --region "eu-north-1" --image-id ${STOCKHOLM_TEMPLATE_IMAGE} &&
aws ec2 deregister-image --region "eu-central-1" --image-id ${FRANKFURT_TEMPLATE_IMAGE} &&
# proceeed if there is no images on EC2 anymore
rm -f ${IMAGE_IDS_FILE} ||
interrupted
}
interrupted(){
local COLOR_RED=$'\e[1;31m'
local COLOR_YELLOW=$'\e[1;33m'
local RESET_COLOR=$'\e[0m'
echo -e "${COLOR_YELLOW}The removing of AMI images was not succesfull.${RESET_COLOR}"
[[ -f ${IMAGE_IDS_FILE} ]] &&
echo -e "${COLOR_RED}Don't forget to remove ${IMAGE_IDS_FILE} file once the issue is resolved.${RESET_COLOR}"
exit 0
}
./checkAWS.sh && main || ./awsCliNa.sh