From 02a77b528ba0fcc2df9d72a7e5312e405c407bbd Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 3 Jun 2020 10:32:11 -0400 Subject: [PATCH] Support recursive symlinks in release script See https://github.com/cdr/code-server/issues/1746#issuecomment-637830396 --- ci/build/code-server.sh | 44 +++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/ci/build/code-server.sh b/ci/build/code-server.sh index 4793cc5b..62b59a0f 100755 --- a/ci/build/code-server.sh +++ b/ci/build/code-server.sh @@ -1,26 +1,40 @@ #!/bin/sh +set -eu # This script is intended to be bundled into the standalone releases. # Runs code-server with the bundled node binary. -# More complicated than readlink -f or realpath to support macOS. -# See https://github.com/cdr/code-server/issues/1537 -root_dir() { - # We read the symlink, which may be relative from $0. - dst="$(readlink "$0")" - # We cd into the $0 directory. - cd "$(dirname "$0")" || exit 1 - # Now we can cd into the directory above the dst directory which is the root - # of the release. - cd "$(dirname "$dst")/.." || exit 1 - # Finally we use pwd -P to print the absolute path the root. - pwd -P || exit 1 +_realpath() { + if [ "$(uname)" = "Linux" ]; then + readlink -f "$1" + return + fi + + # See https://github.com/cdr/code-server/issues/1537 + if [ "$(uname)" = "Darwin" ]; then + # We read the symlink, which may be relative from $1. + script="$1" + if [ -L "$script" ]; then + while [ -L "$script" ]; do + script="$(readlink "$script")" + cd "$(dirname "$script")" + done + else + cd "$(dirname "$script")" + fi + + echo "$PWD/$(basename "$script")" + return + fi + + echo "Unsupported OS $(uname)" >&2 + exit 1 } -ROOT="$(root_dir)" +ROOT="$(dirname "$(dirname "$(_realpath "$0")")")" if [ "$(uname)" = "Linux" ]; then - export LD_LIBRARY_PATH="$ROOT/lib:$LD_LIBRARY_PATH" + export LD_LIBRARY_PATH="$ROOT/lib:${LD_LIBRARY_PATH-}" elif [ "$(uname)" = "Darwin" ]; then - export DYLD_LIBRARY_PATH="$ROOT/lib:$DYLD_LIBRARY_PATH" + export DYLD_LIBRARY_PATH="$ROOT/lib:${DYLD_LIBRARY_PATH-}" fi exec "$ROOT/lib/node" "$ROOT" "$@"