From d73e02cd9d6cab1779c0c94f2c712b2768e3c6c7 Mon Sep 17 00:00:00 2001 From: Serge Guzik Date: Wed, 13 Feb 2019 18:10:58 +0200 Subject: [PATCH] refactor: Quote all variables with potential spaces within --- warp4j | 122 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/warp4j b/warp4j index c3bb60b..43913e0 100755 --- a/warp4j +++ b/warp4j @@ -281,14 +281,14 @@ function print_launcher_bash() { printf "%s" \ '#!/usr/bin/env bash -JAVA_DIST='$BUNDLED_DISTRO_SUBDIR' -JAR='$JAR_NAME'.jar +JAVA_DIST='"$BUNDLED_DISTRO_SUBDIR"' +JAR='"$JAR_NAME"'.jar DIR="$(cd "$(dirname "$0")" ; pwd -P)" JAVA=$DIR/$JAVA_DIST/bin/java JAR_PATH=$DIR/$JAR -exec $JAVA '"$JVM_OPTIONS"' -jar $JAR_PATH $@ +exec "$JAVA" '"$JVM_OPTIONS"' -jar "$JAR_PATH" "$@" ' } @@ -299,8 +299,8 @@ printf "%s" \ SETLOCAL -SET "JAVA_DIST='$BUNDLED_DISTRO_SUBDIR'" -SET "JAR='$JAR_NAME'.jar" +SET "JAVA_DIST='"$BUNDLED_DISTRO_SUBDIR"'" +SET "JAR='"$JAR_NAME"'.jar" SET "JAVA=%~dp0\%JAVA_DIST%\bin\java.exe" SET "JAR_PATH=%~dp0\%JAR%" @@ -332,13 +332,13 @@ MARKER_UNPACKED="unpacked" # after runtime uncompress # returns latest cached version that matches version specified by user function find_latest_cached() { - local platform=$1 # in terms of adoptopenjdk.net: windows, linux, mac + local platform=$1 local user_version=$2 local platform_dir=$JAVA_DOWNLOAD_PATH/$platform/ # turning something like "11.0.1+13" into regexp like "^11\.0\.1\+13" local pattern="^"$(echo $user_version \ | sed -e 's/\./\\\./g' -e 's/\+/\\\+/g') - local versions=$(ls -1 $platform_dir 2> /dev/null \ + local versions=$(ls -1 "$platform_dir" 2> /dev/null \ | sort --reverse --version-sort) local version for v in ${versions[@]}; do @@ -417,10 +417,10 @@ function download_distro() { local link=$3 local download_dir=$JAVA_DOWNLOAD_PATH/$platform/$version echo "Downloading $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform..." - rm -rf $download_dir - mkdir -p $download_dir - (cd $download_dir - curl --progress-bar --location --remote-name $link + rm -rf "$download_dir" + mkdir -p "$download_dir" + (cd "$download_dir" + curl --progress-bar --location --remote-name "$link" if [[ $? == 0 ]]; then touch $MARKER_DOWNLOADED else @@ -441,7 +441,7 @@ function ensure_distro_cached() { distro_info=$(fetch_distro_info $platform $LATEST_LTS) CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $LATEST_LTS) distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION) - download_distro $platform $CONCRETE_JAVA_VERSION $distro_link + download_distro $platform $CONCRETE_JAVA_VERSION "$distro_link" else CONCRETE_JAVA_VERSION=$(find_latest_cached $platform $LATEST_LTS) fi @@ -450,7 +450,7 @@ function ensure_distro_cached() { distro_info=$(fetch_distro_info $platform $JAVA_VERSION_BASE) CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $JAVA_VERSION) distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION) - download_distro $platform $CONCRETE_JAVA_VERSION $distro_link + download_distro $platform $CONCRETE_JAVA_VERSION "$distro_link" else CONCRETE_JAVA_VERSION=$(find_latest_cached $platform $JAVA_VERSION) fi @@ -465,7 +465,7 @@ function ensure_distro_cached() { fi if [[ ! $(find_latest_cached $platform $CONCRETE_JAVA_VERSION) ]]; then distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION) - download_distro $platform $CONCRETE_JAVA_VERSION $distro_link + download_distro $platform $CONCRETE_JAVA_VERSION "$distro_link" fi fi } @@ -486,15 +486,15 @@ function ensure_distro_unpacked() { if [[ ! -e $download_dir/$MARKER_UNPACKED ]]; then echo "Uncompressing $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform" # removing all leftover directories - for d in $download_dir/* ; do + for d in "$download_dir"/* ; do if [[ -d $d ]]; then - rm -rf $d + rm -rf "$d" fi done case $platform in $LIN) - mkdir -p $unpacked_dir - tar --strip-components=1 -C $unpacked_dir -xzf $download_dir/*.tar.gz + mkdir -p "$unpacked_dir" + tar --strip-components=1 -C "$unpacked_dir" -xzf "$download_dir"/*.tar.gz ;; $MAC) # to uncompess distro for macOS we need to use wildcards @@ -508,18 +508,18 @@ function ensure_distro_unpacked() { else tar_cmd="tar --wildcards" fi - mkdir -p $unpacked_dir - $tar_cmd --strip-components=3 -C $unpacked_dir -xzf $download_dir/*.tar.gz \ + mkdir -p "$unpacked_dir" + $tar_cmd --strip-components=3 -C "$unpacked_dir" -xzf "$download_dir"/*.tar.gz \ "jdk*/Contents/Home" ;; $WIN) - (cd $download_dir + (cd "$download_dir" unzip -oq *.zip && mv jdk* $UNPACKED_SUBDIR ) ;; esac if [[ $? == 0 ]]; then - touch $download_dir/$MARKER_UNPACKED + touch "$download_dir/$MARKER_UNPACKED" else echo "Error: Failed to unpack $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform" >&2 fail @@ -540,7 +540,7 @@ JDEPS=$JDK_PATH/bin/jdeps if [[ $JAVA_DISTRO_TYPE == $DISTRO_TYPE_JDK ]]; then echo "Analyzing dependencies..." # TODO check for errors - MODULES=$($JDEPS --print-module-deps $JAR | grep -v Warning) + MODULES=$("$JDEPS" --print-module-deps "$JAR" | grep -v Warning) fi # creates minimized runtime for the platform @@ -548,13 +548,13 @@ function create_optimized_runtime() { local platform=$1 local jmods=$JAVA_DOWNLOAD_PATH/$platform/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/jmods echo "Creating minimal runtime for $platform..." - $JLINK \ + "$JLINK" \ --no-header-files \ --no-man-pages \ --strip-debug \ - --module-path $jmods \ + --module-path "$jmods" \ --add-modules $MODULES \ - --output $BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR + --output "$BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR" if [[ $? != 0 ]]; then echo "Error: Failed to optimize runtime" >&2 fail @@ -569,22 +569,22 @@ function create_bundle() { create_optimized_runtime $platform ;; $DISTRO_TYPE_JRE) - mkdir -p $BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR - cp -r $JAVA_DOWNLOAD_PATH/$platform/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/* \ - $BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR + mkdir -p "$BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR" + cp -r "$JAVA_DOWNLOAD_PATH/$platform/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR"/* \ + "$BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR" ;; esac case $platform in - $WIN) print_launcher_cmd > $BUNDLES_PATH/$platform/$LAUNCHER_NAME.cmd ;; - *) print_launcher_bash > $BUNDLES_PATH/$platform/$LAUNCHER_NAME.sh - chmod +x $BUNDLES_PATH/$platform/$LAUNCHER_NAME.sh + $WIN) print_launcher_cmd > "$BUNDLES_PATH/$platform/$LAUNCHER_NAME.cmd" ;; + *) print_launcher_bash > "$BUNDLES_PATH/$platform/$LAUNCHER_NAME.sh" + chmod +x "$BUNDLES_PATH/$platform/$LAUNCHER_NAME.sh" ;; esac - cp $JAR $BUNDLES_PATH/$platform/ + cp "$JAR" "$BUNDLES_PATH/$platform/" } # remove old bundles -rm -rf $BUNDLES_PATH +rm -rf "$BUNDLES_PATH" # actually create bundles for all targets for target in ${TARGETS[@]}; do create_bundle $target @@ -592,56 +592,56 @@ done # creates binaries and archives for all targets function warp_targets() { - mkdir -p $WARPED_PATH + mkdir -p "$WARPED_PATH" if [[ ${TARGETS[*]} == *"$LIN"* ]]; then echo "Warping for $LIN..." - mkdir -p $WARPED_TEMP_PATH/$LIN + mkdir -p "$WARPED_TEMP_PATH/$LIN" warp-packer \ --arch linux-x64 \ - --input_dir $BUNDLES_PATH/$LIN \ - --exec $LAUNCHER_NAME.sh \ - --output $WARPED_TEMP_PATH/$LIN/$APP_NAME \ + --input_dir "$BUNDLES_PATH/$LIN" \ + --exec "$LAUNCHER_NAME.sh" \ + --output "$WARPED_TEMP_PATH/$LIN/$APP_NAME" \ &> /dev/null - tar -C $WARPED_TEMP_PATH/$LIN -czf $WARPED_TEMP_PATH/$APP_NAME-$LIN-x64.tar.gz $APP_NAME - mv $WARPED_TEMP_PATH/$LIN/$APP_NAME $WARPED_PATH/$APP_NAME-$LIN - mv $WARPED_TEMP_PATH/$APP_NAME-$LIN-x64.tar.gz $WARPED_PATH - rmdir $WARPED_TEMP_PATH/$LIN + tar -C "$WARPED_TEMP_PATH/$LIN" -czf "$WARPED_TEMP_PATH/$APP_NAME-$LIN-x64.tar.gz" "$APP_NAME" + mv "$WARPED_TEMP_PATH/$LIN/$APP_NAME" "$WARPED_PATH/$APP_NAME-$LIN" + mv "$WARPED_TEMP_PATH/$APP_NAME-$LIN-x64.tar.gz" "$WARPED_PATH" + rmdir "$WARPED_TEMP_PATH/$LIN" fi if [[ ${TARGETS[*]} == *"$MAC"* ]]; then echo "Warping for $MAC..." - mkdir -p $WARPED_TEMP_PATH/$MAC + mkdir -p "$WARPED_TEMP_PATH/$MAC" warp-packer \ --arch macos-x64 \ - --input_dir $BUNDLES_PATH/$MAC \ - --exec $LAUNCHER_NAME.sh \ - --output $WARPED_TEMP_PATH/$MAC/$APP_NAME \ + --input_dir "$BUNDLES_PATH/$MAC" \ + --exec "$LAUNCHER_NAME.sh" \ + --output "$WARPED_TEMP_PATH/$MAC/$APP_NAME" \ &> /dev/null - tar -C $WARPED_TEMP_PATH/$MAC -czf $WARPED_TEMP_PATH/$APP_NAME-$MAC-x64.tar.gz $APP_NAME - mv $WARPED_TEMP_PATH/$MAC/$APP_NAME $WARPED_PATH/$APP_NAME-$MAC - mv $WARPED_TEMP_PATH/$APP_NAME-$MAC-x64.tar.gz $WARPED_PATH - rmdir $WARPED_TEMP_PATH/$MAC + tar -C "$WARPED_TEMP_PATH/$MAC" -czf "$WARPED_TEMP_PATH/$APP_NAME-$MAC-x64.tar.gz" "$APP_NAME" + mv "$WARPED_TEMP_PATH/$MAC/$APP_NAME" "$WARPED_PATH/$APP_NAME-$MAC" + mv "$WARPED_TEMP_PATH/$APP_NAME-$MAC-x64.tar.gz" "$WARPED_PATH" + rmdir "$WARPED_TEMP_PATH/$MAC" fi if [[ ${TARGETS[*]} == *"$WIN"* ]]; then echo "Warping for $WIN..." - mkdir -p $WARPED_TEMP_PATH/$WIN + mkdir -p "$WARPED_TEMP_PATH/$WIN" warp-packer \ --arch windows-x64 \ - --input_dir $BUNDLES_PATH/$WIN \ - --exec $LAUNCHER_NAME.cmd \ - --output $WARPED_TEMP_PATH/$WIN/$APP_NAME.exe \ + --input_dir "$BUNDLES_PATH/$WIN" \ + --exec "$LAUNCHER_NAME.cmd" \ + --output "$WARPED_TEMP_PATH/$WIN/$APP_NAME.exe" \ &> /dev/null - (cd $WARPED_TEMP_PATH/$WIN - zip -r $WARPED_TEMP_PATH/$APP_NAME-$WIN-x64.zip $APP_NAME.exe &> /dev/null + (cd "$WARPED_TEMP_PATH/$WIN" + zip -r "$WARPED_TEMP_PATH/$APP_NAME-$WIN-x64.zip" "$APP_NAME.exe" &> /dev/null ) - mv $WARPED_TEMP_PATH/$WIN/$APP_NAME.exe $WARPED_PATH/$APP_NAME-windows.exe - mv $WARPED_TEMP_PATH/$APP_NAME-$WIN-x64.zip $WARPED_PATH - rmdir $WARPED_TEMP_PATH/$WIN + mv "$WARPED_TEMP_PATH/$WIN/$APP_NAME.exe" "$WARPED_PATH/$APP_NAME-windows.exe" + mv "$WARPED_TEMP_PATH/$APP_NAME-$WIN-x64.zip" "$WARPED_PATH" + rmdir "$WARPED_TEMP_PATH/$WIN" fi - rmdir $WARPED_TEMP_PATH + rmdir "$WARPED_TEMP_PATH" } # actually create binaries and archives for all targets