-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmta-cli
More file actions
executable file
·338 lines (277 loc) · 9.26 KB
/
mta-cli
File metadata and controls
executable file
·338 lines (277 loc) · 9.26 KB
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/bin/bash
# ----------------------------------------------------------------------------
# Copyright 2012 Red Hat, Inc. and/or its affiliates.
#
# Licensed under the Eclipse Public License version 1.0, available at
# http://www.eclipse.org/legal/epl-v10.html
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------
# MTA Startup script
#
# Required Environment vars:
# ------------------
# JAVA_HOME - location of a JRE home directory
#
# Optional Environment Variables
# ------------------
# MTA_HOME - location of MTA's installed home dir
# MTA_OPTS - parameters passed to the Java VM when running MTA
# MAX_MEMORY - Maximum Java Heap (example: 2048m)
# MAX_METASPACE_SIZE - Maximum Metaspace size (example: 256m)
# RESERVED_CODE_CACHE_SIZE - Hotspot code cache size (example: 128m)
# -----------------------------------------------------------------------
ADDONS_DIR=()
MTA_DEBUG_ARGS=()
QUOTED_ARGS=()
RUN_OPENREWRITE=()
TRANSFORM_PROJECT_PATH=()
OPENREWRITE_QUOTED_ARGS=()
OPENREWRITE_GOAL=( "dryRun" )
REPO_URL=()
REPO_BRANCH=()
## Increase the open file limit if low, to what we need or at least to the hard limit.
## Complain if the hard limit is lower than what we need.
## Value set to 10000 to be aligned with windup-web-distribution
WE_NEED=10000
MAX_HARD=$(ulimit -H -n);
MAX_SOFT=$(ulimit -S -n);
if [ $MAX_SOFT == 'unlimited' ] ; then MAX_SOFT=$WE_NEED; fi;
if [ $MAX_HARD == 'unlimited' ] ; then MAX_HARD=$WE_NEED; fi;
if [ $MAX_SOFT -lt $WE_NEED ] || [ $MAX_HARD -lt $WE_NEED ] ; then
if [ $MAX_HARD -lt $WE_NEED ] ; then
echo ""
echo "[WARNING] The limit ($MAX_HARD) for open files is too low and could make MTA unstable. Please increase them to at least $WE_NEED."
echo ""
echo " {RHEL & Fedora} Limits are typically configured in /etc/security/limits.conf"
echo " -> Follow instructions of https://access.redhat.com/solutions/60746"
echo ""
echo " {MacOS} Limits are typically configured in /etc/launchd.conf or /etc/sysctl.conf."
echo " -> Execute this script: https://gist.github.com/Maarc/d13b1e70f191d5b527a24d39dd3e2569 and restart your operating system."
echo ""
fi
MIN_WE_NEED_OR_CAN_HAVE=$(( $MAX_HARD > $WE_NEED ? $WE_NEED : $MAX_HARD ))
echo "Increasing the maximum of open files to $MIN_WE_NEED_OR_CAN_HAVE."
ulimit -S -n $MIN_WE_NEED_OR_CAN_HAVE
fi
## resolve links - $0 may be a link to MTA's home
SCRIPT_HOME="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
SCRIPT_HOME=`dirname "$SCRIPT_HOME"`/..
# make it fully qualified
SCRIPT_HOME=`cd "$SCRIPT_HOME" && pwd`
cd "$saveddir"
while [ "$1" != "" ] ; do
if [ "$1" = "--debug" ] ; then
MTA_DEBUG_ARGS=( "-Xdebug" "-Xnoagent" "-Djava.compiler=NONE" "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" )
fi
if [ "$1" = "--openrewrite" ] ; then
RUN_OPENREWRITE=( "yes" )
elif [ "$1" = "--input" ] ; then
TRANSFORM_PROJECT_PATH=("$2")
elif [ "$1" = "$TRANSFORM_PROJECT_PATH" ] ; then
pathfound=true
elif [ "$1" = "--goal" ] ; then
OPENREWRITE_GOAL=("$2")
elif [ "$1" = "$OPENREWRITE_GOAL" ] ; then
goalfound=true
elif [ "$1" = "--repoUrl" ] ; then
REPO_URL=("$2")
shift
continue
elif [ "$1" = "$REPO_URL" ] ; then
repofound=true
shift
continue
elif [ "$1" = "--repoBranch" ] ; then
REPO_BRANCH=("$2")
shift
continue
elif [ "$1" = "$REPO_BRANCH" ] ; then
branchfound=true
shift
continue
else
OPENREWRITE_QUOTED_ARGS+=("$1")
fi
QUOTED_ARGS+=("$1")
shift
done
if [ -f /etc/mtarc ] ; then
. /etc/mtarc
fi
if [ -f "$HOME/.mtarc" ] ; then
. "$HOME/.mtarc"
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
## Prevent "Too many open files" on Mac.
FILE_DESCRIPTOR_OPTS="-XX:-MaxFDLimit";
if [ -z "$JAVA_VERSION" ] ; then
JAVA_VERSION="1.7+"
fi
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME="`/usr/libexec/java_home --version $JAVA_VERSION`"
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -n "$MTA_HOME" ] ; then
# Detect if this script is in a MTA directory
if [ ! -f "$SCRIPT_HOME/mta-cli-version.txt" ] ; then
# If it is, then use it as MTA_HOME
echo "Resetting MTA_HOME to $SCRIPT_HOME (from: $MTA_HOME)"
# Set it to blank and we will recalculate it later on
MTA_HOME="$SCRIPT_HOME"
fi
fi
if [ -z "$MTA_HOME" ] ; then
## resolve links - $0 may be a link to MTA's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
MTA_HOME=`dirname "$PRG"`/..
# make it fully qualified
MTA_HOME=`cd "$MTA_HOME" && pwd`
cd "$saveddir"
fi
echo Using MTA at $MTA_HOME
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$MTA_HOME" ] &&
MTA_HOME=`cygpath --unix "$MTA_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$MTA_HOME" ] &&
MTA_HOME="`(cd "$MTA_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi
MODULES=""
JAVAVER=`"$JAVACMD" -version 2>&1`
case $JAVAVER in
"11."*)
MODULES="--add-modules=java.se"
echo "TECH PREVIEW Running on JDK $JAVAVER"
;;
*1.[8-9]*) ;;
*1.[1-7]*)
echo " Error: a Java 1.8 or higher JRE is required to run MTA; found [$JAVACMD -version == $JAVAVER]."
exit 1
;;
esac
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
MTA_MAIN_CLASS=org.jboss.windup.bootstrap.Bootstrap
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$MTA_HOME" ] &&
MTA_HOME=`cygpath --path --windows "$MTA_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$HOME" ] &&
HOME=`cygpath --path --windows "$HOME"`
fi
#
if [ -r "$MTA_HOME/addons/" ] ; then
ADDONS_DIR=("--immutableAddonDir" "$MTA_HOME/addons/")
fi
if [ -z "$MAX_METASPACE_SIZE" ] ; then
MAX_METASPACE_SIZE="256m"
fi
if [ -z "$RESERVED_CODE_CACHE_SIZE" ] ; then
RESERVED_CODE_CACHE_SIZE="128m"
fi
if [ -z "$MTA_OPTS" ] ; then
if [ -n "$MAX_MEMORY" ] ; then
MTA_OPTS="-Xmx$MAX_MEMORY -XX:MaxMetaspaceSize=$MAX_METASPACE_SIZE -XX:ReservedCodeCacheSize=$RESERVED_CODE_CACHE_SIZE"
else
MTA_OPTS="-XX:MaxMetaspaceSize=$MAX_METASPACE_SIZE -XX:ReservedCodeCacheSize=$RESERVED_CODE_CACHE_SIZE"
fi
fi
MTA_OPTS="$MTA_OPTS $FILE_DESCRIPTOR_OPTS";
if [ "$RUN_OPENREWRITE" != "" ] ; then
( cd "$TRANSFORM_PROJECT_PATH"; exec mvn org.openrewrite.maven:rewrite-maven-plugin:4.13.0:"${OPENREWRITE_GOAL}" -DconfigLocation="${MTA_HOME}"/rules/openrewrite/rewrite.yml "${OPENREWRITE_QUOTED_ARGS[@]}" )
exit 0;
fi
if [ "$REPO_URL" != "" ] ; then
RESPONSE_CODE=$(curl -L --write-out %{http_code} --silent --output /dev/null https://"${REPO_URL}"/info/refs?service=git-upload-pack)
if [ "$RESPONSE_CODE" != 200 ] ; then
echo ${REPO_URL} is a private repo. You must provide a valid token to access it.
read -sp 'Access Token: ' repoToken
if [ "$repoToken" == "" ] ; then
echo -e \\nNo token provided to access private repo. Aborting.
exit 0;
fi
fi
echo -e \\nDownloading repo ${REPO_URL}
if [[ $REPO_URL == *github* ]]; then
RESPONSE_CODE_DOWNLOAD=$(curl -Lo repo.zip -w %{http_code} https://"${repoToken}"@"${REPO_URL}"/archive/refs/heads/"${REPO_BRANCH}".zip)
fi
if [[ $REPO_URL == *gitlab* ]]; then
RESPONSE_CODE_DOWNLOAD=$(curl -Lo repo.zip -w %{http_code} https://"${REPO_URL}"/-/archive/"${REPO_BRANCH}"/*-"${REPO_BRANCH}".zip?private_token="${repoToken}")
fi
unzip -tqq repo.zip > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo Repo download unsuccessful. Aborting!
exit 0;
fi
QUOTED_ARGS+=("--input")
QUOTED_ARGS+=("./repo.zip")
QUOTED_ARGS+=("--inputApplicationName")
QUOTED_ARGS+=(${REPO_URL})
fi
exec "$JAVACMD" $MODULES "${MTA_DEBUG_ARGS[@]}" $MTA_OPTS -Dforge.standalone=true -Dforge.home="${MTA_HOME}" -Dwindup.home="${MTA_HOME}" \
-cp "${MTA_HOME}"/lib/'*' $MTA_MAIN_CLASS "${QUOTED_ARGS[@]}" "${ADDONS_DIR[@]}"