Skip to content

Commit 26aa655

Browse files
committed
Fix shellcheck issues on startup script
fixes #470 also fixes some other quoting issues and improves vmArgs handling
1 parent 5bb5a85 commit 26aa655

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#set ($vmArgs = $StringUtils.join($info.vmArgs, " "))
21
#!/usr/bin/env bash
32
# GNU/Linux startup script generated by JavaPackager plugin
43

@@ -11,7 +10,7 @@ function showMessage() {
1110
if type -p notify-send; then
1211
notify-send -u critical "${info.name}" "$1"
1312
else
14-
echo $1
13+
echo "$1"
1514
fi
1615
}
1716
if type -p java > /dev/null; then
@@ -45,8 +44,7 @@ function compareVersions() {
4544
return 0
4645
}
4746
JAVA_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}')
48-
compareVersions "$JAVA_VERSION" "${info.jreMinVersion}"
49-
if [[ $? != 0 ]]; then
47+
if ! compareVersions "$JAVA_VERSION" "${info.jreMinVersion}"; then
5048
showMessage "The application requires a Java Runtime Environment ${info.jreMinVersion} or higher."
5149
exit 1
5250
fi
@@ -63,17 +61,21 @@ BINARY="$SCRIPTPATH/${info.jarFile.name}"
6361
export PATH=${info.envPath}
6462
#end
6563

66-
JVMDefaultOptions="${vmArgs}"
64+
JVMDefaultOptions=()
65+
#foreach ($vmArg in $info.vmArgs)
66+
JVMDefaultOptions+=("$vmArg")
67+
#end
68+
6769
JVMOptionsFile="$SCRIPTPATH/${info.name}.l4j.ini"
68-
[ -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}")"
6971

7072
JVMClassPath="$BINARY"
7173
#foreach ($classpath in $info.classpaths)
7274
JVMClassPath+=":${classpath}"
7375
#end
7476

7577
#if ($info.useResourcesAsWorkingDir)
76-
cd "$SCRIPTPATH"
78+
cd "$SCRIPTPATH" || exit 1
7779
#end
7880

7981
#if ($info.scripts.bootstrap)
@@ -82,8 +84,8 @@ Bootstrap="$SCRIPTPATH/scripts/${info.bootstrapFile.name}" && [ -x "$Bootstrap"
8284
#end
8385

8486
#if ($info.administratorRequired)
85-
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 "${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
87+
pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" GDKBACKEND=x11 "${JAVA}" "${JVMDefaultOptions[@]}" -jar "${JVMClassPath}" "$@"
8688
#else
87-
"${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
89+
"${JAVA}" "${JVMDefaultOptions[@]}" -jar "${JVMClassPath}" "@"
8890
#end
8991
exit 0

0 commit comments

Comments
 (0)