Skip to content

Commit 0f3ada0

Browse files
committed
review feedback
1 parent 16ab265 commit 0f3ada0

4 files changed

Lines changed: 17 additions & 69 deletions

File tree

pkg/cmd/register/register_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ func Test_runRegister_UserCancels(t *testing.T) {
255255
}
256256

257257
// Registration should not exist
258-
exists, eerr := regStore.Exists()
259-
if eerr != nil {
260-
t.Fatalf("Exists error: %v", eerr)
258+
exists, err := regStore.Exists()
259+
if err != nil {
260+
t.Fatalf("Exists error: %v", err)
261261
}
262262
if exists {
263263
t.Error("registration should not exist after cancel")

pkg/cmd/upgrade/detector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ type InstallMethod int
77

88
const (
99
// InstallMethodDirect means brev was installed via direct binary download.
10-
InstallMethodDirect InstallMethod = iota
10+
InstallMethodDirect InstallMethod = 0
1111
// InstallMethodBrew means brev was installed via Homebrew.
12-
InstallMethodBrew
12+
InstallMethodBrew InstallMethod = 1
1313
)
1414

1515
// Detector determines how brev was installed.

pkg/cmd/upgrade/runner.go

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"fmt"
55
"os"
66
"os/exec"
7-
"path/filepath"
8-
"runtime"
97

108
"github.com/brevdev/brev-cli/pkg/terminal"
119
)
1210

11+
const installScriptURL = "https://raw.githubusercontent.com/brevdev/brev-cli/main/bin/install-latest.sh"
12+
1313
// Upgrader executes the actual upgrade process.
1414
type Upgrader interface {
1515
UpgradeViaBrew(t *terminal.Terminal) error
@@ -33,68 +33,16 @@ func (SystemUpgrader) UpgradeViaBrew(t *terminal.Terminal) error {
3333
return nil
3434
}
3535

36-
// UpgradeViaInstallScript downloads and installs the latest brev binary from GitHub.
36+
// UpgradeViaInstallScript runs the upstream install-latest.sh script via sudo.
3737
func (SystemUpgrader) UpgradeViaInstallScript(t *terminal.Terminal) error {
38-
osName := runtime.GOOS
39-
arch := runtime.GOARCH
40-
41-
t.Vprintf("Detected platform: %s/%s\n", osName, arch)
38+
t.Vprintf("Running: bash -c \"$(curl -fsSL %s)\"\n", installScriptURL)
4239
t.Vprint("")
4340

44-
// Fetch latest release download URL
45-
t.Vprint("Fetching latest release...")
46-
pattern := fmt.Sprintf("browser_download_url.*%s.*%s", osName, arch)
47-
curlCmd := fmt.Sprintf(
48-
`curl -s https://api.github.com/repos/brevdev/brev-cli/releases/latest | grep "%s" | cut -d '"' -f 4`,
49-
pattern,
50-
)
51-
out, err := exec.Command("bash", "-c", curlCmd).Output() //nolint:gosec // constructing URL pattern from known values
52-
if err != nil {
53-
return fmt.Errorf("failed to fetch latest release: %w", err)
54-
}
55-
downloadURL := string(out)
56-
if downloadURL == "" {
57-
return fmt.Errorf("could not find release for %s/%s", osName, arch)
58-
}
59-
// Trim trailing newline
60-
downloadURL = downloadURL[:len(downloadURL)-1]
61-
62-
// Create temp directory
63-
tmpDir, err := os.MkdirTemp("", "brev-upgrade-*")
64-
if err != nil {
65-
return fmt.Errorf("failed to create temp directory: %w", err)
66-
}
67-
defer os.RemoveAll(tmpDir)
68-
69-
// Download
70-
t.Vprintf("Downloading %s...\n", downloadURL)
71-
tarPath := filepath.Join(tmpDir, "brev.tar.gz")
72-
dlCmd := exec.Command("curl", "-sL", downloadURL, "-o", tarPath)
73-
dlCmd.Stderr = os.Stderr
74-
if err := dlCmd.Run(); err != nil {
75-
return fmt.Errorf("download failed: %w", err)
76-
}
77-
78-
// Extract
79-
extractCmd := exec.Command("tar", "-xzf", tarPath, "-C", tmpDir)
80-
if err := extractCmd.Run(); err != nil {
81-
return fmt.Errorf("extraction failed: %w", err)
82-
}
83-
84-
// Install with sudo
85-
brevPath := filepath.Join(tmpDir, "brev")
86-
t.Vprint("Installing to /usr/local/bin/brev...")
87-
mvCmd := exec.Command("sudo", "mv", brevPath, "/usr/local/bin/brev")
88-
mvCmd.Stdout = os.Stdout
89-
mvCmd.Stderr = os.Stderr
90-
if err := mvCmd.Run(); err != nil {
91-
return fmt.Errorf("failed to install binary: %w", err)
92-
}
93-
94-
chmodCmd := exec.Command("sudo", "chmod", "+x", "/usr/local/bin/brev")
95-
if err := chmodCmd.Run(); err != nil {
96-
return fmt.Errorf("failed to set permissions: %w", err)
41+
cmd := exec.Command("bash", "-c", fmt.Sprintf(`curl -fsSL "%s" | bash`, installScriptURL)) //nolint:gosec // URL is a compile-time constant
42+
cmd.Stdout = os.Stdout
43+
cmd.Stderr = os.Stderr
44+
if err := cmd.Run(); err != nil {
45+
return fmt.Errorf("install script failed: %w", err)
9746
}
98-
9947
return nil
10048
}

pkg/sudo/sudo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ type Status int
1414

1515
const (
1616
// StatusRoot means the process is already running as root.
17-
StatusRoot Status = iota
17+
StatusRoot Status = 0
1818
// StatusCached means the user has a valid sudo timestamp (no password needed).
19-
StatusCached
19+
StatusCached Status = 1
2020
// StatusUncached means sudo will require a password prompt.
21-
StatusUncached
21+
StatusUncached Status = 2
2222
)
2323

2424
// Check returns the current sudo status.

0 commit comments

Comments
 (0)