forked from holatuwol/liferay-faster-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appserverprops
executable file
·317 lines (232 loc) · 10 KB
/
appserverprops
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
appserveruserprops() {
if [ ! -f "${GIT_ROOT}/app.server.properties" ]; then
return 0
fi
touch "${GIT_ROOT}/app.server.${USER}.properties"
if [[ 0 -ne $(egrep -o $'\r\n'\$ "${GIT_ROOT}/app.server.${USER}.properties" | wc -c ) ]]; then
perl -pi -e 's/\r\n|\n|\r/\n/g' "${GIT_ROOT}/app.server.${USER}.properties"
fi
return 0
}
buildprops() {
if [ ! -f ${GIT_ROOT}/build.xml ]; then
return 0
fi
if [ -f ${GIT_ROOT}/build.${USER}.properties ]; then
set_sdk_version
if [[ 0 -ne $(egrep -o $'\r\n'\$ "${GIT_ROOT}/build.${USER}.properties" | wc -c ) ]]; then
perl -pi -e 's/\r\n|\n|\r/\n/g' "${GIT_ROOT}/build.${USER}.properties"
fi
if [ "" != "$(grep -F javac.compiler ${GIT_ROOT}/build.properties | grep -F 'modern' | grep -F '#')" ]; then
if [ "" == "$(grep -F javac.compiler ${GIT_ROOT}/build.${USER}.properties)" ]; then
echo -e '\njavac.compiler=modern' >> ${GIT_ROOT}/build.${USER}.properties
fi
fi
if [ "" == "$(grep -F mirrors.hostname ${GIT_ROOT}/build.${USER}.properties)" ]; then
echo -e '\nmirrors.hostname=' >> ${GIT_ROOT}/build.${USER}.properties
fi
if [ "" == "$(grep -F baseline.jar.report.level ${GIT_ROOT}/build.${USER}.properties)" ]; then
echo -e '\nbaseline.jar.report.level=off' >> ${GIT_ROOT}/build.${USER}.properties
fi
if [ "" == "$(grep -F org.gradle.daemon ${GIT_ROOT}/build.${USER}.properties)" ]; then
echo -e '\norg.gradle.daemon=false' >> ${GIT_ROOT}/build.${USER}.properties
fi
if [ "" == "$(grep -F build.binaries.cache.url ${GIT_ROOT}/build.${USER}.properties)" ]; then
if [ "" != "$(grep -F build.binaries.cache.repository.name ${GIT_ROOT}/build.properties)" ]; then
echo '' >> ${GIT_ROOT}/build.${USER}.properties
grep -F build.binaries.cache.repository.name ${GIT_ROOT}/build.properties >> ${GIT_ROOT}/build.${USER}.properties
echo '[email protected]:liferay/${build.binaries.cache.repository.name}.git' >> ${GIT_ROOT}/build.${USER}.properties
fi
fi
repopass
return 0
fi
cat /dev/null > ${GIT_ROOT}/build.${USER}.properties
# If we're on an older CentOS server, we can't use the node.js SASS compiler
if [ "" != "$(which rpm 2> /dev/null)" ] && [ ! -f modules/yarn.lock ]; then
echo 'sass.compiler.class.name=ruby' >> ${GIT_ROOT}/build.${USER}.properties
fi
# Avoid using ECJ for compilation
echo 'javac.compiler=modern' >> ${GIT_ROOT}/build.${USER}.properties
# Make sure baseline report is turned off
if [ "" == "$(grep -F baseline.jar.report.level build.${USER}.properties)" ]; then
echo -e '\nbaseline.jar.report.level=off' >> ${GIT_ROOT}/build.${USER}.properties
fi
# Ensure we have an up-to-date repository password for private repositories
repopass
}
checkliferayhome() {
local CATALINA_WEBAPPS=$(find ${PWD} -mindepth 2 -maxdepth 2 -type d -name 'webapps' | sort | tail -1)
if [ "" == "${CATALINA_WEBAPPS}" ]; then
return 1
fi
CATALINA_HOME=$(dirname "${CATALINA_WEBAPPS}")
TOMCAT_FOLDER=$(basename "${CATALINA_HOME}")
TOMCAT_VERSION=$(echo "${TOMCAT_FOLDER}" | cut -d'-' -f 2-)
LIFERAY_HOME=$(dirname "${CATALINA_HOME}")
echo "Using ${LIFERAY_HOME} as liferay.home"
}
cleanappserver() {
if [ ! -f ${GIT_ROOT}/app.server.properties ]; then
return 0
fi
local TOMCAT_VERSION=
TOMCAT_FOLDER=
CATALINA_HOME=
if [ -f ${GIT_ROOT}/app.server.${USER}.properties ]; then
TOMCAT_VERSION=$(grep -F app.server.tomcat.version= ${GIT_ROOT}/app.server.${USER}.properties | cut -d'=' -f 2)
fi
if [ "" == "${TOMCAT_VERSION}" ]; then
TOMCAT_VERSION=$(grep -F app.server.tomcat.version= ${GIT_ROOT}/app.server.properties | cut -d'=' -f 2)
fi
if [ "" != "${TOMCAT_VERSION}" ]; then
TOMCAT_FOLDER=tomcat-${TOMCAT_VERSION}
CATALINA_HOME=${LIFERAY_HOME}/${TOMCAT_FOLDER}
fi
if [ "" == "${CATALINA_HOME}" ] && [ "" != "${LIFERAY_HOME}" ] && [ -d "${LIFERAY_HOME}" ]; then
pushd ${LIFERAY_HOME} > /dev/null
checkliferayhome
popd > /dev/null
fi
if [ "" == "${CATALINA_HOME}" ]; then
return 1
fi
if [ "" == "${CURRENT_HASH}" ]; then
if [ ! -d ${CATALINA_HOME} ]; then
echo "Missing ${CATALINA_HOME}"
ant -f build-dist.xml unzip-tomcat
fi
if [ "" != "${ARCHIVE_HOME}" ]; then
mkdir -p ${ARCHIVE_HOME}
local TOMCAT_MAJOR_VERSION=$(echo ${TOMCAT_VERSION} | cut -d'.' -f 1)
# make sure we have an archive file
ARCHIVE_FILE=${ARCHIVE_HOME}/apache-tomcat-${TOMCAT_VERSION}.zip
if [ ! -f "${ARCHIVE_FILE}" ]; then
pushd ${ARCHIVE_HOME} > /dev/null
curl -O "http://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.zip"
popd > /dev/null
fi
# cleanup the existing folder so that we can have a clean slate
rm -rf "${CATALINA_HOME}"
mkdir -p "${LIFERAY_HOME}"
pushd "${LIFERAY_HOME}" > /dev/null
unzip "${ARCHIVE_FILE}"
mv apache-tomcat-${TOMCAT_VERSION} ${TOMCAT_FOLDER}
rm -rf ${TOMCAT_FOLDER}/webapps/*
popd > /dev/null
fi
fi
# setup catalina.properties
if [ -f ${LIFERAY_HOME}/${TOMCAT_FOLDER}/conf/catalina.properties ] && [ "" == "$(grep -F /ext/ ${LIFERAY_HOME}/${TOMCAT_FOLDER}/conf/catalina.properties)" ]; then
if [ "" != "$(grep -F 'common.loader="' ${LIFERAY_HOME}/${TOMCAT_FOLDER}/conf/catalina.properties)" ]; then
sed -i 's#common.loader=#common.loader="${catalina.base}/lib/ext/*.jar",#g' ${LIFERAY_HOME}/${TOMCAT_FOLDER}/conf/catalina.properties
else
sed -i 's#common.loader=#common.loader=${catalina.base}/lib/ext/*.jar,#g' ${LIFERAY_HOME}/${TOMCAT_FOLDER}/conf/catalina.properties
fi
fi
}
gradleprops() {
local ANT_LIFERAY_HOME=
local GRADLE_LIFERAY_HOME=
if [ -f "${GIT_ROOT}/app.server.properties" ]; then
if [ -f "${GIT_ROOT}/app.server.${USER}.properties" ]; then
ANT_LIFERAY_HOME=$(grep -F 'app.server.parent.dir=' "${GIT_ROOT}/app.server.${USER}.properties" | grep -vF '#' | cut -d'=' -f 2)
fi
if [ "" == "${ANT_LIFERAY_HOME}" ]; then
ANT_LIFERAY_HOME=$(grep -F 'app.server.parent.dir=' "${GIT_ROOT}/app.server.properties" | grep -vF '#' | cut -d'=' -f 2)
echo -e "\napp.server.parent.dir=${ANT_LIFERAY_HOME}" >> app.server.${USER}.properties
LIFERAY_HOME="$(echo ${ANT_LIFERAY_HOME} | sed 's@${project.dir}/@'${GIT_ROOT}'/@g')"
return 0
fi
fi
if [[ ${ANT_LIFERAY_HOME} == '${project.dir}/'* ]]; then
LIFERAY_HOME="$(echo ${ANT_LIFERAY_HOME} | sed 's@${project.dir}/@'${GIT_ROOT}'/@g')"
return 0
fi
# Find gradle root
GRADLE_HOME=$PWD
while [ ! -e ${GRADLE_HOME}/gradlew ] && [ "/" != "${GRADLE_HOME}" ]; do
GRADLE_HOME=$(dirname ${GRADLE_HOME})
done
# If this is a blade workspace, don't do anything
if [ "/" != "${GRADLE_HOME}" ] && [ -f ${GRADLE_HOME}/build.gradle ]; then
return 0
fi
# Make sure that we've run ant setup-sdk
local GRADLE_LIFERAY_HOME=
if [ -f "${GRADLE_HOME}/.gradle/gradle.properties" ]; then
GRADLE_LIFERAY_HOME=$(grep -F liferay.home= ${GRADLE_HOME}/.gradle/gradle.properties | cut -d'=' -f 2 | perl -C -Mutf8 -pe 's@'${GIT_ROOT}'/@@i')
elif [ -f "${GIT_ROOT}/gradle.properties" ]; then
GRADLE_LIFERAY_HOME=$(grep -F 'liferay.home=' "${GIT_ROOT}/gradle.properties" | grep -vF '#' | cut -d'=' -f 2)
if [ "" == "${GRADLE_USER_HOME}" ] && [ -f $HOME/.gradle/gradle.properties ]; then
GRADLE_USER_HOME=$HOME/.gradle
fi
if [ "" == "${GRADLE_LIFERAY_HOME}" ] && [ -f ${GRADLE_USER_HOME}/gradle.properties ]; then
GRADLE_LIFERAY_HOME=$(grep -F 'liferay.home=' "${GRADLE_USER_HOME}/gradle.properties" | grep -vF '#' | cut -d'=' -f 2)
fi
local TOMCAT_FOLDER=$(grep -F 'app.server.parent.dir=' "${GIT_ROOT}/gradle.properties" | grep -vF '#' | cut -d'=' -f 2)
if [ "" == "${TOMCAT_FOLDER}" ] && [ -f ${GRADLE_USER_HOME}/gradle.properties ]; then
TOMCAT_FOLDER=$(grep -F 'app.server.parent.dir=' "${GRADLE_USER_HOME}/gradle.properties" | grep -vF '#' | cut -d'=' -f 2)
fi
if [ "" == "${GRADLE_LIFERAY_HOME}" ] && [ "" == "${TOMCAT_FOLDER}" ]; then
echo "Missing liferay.home and app.server.parent.dir in gradle.properties"
return 1
elif [ "" == "${GRADLE_LIFERAY_HOME}" ]; then
echo "Missing liferay.home in gradle.properties"
return 1
elif [ "" == "${TOMCAT_FOLDER}" ]; then
echo "Missing app.server.parent.dir in gradle.properties"
return 1
fi
fi
if [ "" == "$ANT_LIFERAY_HOME" ]; then
if [ "" == "${GRADLE_LIFERAY_HOME}" ]; then
echo "Missing app.server.${USER}.properties and gradle.properties"
return 1
fi
if [ ! -f "${GIT_ROOT}/gradle.properties" ]; then
echo -e "\napp.server.parent.dir=${GRADLE_LIFERAY_HOME}" >> ${GIT_ROOT}/app.server.${USER}.properties
fi
ANT_LIFERAY_HOME=${GRADLE_LIFERAY_HOME}
fi
local LOWER_ANT_LIFERAY_HOME=$(echo ${ANT_LIFERAY_HOME} | tr '[:upper:]' '[:lower:]')
local LOWER_GRADLE_LIFERAY_HOME=$(echo ${GRADLE_LIFERAY_HOME} | tr '[:upper:]' '[:lower:]')
if [ "${LOWER_ANT_LIFERAY_HOME}" != "${LOWER_GRADLE_LIFERAY_HOME}" ] && [ -f ${GIT_ROOT}/build.xml ] && [ "" != "$(grep -F setup-sdk ${GIT_ROOT}/build.xml)" ]; then
if [ "" == "${GRADLE_LIFERAY_HOME}" ]; then
echo "Missing .gradle/gradle.properties, generating via ant setup-sdk"
else
echo "Fixing mismatch between app.server.${USER}.properties (${ANT_LIFERAY_HOME}) and .gradle/gradle.properties (${GRADLE_LIFERAY_HOME}) via ant setup-sdk"
fi
pushd ${GIT_ROOT} > /dev/null
# ant setup-sdk
GRADLE_LIFERAY_HOME=$ANT_LIFERAY_HOME
popd > /dev/null
fi
# Update the environment variable for other scripts
LIFERAY_HOME=$ANT_LIFERAY_HOME
}
setopts() {
. $(dirname "${BASH_SOURCE[0]}")/setopts
}
repopass() {
$(dirname "${BASH_SOURCE[0]}")/repopass
}
set_sdk_version() {
if [ "1.0" != "$(grep build.sdk.version ${GIT_ROOT}/build.properties | cut -d'=' -f 2 | cut -d'.' -f 1,2)" ]; then
return 0
fi
if [[ 20 -le $(grep build.sdk.version ${GIT_ROOT}/build.properties | cut -d'=' -f 2 | cut -d'.' -f 3) ]]; then
return 0
fi
if [ -f ${GIT_ROOT}/build.${USER}.properties ] && [ "" != "$(grep build.sdk.version= ${GIT_ROOT}/build.${USER}.properties)" ]; then
return 0
fi
echo -e '\nbuild.sdk.version=1.0.20' >> ${GIT_ROOT}/build.${USER}.properties
}
setopts
if [[ 0 -eq $? ]]; then
appserveruserprops && buildprops && gradleprops && cleanappserver
else
checkliferayhome
fi