@@ -14,14 +14,20 @@ Usage: install [options]
1414Options:
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
1822Examples:
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
2126EOF
2227}
2328
2429requested_version=" "
30+ no_modify_path=false
2531while [[ $# -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
3949done
@@ -80,23 +90,148 @@ version="${version#v}"
8090filename=" sentry-${os} -${arch}${suffix} "
8191url=" 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+
85126install_path=" ${install_dir} /sentry${suffix} "
86127
128+ # Create directory if needed
87129mkdir -p " $install_dir "
130+
131+ # Download binary
88132echo -e " ${MUTED} Downloading sentry v${version} ...${NC} "
89133curl -fsSL --progress-bar " $url " -o " $install_path "
90134chmod +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
93227echo " "
94228echo -e " Installed ${NC} sentry v${version}${MUTED} to ${NC}${install_path} "
95229echo " "
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
100235echo " sentry --help"
101236echo " "
102237echo -e " ${MUTED} https://cli.sentry.dev${NC} "
0 commit comments