#!/bin/sh # Add default JVM options here. You can also use JAVA_OPTS and KOBWEB_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Dkobweb.version={pkgver}"' # Add all dependency libraries to the CLASSPATH for name in /usr/share/java/kobweb/*.jar ; do CLASSPATH=$CLASSPATH:$name done # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $KOBWEB_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in # double quotes to make sure that they get re-expanded; and # * put everything else in single quotes, so that it's not re-expanded. set -- \ -classpath "$CLASSPATH" \ MainKt \ "$@" # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. # # In Bash we could simply go: # # readarray ARGS < <( xargs -n1 <<<"$var" ) && # set -- "${ARGS[@]}" "$@" # # but POSIX shell has neither arrays nor command substitution, so instead we # post-process each arg (as a line of input to sed) to backslash-escape any # character that might be a shell metacharacter, then use eval to reverse # that process (while maintaining the separation between arguments), and wrap # the whole thing up as a single "set" statement. # # This will of course break if any of these variables contains a newline or # an unmatched quote. eval "set -- $( printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $KOBWEB_OPTS" | xargs -n1 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | tr '\n' ' ' )" '"$@"' exec /usr/bin/java "$@"