-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuddy
More file actions
executable file
·78 lines (61 loc) · 1.94 KB
/
buddy
File metadata and controls
executable file
·78 lines (61 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
set -e
ROOT_DIR=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
PANTRY_LOCAL_BIN="${ROOT_DIR}/pantry/.bin"
USER_LOCAL_BIN="${HOME}/.local/bin"
PANTRY_INSTALLER="${ROOT_DIR}/storage/framework/scripts/pantry-install"
BUDDY_ENTRY="${ROOT_DIR}/storage/framework/core/buddy/src/cli.ts"
PANTRY_BOOTSTRAP_TIMEOUT_SECONDS="${PANTRY_BOOTSTRAP_TIMEOUT_SECONDS:-600}"
PANTRY_DEPENDENCIES_TIMEOUT_SECONDS="${PANTRY_DEPENDENCIES_TIMEOUT_SECONDS:-1200}"
run_with_timeout() {
timeout_seconds="$1"
shift
timeout_flag="${TMPDIR:-/tmp}/buddy-timeout-$$"
rm -f "${timeout_flag}"
"$@" &
cmd_pid=$!
(
sleep "${timeout_seconds}"
if kill -0 "${cmd_pid}" 2>/dev/null; then
echo "Command timed out after ${timeout_seconds}s: $*" >&2
: > "${timeout_flag}"
kill "${cmd_pid}" 2>/dev/null || true
sleep 2
kill -9 "${cmd_pid}" 2>/dev/null || true
fi
) &
watchdog_pid=$!
wait "${cmd_pid}"
status=$?
kill "${watchdog_pid}" 2>/dev/null || true
wait "${watchdog_pid}" 2>/dev/null || true
if [ -f "${timeout_flag}" ]; then
rm -f "${timeout_flag}"
return 124
fi
rm -f "${timeout_flag}"
return "${status}"
}
run_buddy() {
exec env PATH="${PANTRY_LOCAL_BIN}:${USER_LOCAL_BIN}:${PATH}" "${PANTRY_LOCAL_BIN}/bun" "${BUDDY_ENTRY}" "$@"
}
if [ -x "${PANTRY_LOCAL_BIN}/bun" ]; then
run_buddy "$@"
fi
if ! command -v pantry >/dev/null 2>&1; then
if [ ! -x "${PANTRY_INSTALLER}" ]; then
echo "Pantry installer not found at ${PANTRY_INSTALLER}" >&2
exit 1
fi
run_with_timeout "${PANTRY_BOOTSTRAP_TIMEOUT_SECONDS}" "${PANTRY_INSTALLER}"
export PATH="${USER_LOCAL_BIN}:${PATH}"
fi
run_with_timeout "${PANTRY_DEPENDENCIES_TIMEOUT_SECONDS}" pantry install
if [ -x "${PANTRY_LOCAL_BIN}/bun" ]; then
run_buddy "$@"
fi
if command -v bun >/dev/null 2>&1; then
exec env PATH="${PANTRY_LOCAL_BIN}:${USER_LOCAL_BIN}:${PATH}" bun "${BUDDY_ENTRY}" "$@"
fi
echo "Pantry did not provide a local bun runtime." >&2
exit 1