Skip to content

Commit 5819e04

Browse files
feat: install brev CLI to ~/.local/bin without requiring sudo
- Changed install-latest.sh and install-latest-linux.sh to install to ~/.local/bin instead of /usr/local/bin, removing the need for sudo - Added PATH warning if ~/.local/bin is not in the user's PATH - Updated README install instructions to remove sudo prefix - Removed sudo gating from the upgrade command's direct install path - Updated upgrade message to reflect new install location Co-Authored-By: Alec Fong <alecsanf@usc.edu>
1 parent 1a12fd5 commit 5819e04

6 files changed

Lines changed: 46 additions & 24 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ brew install brevdev/homebrew-brev/brev
1414
### Linux
1515

1616
```bash
17-
sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/brevdev/brev-cli/main/bin/install-latest.sh)"
17+
bash -c "$(curl -fsSL https://raw.githubusercontent.com/brevdev/brev-cli/main/bin/install-latest.sh)"
1818
```
1919

2020
### Windows
@@ -30,7 +30,7 @@ Brev is supported on windows currently through the Windows Subsystem for Linux (
3030
Once you have WSL installed and configured, you can install Brev by running the following command in your terminal:
3131

3232
```bash
33-
sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/brevdev/brev-cli/main/bin/install-latest.sh)"
33+
bash -c "$(curl -fsSL https://raw.githubusercontent.com/brevdev/brev-cli/main/bin/install-latest.sh)"
3434
```
3535

3636
### From conda-forge

bin/install-latest-linux.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@ curl -L "${DOWNLOAD_URL}" -o "${TMP_DIR}/$(basename "${DOWNLOAD_URL}")"
1515
ARCHIVE_FILE="$(find "${TMP_DIR}" -name "brev*.tar.gz" -type f)"
1616
tar -xzf "${ARCHIVE_FILE}" -C "${TMP_DIR}"
1717

18-
# Install the binary to system location
19-
sudo mv "${TMP_DIR}/brev" /usr/local/bin/brev
20-
sudo chmod +x /usr/local/bin/brev
18+
# Install the binary to user-local location (no sudo required)
19+
INSTALL_DIR="${HOME}/.local/bin"
20+
mkdir -p "${INSTALL_DIR}"
21+
mv "${TMP_DIR}/brev" "${INSTALL_DIR}/brev"
22+
chmod +x "${INSTALL_DIR}/brev"
23+
24+
echo "Successfully installed brev CLI to ${INSTALL_DIR}/brev"
25+
26+
# Warn if the install directory is not in PATH
27+
case ":${PATH}:" in
28+
*":${INSTALL_DIR}:"*) ;;
29+
*)
30+
echo ""
31+
echo "WARNING: ${INSTALL_DIR} is not in your PATH."
32+
echo "Add it by running:"
33+
echo ""
34+
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc && source ~/.bashrc"
35+
echo ""
36+
;;
37+
esac
2138

bin/install-latest.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,23 @@ trap 'rm -rf "${TMP_DIR}"' EXIT
2626
curl -sL "${DOWNLOAD_URL}" -o "${TMP_DIR}/brev.tar.gz"
2727
tar -xzf "${TMP_DIR}/brev.tar.gz" -C "${TMP_DIR}"
2828

29-
# Install the binary to system location
30-
sudo mv "${TMP_DIR}/brev" /usr/local/bin/brev
31-
sudo chmod +x /usr/local/bin/brev
29+
# Install the binary to user-local location (no sudo required)
30+
INSTALL_DIR="${HOME}/.local/bin"
31+
mkdir -p "${INSTALL_DIR}"
32+
mv "${TMP_DIR}/brev" "${INSTALL_DIR}/brev"
33+
chmod +x "${INSTALL_DIR}/brev"
3234

33-
echo "Successfully installed brev CLI to /usr/local/bin/brev"
35+
echo "Successfully installed brev CLI to ${INSTALL_DIR}/brev"
36+
37+
# Warn if the install directory is not in PATH
38+
case ":${PATH}:" in
39+
*":${INSTALL_DIR}:"*) ;;
40+
*)
41+
echo ""
42+
echo "WARNING: ${INSTALL_DIR} is not in your PATH."
43+
echo "Add it by running:"
44+
echo ""
45+
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc && source ~/.bashrc"
46+
echo ""
47+
;;
48+
esac

pkg/cmd/upgrade/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (SystemUpgrader) UpgradeViaBrew(t *terminal.Terminal) error {
3333
return nil
3434
}
3535

