Skip to content

Commit 3e73719

Browse files
committed
feat(install): prefer ~/.local/bin and record installation method
Install script changes: - Prefer ~/.local/bin or ~/bin when available and in $PATH - Fall back to ~/.sentry/bin only when needed (adds to PATH) - Support SENTRY_INSTALL_DIR env var for custom locations - Call 'sentry cli record-install' after installation New 'sentry cli record-install' command: - Records method, path, version in SQLite metadata table - Called automatically by install script - Enables future upgrades to use correct method/path Detection improvements: - Check stored install info first (fast path) - Legacy detection for existing installs (auto-saves for future) - Expanded known curl paths: ~/.local/bin, ~/bin, ~/.sentry/bin Upgrade command: - Persists --method flag for future upgrades - Uses stored path for curl upgrades instead of hardcoded path
1 parent fe8631b commit 3e73719

9 files changed

Lines changed: 678 additions & 211 deletions

File tree

docs/public/install

Lines changed: 0 additions & 189 deletions
This file was deleted.

docs/public/install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../install

install

Lines changed: 141 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ Usage: install [options]
1414
Options:
1515
-h, --help Display this help message
1616
-v, --version <version> Install a specific version (e.g., 0.2.0)
17+
--no-modify-path Don't modify shell config files (.zshrc, .bashrc, etc.)
18+
19+
Environment Variables:
20+
SENTRY_INSTALL_DIR Override the installation directory
1721
1822
Examples:
1923
curl -fsSL https://cli.sentry.dev/install | bash
2024
curl -fsSL https://cli.sentry.dev/install | bash -s -- --version 0.2.0
25+
SENTRY_INSTALL_DIR=~/.local/bin curl -fsSL https://cli.sentry.dev/install | bash
2126
EOF
2227
}
2328

