Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkg/update/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,39 @@ func FetchLatest(ctx context.Context) (tag string, url string, err error) {
return "", "", errors.New("no stable releases found")
}

// isOnOldBrewTap checks if the user has kernel installed from onkernel/tap
// instead of the current kernel/tap by checking the install receipt.
func isOnOldBrewTap() bool {
// Find the Homebrew Cellar path
cellarPaths := []string{
"/opt/homebrew/Cellar/kernel", // Apple Silicon
"/usr/local/Cellar/kernel", // Intel Mac
"/home/linuxbrew/.linuxbrew/Cellar/kernel", // Linux
}

for _, cellar := range cellarPaths {
entries, err := os.ReadDir(cellar)
if err != nil {
continue
}
for _, entry := range entries {
if !entry.IsDir() {
continue
}
receiptPath := filepath.Join(cellar, entry.Name(), "INSTALL_RECEIPT.json")
data, err := os.ReadFile(receiptPath)
if err != nil {
continue
}
// Check if installed from onkernel/tap
if strings.Contains(string(data), `"tap":"onkernel/tap"`) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON string matching may miss whitespace variations

Medium Severity

The isOnOldBrewTap() function uses literal string matching "tap":"onkernel/tap" (no space after colon) to detect the tap source. However, JSON formatting can vary - Homebrew may output "tap": "onkernel/tap" (with space after colon) depending on whether it uses compact or pretty-printed JSON. If the actual file has whitespace differences, the detection silently fails, and users on the old tap receive incorrect upgrade instructions (brew upgrade kernel/tap/kernel) instead of migration instructions. Since the encoding/json package is already imported, parsing the JSON properly would be more reliable.

Fix in Cursor Fix in Web

return true
}
}
}
return false
}

// printUpgradeMessage prints a concise upgrade banner.
func printUpgradeMessage(current, latest, url string) {
cur := strings.TrimPrefix(current, "v")
Expand All @@ -134,6 +167,18 @@ func printUpgradeMessage(current, latest, url string) {
if url != "" {
pterm.Info.Printf("Release notes: %s\n", url)
}

method, _ := DetectInstallMethod()
if method == InstallMethodBrew && isOnOldBrewTap() {
pterm.Println()
pterm.Warning.Println("You have kernel installed from the old tap (onkernel/tap).")
pterm.Warning.Println("To upgrade, switch to the new tap:")
pterm.Println()
pterm.Println(" brew uninstall kernel")
pterm.Println(" brew install kernel/tap/kernel")
return
}

if cmd := SuggestUpgradeCommand(); cmd != "" {
pterm.Info.Printf("To upgrade, run: %s\n", cmd)
} else {
Expand Down