19
19
20
20
log_err () {
21
21
l_prefix=$( date +' %H:%M:%S' )
22
- printf " [%s] %s\n" " ${l_prefix} " " $@ " 1>&2 ;
22
+ printf " [%s] %s\\ n" " ${l_prefix} " " $@ " 1>&2 ;
23
23
}
24
24
25
25
log_out () {
26
26
if [ -n " ${JDKW_VERBOSE} " ]; then
27
27
l_prefix=$( date +' %H:%M:%S' )
28
- printf " [%s] %s\n" " ${l_prefix} " " $@ "
28
+ printf " [%s] %s\\ n" " ${l_prefix} " " $@ "
29
29
fi
30
30
}
31
31
@@ -43,10 +43,12 @@ safe_command() {
43
43
checksum () {
44
44
l_file=" $1 "
45
45
checksum_exec=" "
46
+ checksum_args=" "
46
47
if command -v sha256sum > /dev/null; then
47
48
checksum_exec=" sha256sum"
48
49
elif command -v shasum > /dev/null; then
49
- checksum_exec=" shasum -a 256"
50
+ checksum_exec=" shasum"
51
+ checksum_args=" -a 256"
50
52
elif command -v sha1sum > /dev/null; then
51
53
checksum_exec=" sha1sum"
52
54
elif command -v md5 > /dev/null; then
@@ -56,7 +58,7 @@ checksum() {
56
58
log_err " ERROR: No supported checksum command found!"
57
59
exit 1
58
60
fi
59
- cat " ${l_file} " | ${checksum_exec}
61
+ ${checksum_exec} ${checksum_args} < " ${l_file} "
60
62
}
61
63
62
64
rand () {
@@ -99,19 +101,17 @@ safe_command "rm \"${l_fifo}\""
99
101
command=
100
102
cmd_configuration=
101
103
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} "
111
111
fi
112
112
case " ${arg} " in
113
113
* \' * )
114
- arg=` printf " %s" " $arg " | sed " s/'/'\" '\" '/g" `
114
+ arg=$( printf " %s" " $arg " | sed " s/'/'\" '\" '/g" )
115
115
;;
116
116
* ) : ;;
117
117
esac
159
159
if [ " ${JDKW_RELEASE} " = " latest" ]; then
160
160
latest_version_json=" ${TMPDIR:-/ tmp} /jdkw-latest-version-$$ .$( rand) "
161
161
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} " )
163
163
rm -f " ${latest_version_json} "
164
164
log_out " Resolved latest version to ${JDKW_RELEASE} "
165
165
fi
@@ -177,17 +177,20 @@ jdkw_wrapper="jdk-wrapper.sh"
177
177
download_if_needed " ${jdkw_impl} " " ${jdkw_path} "
178
178
download_if_needed " ${jdkw_wrapper} " " ${jdkw_path} "
179
179
180
- # Execute the provided command
181
- eval ${jdkw_path} /${jdkw_impl} ${command}
182
- result=$?
183
-
184
180
# Check whether this wrapper is the one specified for this version
185
181
jdkw_download=" ${jdkw_path} /${jdkw_wrapper} "
186
182
jdkw_current=" $( CDPATH= cd -- " $( dirname -- " $0 " ) " && pwd) /$( basename " $0 " ) "
187
183
if [ " $( checksum " ${jdkw_download} " ) " != " $( checksum " ${jdkw_current} " ) " ]; then
188
184
printf " \e[0;31m[WARNING]\e[0m Your jdk-wrapper.sh file does not match the one in your JDKW_RELEASE.\n"
189
185
printf " \e[0;32mUpdate your jdk-wrapper.sh to match by running:\e[0m\n"
190
186
printf " cp \" %s\" \" %s\" \n" " ${jdkw_download} " " ${jdkw_current} "
187
+ sleep 3
191
188
fi
192
189
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