Skip to content

Commit aeea807

Browse files
committed
Improve lib.sh sourcing with local fallback and cleanup
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent 785237b commit aeea807

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

install.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,30 @@ main() {
8282
local package_name="vllm-metal"
8383

8484
# Source shared library functions
85-
LIB_URL="https://raw.githubusercontent.com/$repo_owner/$repo_name/main/scripts/lib.sh"
86-
# shellcheck source=/dev/null
87-
if ! source <(curl -fsSL "$LIB_URL"); then
88-
echo "Error: Failed to fetch lib.sh from $LIB_URL" >&2
89-
exit 1
85+
# Try local lib.sh first (when running ./install.sh), fall back to remote (when piped from curl)
86+
local local_lib=""
87+
if [[ -n "${BASH_SOURCE[0]}" ]]; then
88+
local script_dir
89+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
90+
local_lib="$script_dir/scripts/lib.sh"
91+
fi
92+
93+
if [[ -n "$local_lib" && -f "$local_lib" ]]; then
94+
# shellcheck source=/dev/null
95+
source "$local_lib"
96+
else
97+
# Fetch from remote (curl | bash case)
98+
local lib_url="https://raw.githubusercontent.com/$repo_owner/$repo_name/main/scripts/lib.sh"
99+
local lib_tmp
100+
lib_tmp=$(mktemp)
101+
if ! curl -fsSL "$lib_url" -o "$lib_tmp"; then
102+
echo "Error: Failed to fetch lib.sh from $lib_url" >&2
103+
rm -f "$lib_tmp"
104+
exit 1
105+
fi
106+
# shellcheck source=/dev/null
107+
source "$lib_tmp"
108+
rm -f "$lib_tmp"
90109
fi
91110

92111
is_apple_silicon

0 commit comments

Comments
 (0)