-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-modules-codebuild.sh
executable file
·129 lines (110 loc) · 3.8 KB
/
get-modules-codebuild.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
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# Get Terraform Submodules (Inside CodeBuild)
# -----------------------------------------------------------------------------
# Author : DevOps Engineer (support@devopscorner.id)
# License : Apache v2
# -----------------------------------------------------------------------------
set -e
TITLE="TERRAFORM SUBMODULES" # script name
VER="2.3" # script version
PATH_CODEBUILD="${CODEBUILD_SRC_DIR}"
SUBMODULE_TERRAFORM_COMMUNITY="${CODEBUILD_SRC_DIR}/module_community.lst"
SUBMODULE_TERRAFORM_OFFICIALS="${CODEBUILD_SRC_DIR}/module_officials.lst"
PATH_MODULES="${PATH_CODEBUILD}/terraform/modules/providers/aws"
PATH_MODULES_COMMUNITY="${PATH_MODULES}/community"
PATH_MODULES_OFFICIALS="${PATH_MODULES}/officials"
COL_RED="\033[22;31m"
COL_GREEN="\033[22;32m"
COL_BLUE="\033[22;34m"
COL_END="\033[0m"
get_time() {
DATE=$(date '+%Y-%m-%d %H:%M:%S')
}
print_line0() {
echo "$COL_GREEN=====================================================================================$COL_END"
}
print_line1() {
echo "$COL_GREEN-------------------------------------------------------------------------------------$COL_END"
}
print_line2() {
echo "-------------------------------------------------------------------------------------"
}
logo() {
clear
print_line0
echo "$COL_RED'########:'########:'########:::'#######:::'######::::'#####:::'########:::'#######:: $COL_END"
echo "$COL_RED..... ##:: ##.....:: ##.... ##:'##.... ##:'##... ##::'##.. ##:: ##.... ##:'##.... ##: $COL_END"
echo "$COL_RED:::: ##::: ##::::::: ##:::: ##: ##:::: ##: ##:::..::'##:::: ##: ##:::: ##:..::::: ##: $COL_END"
echo "$COL_RED::: ##:::: ######::: ########:: ##:::: ##: ##::::::: ##:::: ##: ##:::: ##::'#######:: $COL_END"
echo "$COL_RED:: ##::::: ##...:::: ##.. ##::: ##:::: ##: ##::::::: ##:::: ##: ##:::: ##::...... ##: $COL_END"
echo "$COL_RED: ##:::::: ##::::::: ##::. ##:: ##:::: ##: ##::: ##:. ##:: ##:: ##:::: ##:'##:::: ##: $COL_END"
echo "$COL_RED ########: ########: ##:::. ##:. #######::. ######:::. #####::: ########::. #######:: $COL_END"
echo "$COL_RED........::........::..:::::..:::.......::::......:::::.....::::........::::.......::: $COL_END"
print_line1
echo "$COL_GREEN# $TITLE :: ver-$VER $COL_END"
}
header() {
logo
print_line0
get_time
echo "$COL_RED# BEGIN PROCESS..... (Please Wait) $COL_END"
echo "$COL_RED# Start at: $DATE $COL_END\n"
}
footer() {
print_line0
get_time
echo "$COL_RED# Finish at: $DATE $COL_END"
echo "$COL_RED# END PROCESS..... $COL_END\n"
}
skip_exists() {
if [[ -f "$1" ]]; then
echo ">> Skip for existing file $1 ..."
else
git clone --depth 1 $1
fi
}
submodule_cleanup(){
print_line2
get_time
echo "$COL_BLUE[ $DATE ] ##### Rebuild Submodule(s): $COL_END"
cd ${PATH_CODEBUILD}
rm -rf modules
mkdir -p ${PATH_MODULES_COMMUNITY}
mkdir -p ${PATH_MODULES_OFFICIALS}
echo '- REBUILD DONE -'
}
submodule_terrafom_community() {
print_line2
get_time
echo "$COL_BLUE[ $DATE ] ##### Download Community Submodule(s): $COL_END"
submodule_download $PATH_MODULES_COMMUNITY $SUBMODULE_TERRAFORM_COMMUNITY
}
submodule_terrafom_officials() {
print_line2
get_time
echo "$COL_BLUE[ $DATE ] ##### Download Officials Submodule(s): $COL_END"
submodule_download $PATH_MODULES_OFFICIALS $SUBMODULE_TERRAFORM_OFFICIALS
}
submodule_download() {
cd $1
while IFS= read line; do
get_time
print_line2
echo "$COL_GREEN[ $DATE ] git clone --depth 1 $line $COL_END"
print_line2
# skip_exists $line
git clone --depth 1 $line
echo ""
done <"$2"
echo '- DOWNLOAD DONE -'
}
main() {
header
submodule_cleanup
submodule_terrafom_community
submodule_terrafom_officials
footer
}
### START HERE ###
main $@