Skip to content

Commit b245ed9

Browse files
committed
Exec change to JDK Wrapper.
1 parent c88ccbd commit b245ed9

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

jdk-wrapper.sh

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
log_err() {
2121
l_prefix=$(date +'%H:%M:%S')
22-
printf "[%s] %s\n" "${l_prefix}" "$@" 1>&2;
22+
printf "[%s] %s\\n" "${l_prefix}" "$@" 1>&2;
2323
}
2424

2525
log_out() {
2626
if [ -n "${JDKW_VERBOSE}" ]; then
2727
l_prefix=$(date +'%H:%M:%S')
28-
printf "[%s] %s\n" "${l_prefix}" "$@"
28+
printf "[%s] %s\\n" "${l_prefix}" "$@"
2929
fi
3030
}
3131

@@ -43,10 +43,12 @@ safe_command() {
4343
checksum() {
4444
l_file="$1"
4545
checksum_exec=""
46+
checksum_args=""
4647
if command -v sha256sum > /dev/null; then
4748
checksum_exec="sha256sum"
4849
elif command -v shasum > /dev/null; then
49-
checksum_exec="shasum -a 256"
50+
checksum_exec="shasum"
51+
checksum_args="-a 256"
5052
elif command -v sha1sum > /dev/null; then
5153
checksum_exec="sha1sum"
5254
elif command -v md5 > /dev/null; then
@@ -56,7 +58,7 @@ checksum() {
5658
log_err "ERROR: No supported checksum command found!"
5759
exit 1
5860
fi
59-
cat "${l_file}" | ${checksum_exec}
61+
${checksum_exec} ${checksum_args} < "${l_file}"
6062
}
6163

6264
rand() {
@@ -99,19 +101,17 @@ safe_command "rm \"${l_fifo}\""
99101
command=
100102
cmd_configuration=
101103
for arg in "$@"; do
102-
if [ -z ${in_command} ]; then
103-
jdkw_arg=$(echo "${arg}" | grep '^JDKW_.*')
104-
jdkw_base_dir_arg=$(echo "${arg}" | grep '^JDKW_BASE_DIR.*')
105-
if [ -n "${jdkw_base_dir_arg}" ]; then
106-
eval ${arg}
107-
fi
108-
if [ -n "${jdkw_arg}" ]; then
109-
cmd_configuration="${cmd_configuration}${arg} "
110-
fi
104+
jdkw_arg=$(echo "${arg}" | grep '^JDKW_.*')
105+
jdkw_base_dir_arg=$(echo "${arg}" | grep '^JDKW_BASE_DIR.*')
106+
if [ -n "${jdkw_base_dir_arg}" ]; then
107+
eval ${arg}
108+
fi
109+
if [ -n "${jdkw_arg}" ]; then
110+
cmd_configuration="${cmd_configuration}${arg} "
111111
fi
112112
case "${arg}" in
113113
*\'*)
114-
arg=`printf "%s" "$arg" | sed "s/'/'\"'\"'/g"`
114+
arg=$(printf "%s" "$arg" | sed "s/'/'\"'\"'/g")
115115
;;
116116
*) : ;;
117117
esac
@@ -159,7 +159,7 @@ fi
159159
if [ "${JDKW_RELEASE}" = "latest" ]; then
160160
latest_version_json="${TMPDIR:-/tmp}/jdkw-latest-version-$$.$(rand)"
161161
safe_command "curl ${curl_options} -f -k -L -o \"${latest_version_json}\" -H 'Accept: application/json' \"${JDKW_BASE_URI}/releases/latest\""
162-
JDKW_RELEASE=$(cat "${latest_version_json}" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
162+
JDKW_RELEASE=$(sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/' < "${latest_version_json}")
163163
rm -f "${latest_version_json}"
164164
log_out "Resolved latest version to ${JDKW_RELEASE}"
165165
fi
@@ -177,17 +177,20 @@ jdkw_wrapper="jdk-wrapper.sh"
177177
download_if_needed "${jdkw_impl}" "${jdkw_path}"
178178
download_if_needed "${jdkw_wrapper}" "${jdkw_path}"
179179

180-
# Execute the provided command
181-
eval ${jdkw_path}/${jdkw_impl} ${command}
182-
result=$?
183-
184180
# Check whether this wrapper is the one specified for this version
185181
jdkw_download="${jdkw_path}/${jdkw_wrapper}"
186182
jdkw_current="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)/$(basename "$0")"
187183
if [ "$(checksum "${jdkw_download}")" != "$(checksum "${jdkw_current}")" ]; then
188184
printf "\e[0;31m[WARNING]\e[0m Your jdk-wrapper.sh file does not match the one in your JDKW_RELEASE.\n"
189185
printf "\e[0;32mUpdate your jdk-wrapper.sh to match by running:\e[0m\n"
190186
printf "cp \"%s\" \"%s\"\n" "${jdkw_download}" "${jdkw_current}"
187+
sleep 3
191188
fi
192189

193-
exit ${result}
190+
# Execute the provided command
191+
# NOTE: The requirements proved quite difficult to run this without exec.
192+
# 1) Exit with the exit status of the child process
193+
# 2) Allow running the wrapper in the background and terminating the child process
194+
# 3) Allow the child process to read from standard input when not running in the background
195+
exec "${jdkw_path}/${jdkw_impl}" "$@"
196+

0 commit comments

Comments
 (0)