Skip to content

Commit 94acd92

Browse files
committed
Fix shellcheck issues on startup script
fixes #470 also fixes some other quoting issues and improves vmArgs handling
1 parent 543d77a commit 94acd92

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/main/resources/linux/startup.sh.vtl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#set ($vmArgs = $StringUtils.join($info.vmArgs, " "))
2-
#set ($appArgs = $StringUtils.join($info.appArgs, " "))
31
#!/usr/bin/env bash
42
# GNU/Linux startup script generated by JavaPackager plugin
53

@@ -12,7 +10,7 @@ function showMessage() {
1210
if type -p notify-send; then
1311
notify-send -u critical "${info.name}" "$1"
1412
else
15-
echo $1
13+
echo "$1"
1614
fi
1715
}
1816
if type -p java > /dev/null; then
@@ -46,8 +44,7 @@ function compareVersions() {
4644
return 0
4745
}
4846
JAVA_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}')
49-
compareVersions "$JAVA_VERSION" "${info.jreMinVersion}"
50-
if [[ $? != 0 ]]; then
47+
if ! compareVersions "$JAVA_VERSION" "${info.jreMinVersion}"; then
5148
showMessage "The application requires a Java Runtime Environment ${info.jreMinVersion} or higher."
5249
exit 1
5350
fi
@@ -64,19 +61,26 @@ BINARY="$SCRIPTPATH/${info.jarFile.name}"
6461
export PATH=${info.envPath}
6562
#end
6663

67-
JVMDefaultOptions="${vmArgs}"
64+
JVMDefaultOptions=()
65+
#foreach ($vmArg in $info.vmArgs)
66+
JVMDefaultOptions+=("$vmArg")
67+
#end
68+
6869
JVMOptionsFile="$SCRIPTPATH/${info.name}.l4j.ini"
69-
[ -f "${JVMOptionsFile}" ] && while read -r option; do JVMDefaultOptions+=" $option"; done <<< $(sed "/^#.*$/d" "${JVMOptionsFile}")
70+
[ -f "${JVMOptionsFile}" ] && while read -r -a option; do JVMDefaultOptions+=("${option[@]}"); done <<< "$(sed -e "/^#.*$/d" -e "/^[[:space:]]*$/d" "${JVMOptionsFile}")"
7071

7172
JVMClassPath="$BINARY"
7273
#foreach ($classpath in $info.classpaths)
7374
JVMClassPath+=":${classpath}"
7475
#end
7576

76-
AppArguments="${appArgs}"
77+
AppArguments=()
78+
#foreach ($appArg in $info.appArgs)
79+
AppArguments+=("appArg")
80+
#end
7781

7882
#if ($info.useResourcesAsWorkingDir)
79-
cd "$SCRIPTPATH"
83+
cd "$SCRIPTPATH" || exit 1
8084
#end
8185

8286
#if ($info.scripts.bootstrap)
@@ -85,8 +89,8 @@ Bootstrap="$SCRIPTPATH/scripts/${info.bootstrapFile.name}" && [ -x "$Bootstrap"
8589
#end
8690

8791
#if ($info.administratorRequired)
88-
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 "${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" ${AppArguments} $@
92+
pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" GDKBACKEND=x11 "${JAVA}" "${JVMDefaultOptions[@]}" -jar "${JVMClassPath}" "${AppArguments[@]}" "$@"
8993
#else
90-
"${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" ${AppArguments} $@
94+
"${JAVA}" "${JVMDefaultOptions[@]}" -jar "${JVMClassPath}" "${AppArguments[@]}" "$@"
9195
#end
9296
exit 0
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)