Skip to content

Commit 83904e9

Browse files
committed
Update install.sh to build a comprehensive PATH for LaunchAgents, including Node.js and meshcore-decoder paths regardless of installation method.
1 parent 3a6ef28 commit 83904e9

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

install.sh

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,13 +1935,82 @@ install_launchd_service() {
19351935
local plist_file="$HOME/Library/LaunchAgents/com.meshcore.packet-capture.plist"
19361936
mkdir -p "$HOME/Library/LaunchAgents"
19371937

1938-
# Build PATH with meshcore-decoder if available
1939-
local service_path="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
1938+
# Build comprehensive PATH that includes Node.js and meshcore-decoder
1939+
# LaunchAgents don't inherit shell PATH, so we must explicitly set it
1940+
local service_path=""
1941+
1942+
# Add nvm Node.js paths if nvm is installed
1943+
if [ -d "$HOME/.nvm" ]; then
1944+
# Find the active Node.js version (check for default alias or latest LTS)
1945+
local nvm_node_path=""
1946+
if [ -d "$HOME/.nvm/versions/node" ]; then
1947+
# Try to find the default alias first
1948+
if [ -f "$HOME/.nvm/alias/default" ]; then
1949+
local default_version=$(cat "$HOME/.nvm/alias/default" 2>/dev/null)
1950+
if [ -d "$HOME/.nvm/versions/node/$default_version" ]; then
1951+
nvm_node_path="$HOME/.nvm/versions/node/$default_version/bin"
1952+
fi
1953+
fi
1954+
# If no default, try to find the latest LTS or latest version
1955+
if [ -z "$nvm_node_path" ]; then
1956+
local latest_node=$(ls -t "$HOME/.nvm/versions/node" 2>/dev/null | head -1)
1957+
if [ -n "$latest_node" ]; then
1958+
nvm_node_path="$HOME/.nvm/versions/node/$latest_node/bin"
1959+
fi
1960+
fi
1961+
fi
1962+
if [ -n "$nvm_node_path" ] && [ -d "$nvm_node_path" ]; then
1963+
service_path="${nvm_node_path}:"
1964+
print_info "Including nvm Node.js path: $nvm_node_path"
1965+
fi
1966+
fi
1967+
1968+
# Add Homebrew paths (for Apple Silicon and Intel Macs)
1969+
if [ -d "/opt/homebrew/bin" ]; then
1970+
service_path="${service_path}/opt/homebrew/bin:"
1971+
fi
1972+
if [ -d "/usr/local/bin" ]; then
1973+
service_path="${service_path}/usr/local/bin:"
1974+
fi
1975+
1976+
# Add npm global bin directory (common locations)
1977+
if [ -d "$HOME/.npm-global/bin" ]; then
1978+
service_path="${service_path}$HOME/.npm-global/bin:"
1979+
fi
1980+
# npm config get prefix can tell us where global packages are installed
1981+
if command -v npm &> /dev/null; then
1982+
local npm_prefix=$(npm config get prefix 2>/dev/null)
1983+
if [ -n "$npm_prefix" ] && [ -d "$npm_prefix/bin" ] && [ "$npm_prefix" != "/usr" ]; then
1984+
service_path="${service_path}$npm_prefix/bin:"
1985+
fi
1986+
fi
1987+
1988+
# Add Node.js directory if node is available (covers various installation methods)
1989+
if command -v node &> /dev/null; then
1990+
local node_dir=$(dirname "$(which node)")
1991+
if [ -n "$node_dir" ] && [ "$node_dir" != "." ] && [[ "$service_path" != *"$node_dir"* ]]; then
1992+
service_path="${service_path}${node_dir}:"
1993+
print_info "Including Node.js path: $node_dir"
1994+
fi
1995+
fi
1996+
1997+
# Add meshcore-decoder directory if found
19401998
if command -v meshcore-decoder &> /dev/null; then
19411999
local decoder_dir=$(dirname "$(which meshcore-decoder)")
1942-
service_path="${decoder_dir}:${service_path}"
2000+
if [ -n "$decoder_dir" ] && [ "$decoder_dir" != "." ] && [[ "$service_path" != *"$decoder_dir"* ]]; then
2001+
service_path="${service_path}${decoder_dir}:"
2002+
print_info "Including meshcore-decoder path: $decoder_dir"
2003+
fi
19432004
fi
19442005

2006+
# Add standard system paths
2007+
service_path="${service_path}/usr/bin:/bin:/usr/sbin:/sbin"
2008+
2009+
# Clean up any double colons
2010+
service_path=$(echo "$service_path" | sed 's/::*/:/g' | sed 's/^://' | sed 's/:$//')
2011+
2012+
print_info "Service PATH will include: $service_path"
2013+
19452014
cat > "$plist_file" << EOF
19462015
<?xml version="1.0" encoding="UTF-8"?>
19472016
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

0 commit comments

Comments
 (0)