forked from adobe/aem-guides-wknd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-deploy.sh
executable file
·234 lines (208 loc) · 6.12 KB
/
build-deploy.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/bash
# #%L
# wcm.io
# %%
# Copyright (C) 2017 - 2022 wcm.io
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# #L%
# Call with "help" parameter to display syntax information
# defaults
MAVEN_PROFILES="fast"
SLING_URL=""
SLING_USER=""
SLING_PASSWORD=""
JVM_ARGS=""
# display pause message only when script was executed via double-click on windows
if [[ $0 == *":\\"* ]]; then
DISPLAY_PAUSE_MESSAGE=true
fi
BUILD=false
DEPLOY=false
HELP=false
DEFAULT_COMMANDS=true
help_message_exit() {
echo ""
echo " Syntax <parameters> <commands>"
echo ""
echo " Parameters:"
echo " --maven.profiles=${MAVEN_PROFILES} or -P${MAVEN_PROFILES}"
echo " --sling.url=${SLING_URL} or -Dsling.url=${SLING_URL}"
echo " --sling.user=${SLING_USER} or -Dsling.user=${SLING_USER}"
echo " --sling.password=${SLING_PASSWORD} or -Dsling.password=${SLING_PASSWORD}"
echo " --jvm.args=${JVM_ARGS} or -Djvm.args=${JVM_ARGS}"
echo ""
echo " Commands:"
echo " build - Clean and install maven project"
echo " deploy - Deploy packages to AEM instance"
echo " help - display this help message"
echo ""
exit 0
}
parse_parameters() {
for i in "$@"
do
case $i in
--maven\.profiles=*|-P*)
MAVEN_PROFILES="${i#*=}"
shift # past argument=value
;;
--sling\.url=*|-Dsling\.url=*)
SLING_URL="${i#*=}"
shift # past argument=value
;;
--sling\.user=*|-Dsling\.user=*)
SLING_USER="${i#*=}"
shift # past argument=value
;;
--sling\.password=*|-Dsling\.password=*)
SLING_PASSWORD="${i#*=}"
shift # past argument=value
;;
--jvm\.args=*|-Djvm\.args=*)
JVM_ARGS="${i#*=}"
shift # past argument=value
;;
--display\.pause\.message=*|-Ddisplay\.pause\.message=*)
DISPLAY_PAUSE_MESSAGE="${i#*=}"
shift # past argument with no value
;;
build)
BUILD=true
DEFAULT_COMMANDS=false
shift # past argument with no value
;;
deploy)
DEPLOY=true
DEFAULT_COMMANDS=false
;;
help)
HELP=true
DEFAULT_COMMANDS=false
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
if [ "$DEFAULT_COMMANDS" = true ]; then
BUILD=true
DEPLOY=true
fi
}
welcome_message() {
echo "********************************************************************"
if ([ "$BUILD" = true ] && [ "$DEPLOY" = true ]) || [ "$HELP" = true ]; then
echo -e "\e[96m ___ _ _ ___ _ ___ _ ___ ___ ___ _ _____ __\e[0m"
echo -e "\e[96m | _ ) | | |_ _| | | \ _| |_ | \| __| _ \ | / _ \ \ / /\e[0m"
echo -e "\e[96m | _ \ |_| || || |__| |) | |_ _| | |) | _|| _/ |_| (_) \ V /\e[0m"
echo -e "\e[96m |___/\___/|___|____|___/ |_| |___/|___|_| |____\___/ |_|\e[0m"
elif [ "$BUILD" = true ]; then
echo -e "\e[96m ___ _ _ ___ _ ___ \e[0m"
echo -e "\e[96m | _ ) | | |_ _| | | \\ \e[0m"
echo -e "\e[96m | _ \ |_| || || |__| |) |\e[0m"
echo -e "\e[96m |___/\___/|___|____|___/\e[0m"
elif [ "$DEPLOY" = true ]; then
echo -e "\e[96m ___ ___ ___ _ _____ __\e[0m"
echo -e "\e[96m | \| __| _ \ | / _ \ \ / /\e[0m"
echo -e "\e[96m | |) | _|| _/ |_| (_) \ V /\e[0m"
echo -e "\e[96m |___/|___|_| |____\___/ |_|\e[0m"
fi
echo ""
echo -e " Maven Profiles: ${MAVEN_PROFILES}"
echo ""
echo "********************************************************************"
}
completion_message() {
ELAPSED_TIME=$(($SECONDS - $START_TIME))
TOTAL_TIME="($(($ELAPSED_TIME/60)):$(printf "%02d" $(($ELAPSED_TIME%60))) min)"
echo ""
if [ "$BUILD" = true ] && [ "$DEPLOY" = true ]; then
echo -e "*** \e[1mBuild+Deploy complete\e[0m $TOTAL_TIME ***"
elif [ "$BUILD" = true ]; then
echo -e "*** \e[1mBuild complete\e[0m $TOTAL_TIME ***"
elif [ "$DEPLOY" = true ]; then
echo -e "*** \e[1mDeploy complete\e[0m $TOTAL_TIME ***"
fi
echo ""
pause_message
}
execute_build() {
echo ""
echo -e "*** \e[1mBuild application\e[0m ***"
echo ""
MAVEN_ARGS=""
if [ -n "$JVM_ARGS" ]; then
MAVEN_ARGS+="${JVM_ARGS} "
fi
if [ -n "${MAVEN_PROFILES}" ]; then
MAVEN_ARGS+="--activate-profiles ${MAVEN_PROFILES} "
fi
mvn $MAVEN_ARGS clean install eclipse:eclipse
if [ "$?" -ne "0" ]; then
exit_with_error "*** BUILD FAILED ***"
fi
}
execute_deploy() {
echo ""
echo -e "*** \e[1mDeploy to AEM\e[0m ***"
echo ""
MAVEN_ARGS=""
if [ -n "$JVM_ARGS" ]; then
MAVEN_ARGS+="${JVM_ARGS} "
fi
if [ -n "${MAVEN_PROFILES}" ]; then
MAVEN_ARGS+="--activate-profiles=${MAVEN_PROFILES} "
fi
if [ -n "${SLING_URL}" ]; then
MAVEN_ARGS+="-Dsling.url=${SLING_URL} "
fi
if [ -n "${SLING_USER}" ]; then
MAVEN_ARGS+="-Dsling.user=${SLING_USER} "
fi
if [ -n "${SLING_PASSWORD}" ]; then
MAVEN_ARGS+="-Dsling.password=${SLING_PASSWORD} "
fi
mvn $MAVEN_ARGS -f all wcmio-content-package:install
if [ "$?" -ne "0" ]; then
exit_with_error "*** DEPLOY FAILED ***"
fi
}
# Display a pause message (only when the script was executed via double-click on windows)
pause_message() {
if [ "$DISPLAY_PAUSE_MESSAGE" = true ]; then
read -n1 -r -p "Press any key to continue..."
fi
}
# Displays error message and exit the script with error code
exit_with_error() {
echo ""
echo -e "\e[91m$1\e[0m" 1>&2
echo ""
pause_message
exit 1
}
START_TIME=$SECONDS
parse_parameters "$@"
welcome_message
if [ "$HELP" = true ]; then
help_message_exit
fi
if [ "$BUILD" = true ]; then
execute_build
fi
if [ "$DEPLOY" = true ]; then
execute_deploy
fi
completion_message