2429
requested_version=""
30+
no_modify_path=false
2531
while [[ $# -gt 0 ]]; do
2632
case "$1" in
2733
-h|--help) usage; exit 0 ;;
@@ -34,6 +40,10 @@ while [[ $# -gt 0 ]]; do
3440
exit 1
3541
fi
3642
;;
43+
--no-modify-path)
44+
no_modify_path=true
45+
shift
46+
;;
3747
*) shift ;;
3848
esac
3949
done
@@ -80,23 +90,148 @@ version="${version#v}"
8090
filename="sentry-${os}-${arch}${suffix}"
8191
url="https://github.com/getsentry/cli/releases/download/${version}/${filename}"
8292

83-
# Install
84-
install_dir="$HOME/.sentry/bin"
93+
# Determine install directory
94+
# Priority:
95+
# 1. SENTRY_INSTALL_DIR environment variable (if set and writable)
96+
# 2. ~/.local/bin (if exists AND in $PATH)
97+
# 3. ~/bin (if exists AND in $PATH)
98+
# 4. ~/.sentry/bin (fallback, will modify PATH)
99+
needs_path_modification=false
100+
install_dir=""
101+
102+
if [[ -n "${SENTRY_INSTALL_DIR:-}" ]]; then
103+
# User explicitly specified install directory
104+
install_dir="$SENTRY_INSTALL_DIR"
105+
if [[ ! -d "$install_dir" ]]; then
106+
mkdir -p "$install_dir" 2>/dev/null || true
107+
fi
108+
if [[ ! -w "$install_dir" ]]; then
109+
echo -e "${RED}Error: Cannot write to $install_dir${NC}"
110+
echo -e "${MUTED}Try running with sudo or choose a different directory.${NC}"
111+
exit 1
112+
fi
113+
# Check if it's in PATH
114+
if ! echo "$PATH" | tr ':' '\n' | grep -Fxq "$install_dir"; then
115+
needs_path_modification=true
116+
fi
117+
elif [[ -d "$HOME/.local/bin" ]] && echo "$PATH" | tr ':' '\n' | grep -Fxq "$HOME/.local/bin"; then
118+
install_dir="$HOME/.local/bin"
119+
elif [[ -d "$HOME/bin" ]] && echo "$PATH" | tr ':' '\n' | grep -Fxq "$HOME/bin"; then
120+
install_dir="$HOME/bin"
121+
else
122+
install_dir="$HOME/.sentry/bin"
123+
needs_path_modification=true
124+
fi
125+
85126
install_path="${install_dir}/sentry${suffix}"
86127

128+
# Create directory if needed
87129
mkdir -p "$install_dir"
130+
131+
# Download binary
88132
echo -e "${MUTED}Downloading sentry v${version}...${NC}"
89133
curl -fsSL --progress-bar "$url" -o "$install_path"
90134
chmod +x "$install_path"
91135

136+
# Record installation metadata
137+
"$install_path" cli record-install --method curl 2>/dev/null || true
138+
139+
# Add to PATH (helper function)
140+
add_to_path() {
141+
local config_file=$1
142+
local command=$2
143+
144+
if grep -Fxq "$command" "$config_file"; then
145+
echo -e "${MUTED}PATH already configured in ${NC}$config_file"
146+
elif [[ -w $config_file ]]; then
147+
echo -e "\n# sentry" >> "$config_file"
148+
echo "$command" >> "$config_file"
149+
echo -e "${MUTED}Added ${NC}sentry ${MUTED}to PATH in ${NC}$config_file"
150+
else
151+
echo -e "${MUTED}Manually add the directory to $config_file (or similar):${NC}"
152+
echo " $command"
153+
fi
154+
}
155+
156+
# Only modify PATH if needed (fallback to ~/.sentry/bin or custom non-PATH dir)
157+
if [[ "$needs_path_modification" == "true" ]] && [[ "$no_modify_path" != "true" ]]; then
158+
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
159+
160+
current_shell=$(basename "${SHELL:-sh}")
161+
case $current_shell in
162+
fish)
163+
config_files=("$XDG_CONFIG_HOME/fish/config.fish")
164+
;;
165+
zsh)
166+
config_files=("$HOME/.zshrc" "$HOME/.zshenv" "$XDG_CONFIG_HOME/zsh/.zshrc" "$XDG_CONFIG_HOME/zsh/.zshenv")
167+
;;
168+
bash)
169+
config_files=("$HOME/.bash_profile" "$HOME/.bashrc" "$HOME/.profile" "$XDG_CONFIG_HOME/bash/.bash_profile" "$XDG_CONFIG_HOME/bash/.bashrc")
170+
;;
171+
ash|sh)
172+
config_files=("$HOME/.profile" "/etc/profile")
173+
;;
174+
*)
175+
config_files=("$HOME/.bash_profile" "$HOME/.bashrc" "$HOME/.profile")
176+
;;
177+
esac
178+
179+
config_file=""
180+
for file in "${config_files[@]}"; do
181+
if [[ -f $file ]]; then
182+
config_file=$file
183+
break
184+
fi
185+
done
186+
187+
if [[ -z $config_file ]]; then
188+
echo -e "${MUTED}No config file found. Manually add to PATH:${NC}"
189+
case $current_shell in
190+
fish)
191+
echo " fish_add_path \"$install_dir\""
192+
;;
193+
*)
194+
echo " export PATH=\"$install_dir\":\$PATH"
195+
;;
196+
esac
197+
else
198+
case $current_shell in
199+
fish)
200+
add_to_path "$config_file" "fish_add_path \"$install_dir\""
201+
;;
202+
*)
203+
add_to_path "$config_file" "export PATH=\"$install_dir\":\$PATH"
204+
;;
205+
esac
206+
fi
207+
elif [[ "$needs_path_modification" == "true" ]] && [[ "$no_modify_path" == "true" ]]; then
208+
echo -e "${MUTED}Skipping PATH modification. Manually add to your shell config:${NC}"
209+
current_shell=$(basename "${SHELL:-sh}")
210+
case $current_shell in
211+
fish)
212+
echo " fish_add_path \"$install_dir\""
213+
;;
214+
*)
215+
echo " export PATH=\"$install_dir\":\$PATH"
216+
;;
217+
esac
218+
fi
219+
220+
# GitHub Actions support
221+
if [[ -n "${GITHUB_ACTIONS:-}" ]] && [[ "${GITHUB_ACTIONS}" == "true" ]] && [[ -n "${GITHUB_PATH:-}" ]]; then
222+
echo "$install_dir" >> "$GITHUB_PATH"
223+
echo -e "${MUTED}Added to \$GITHUB_PATH${NC}"
224+
fi
225+
92226
# Success message
93227
echo ""
94228
echo -e "Installed ${NC}sentry v${version}${MUTED} to ${NC}${install_path}"
95229
echo ""
96-
echo -e "${MUTED}Add to PATH (add to ~/.zshrc or ~/.bashrc):${NC}"
97-
echo " export PATH=\"\$HOME/.sentry/bin:\$PATH\""
98-
echo ""
99-
echo -e "${MUTED}Get started:${NC}"
230+
if [[ "$needs_path_modification" == "true" ]]; then
231+
echo -e "${MUTED}Get started (restart your shell or open a new terminal):${NC}"
232+
else
233+
echo -e "${MUTED}Get started:${NC}"
234+
fi
100235
echo " sentry --help"
101236
echo ""
102237
echo -e "${MUTED}https://cli.sentry.dev${NC}"

src/commands/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { buildRouteMap } from "@stricli/core";
22
import { feedbackCommand } from "./feedback.js";
33
import { fixCommand } from "./fix.js";
4+
import { recordInstallCommand } from "./record-install.js";
45
import { upgradeCommand } from "./upgrade.js";
56

67
export const cliRoute = buildRouteMap({
78
routes: {
89
feedback: feedbackCommand,
910
fix: fixCommand,
11+
"record-install": recordInstallCommand,
1012
upgrade: upgradeCommand,
1113
},
1214
docs: {

0 commit comments

Comments
 (0)