|
1 | 1 | #!/bin/sh
|
| 2 | +set -eu |
2 | 3 |
|
3 | 4 | # This script is intended to be bundled into the standalone releases.
|
4 | 5 | # Runs code-server with the bundled node binary.
|
5 | 6 |
|
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 |
18 | 32 | }
|
19 | 33 |
|
20 |
| -ROOT="$(root_dir)" |
| 34 | +ROOT="$(dirname "$(dirname "$(_realpath "$0")")")" |
21 | 35 | if [ "$(uname)" = "Linux" ]; then
|
22 |
| - export LD_LIBRARY_PATH="$ROOT/lib:$LD_LIBRARY_PATH" |
| 36 | + export LD_LIBRARY_PATH="$ROOT/lib:${LD_LIBRARY_PATH-}" |
23 | 37 | elif [ "$(uname)" = "Darwin" ]; then
|
24 |
| - export DYLD_LIBRARY_PATH="$ROOT/lib:$DYLD_LIBRARY_PATH" |
| 38 | + export DYLD_LIBRARY_PATH="$ROOT/lib:${DYLD_LIBRARY_PATH-}" |
25 | 39 | fi
|
26 | 40 | exec "$ROOT/lib/node" "$ROOT" "$@"
|
0 commit comments