36-
// UpgradeViaInstallScript runs the upstream install-latest.sh script via sudo.
36+
// UpgradeViaInstallScript runs the upstream install-latest.sh script.
3737
func (SystemUpgrader) UpgradeViaInstallScript(t *terminal.Terminal) error {
3838
t.Vprintf("Running: bash -c \"$(curl -fsSL %s)\"\n", installScriptURL)
3939
t.Vprint("")

pkg/cmd/upgrade/upgrade.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/brevdev/brev-cli/pkg/cmd/register"
1010
"github.com/brevdev/brev-cli/pkg/cmd/version"
1111
"github.com/brevdev/brev-cli/pkg/store"
12-
"github.com/brevdev/brev-cli/pkg/sudo"
1312
"github.com/brevdev/brev-cli/pkg/terminal"
1413

1514
"github.com/spf13/cobra"
@@ -43,7 +42,6 @@ type upgradeDeps struct {
4342
detector Detector
4443
upgrader Upgrader
4544
confirmer terminal.Confirmer
46-
gater sudo.Gater
4745
skillInstaller SkillInstaller
4846
}
4947

@@ -52,7 +50,6 @@ func defaultUpgradeDeps() upgradeDeps {
5250
detector: SystemDetector{},
5351
upgrader: SystemUpgrader{},
5452
confirmer: register.TerminalPrompter{},
55-
gater: sudo.Default,
5653
skillInstaller: defaultSkillInstaller{},
5754
}
5855
}
@@ -146,11 +143,12 @@ func upgradeViaBrew(t *terminal.Terminal, deps upgradeDeps) (bool, error) {
146143

147144
func upgradeViaDirect(t *terminal.Terminal, deps upgradeDeps) (bool, error) {
148145
t.Vprint("Detected install method: direct binary install")
149-
t.Vprint("This will download the latest release and install it to /usr/local/bin/brev")
146+
t.Vprint("This will download the latest release and install it to ~/.local/bin/brev")
150147
t.Vprint("")
151148

152-
if err := deps.gater.Gate(t, deps.confirmer, "Upgrade", false); err != nil {
153-
return false, fmt.Errorf("sudo issue: %w", err)
149+
if !deps.confirmer.ConfirmYesNo("Proceed with upgrade?") {
150+
t.Vprint("Upgrade canceled.")
151+
return false, nil
154152
}
155153

156154
t.Vprint("")

pkg/cmd/upgrade/upgrade_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/brevdev/brev-cli/pkg/cmd/version"
88
"github.com/brevdev/brev-cli/pkg/store"
9-
"github.com/brevdev/brev-cli/pkg/sudo"
109
"github.com/brevdev/brev-cli/pkg/terminal"
1110
)
1211

@@ -65,7 +64,6 @@ func Test_runUpgrade_AlreadyUpToDate(t *testing.T) {
6564
detector: mockDetector{method: InstallMethodBrew},
6665
upgrader: upgrader,
6766
confirmer: mockConfirmer{confirm: true},
68-
gater: sudo.CachedGater{},
6967
skillInstaller: skill,
7068
}
7169

@@ -94,7 +92,6 @@ func Test_runUpgrade_BrewPath(t *testing.T) {
9492
detector: mockDetector{method: InstallMethodBrew},
9593
upgrader: upgrader,
9694
confirmer: mockConfirmer{confirm: true},
97-
gater: sudo.CachedGater{},
9895
skillInstaller: skill,
9996
}
10097

@@ -126,7 +123,6 @@ func Test_runUpgrade_DirectPath(t *testing.T) {
126123
detector: mockDetector{method: InstallMethodDirect},
127124
upgrader: upgrader,
128125
confirmer: mockConfirmer{confirm: true},
129-
gater: sudo.CachedGater{},
130126
skillInstaller: skill,
131127
}
132128

@@ -158,7 +154,6 @@ func Test_runUpgrade_UserCancels(t *testing.T) {
158154
detector: mockDetector{method: InstallMethodBrew},
159155
upgrader: upgrader,
160156
confirmer: mockConfirmer{confirm: false},
161-
gater: sudo.CachedGater{},
162157
skillInstaller: skill,
163158
}
164159

@@ -181,7 +176,6 @@ func Test_runUpgrade_VersionCheckFails(t *testing.T) {
181176
detector: mockDetector{method: InstallMethodBrew},
182177
upgrader: &mockUpgrader{},
183178
confirmer: mockConfirmer{confirm: true},
184-
gater: sudo.CachedGater{},
185179
skillInstaller: &mockSkillInstaller{},
186180
}
187181

@@ -204,7 +198,6 @@ func Test_runUpgrade_UpgraderFails(t *testing.T) {
204198
detector: mockDetector{method: InstallMethodBrew},
205199
upgrader: upgrader,
206200
confirmer: mockConfirmer{confirm: true},
207-
gater: sudo.CachedGater{},
208201
skillInstaller: skill,
209202
}
210203

@@ -230,7 +223,6 @@ func Test_runUpgrade_SkillInstallFailure_DoesNotFailUpgrade(t *testing.T) {
230223
detector: mockDetector{method: InstallMethodBrew},
231224
upgrader: upgrader,
232225
confirmer: mockConfirmer{confirm: true},
233-
gater: sudo.CachedGater{},
234226
skillInstaller: skill,
235227
}
236228

0 commit comments

Comments
 (0)