Skip to content

Commit 02a77b5

Browse files
committed
Support recursive symlinks in release script
See #1746 (comment)
1 parent 206f195 commit 02a77b5

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

ci/build/code-server.sh

+29-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
#!/bin/sh
2+
set -eu
23

34
# This script is intended to be bundled into the standalone releases.
45
# Runs code-server with the bundled node binary.
56

6-
# More complicated than readlink -f or realpath to support macOS.
7-
# See https://github.com/cdr/code-server/issues/1537
8-
root_dir() {
9-
# We read the symlink, which may be relative from $0.
10-
dst="$(readlink "$0")"
11-
# We cd into the $0 directory.
12-
cd "$(dirname "$0")" || exit 1
13-
# Now we can cd into the directory above the dst directory which is the root
14-
# of the release.
15-
cd "$(dirname "$dst")/.." || exit 1
16-
# Finally we use pwd -P to print the absolute path the root.
17-
pwd -P || exit 1
7+
_realpath() {
8+
if [ "$(uname)" = "Linux" ]; then
9+
readlink -f "$1"
10+
return
11+
fi
12+
13+
# See https://github.com/cdr/code-server/issues/1537
14+
if [ "$(uname)" = "Darwin" ]; then
15+
# We read the symlink, which may be relative from $1.
16+
script="$1"
17+
if [ -L "$script" ]; then
18+
while [ -L "$script" ]; do
19+
script="$(readlink "$script")"
20+
cd "$(dirname "$script")"
21+
done
22+
else
23+
cd "$(dirname "$script")"
24+
fi
25+
26+
echo "$PWD/$(basename "$script")"
27+
return
28+
fi
29+
30+
echo "Unsupported OS $(uname)" >&2
31+
exit 1
1832
}
1933

20-
ROOT="$(root_dir)"
34+
ROOT="$(dirname "$(dirname "$(_realpath "$0")")")"
2135
if [ "$(uname)" = "Linux" ]; then
22-
export LD_LIBRARY_PATH="$ROOT/lib:$LD_LIBRARY_PATH"
36+
export LD_LIBRARY_PATH="$ROOT/lib:${LD_LIBRARY_PATH-}"
2337
elif [ "$(uname)" = "Darwin" ]; then
24-
export DYLD_LIBRARY_PATH="$ROOT/lib:$DYLD_LIBRARY_PATH"
38+
export DYLD_LIBRARY_PATH="$ROOT/lib:${DYLD_LIBRARY_PATH-}"
2539
fi
2640
exec "$ROOT/lib/node" "$ROOT" "$@"

0 commit comments

Comments
 (0)