github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/upgrade_instructions.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "fmt" 8 "runtime" 9 10 "os/exec" 11 ) 12 13 func PlatformSpecificUpgradeInstructionsString() (string, error) { 14 switch runtime.GOOS { 15 case "linux": 16 return linuxUpgradeInstructionsString() 17 default: 18 return "", nil 19 } 20 } 21 22 func PlatformSpecificUpgradeInstructions(g *GlobalContext, upgradeURI string) { 23 switch runtime.GOOS { 24 case "linux": 25 linuxUpgradeInstructions(g) 26 case "darwin", "ios": 27 darwinUpgradeInstructions(g, upgradeURI) 28 case "windows": 29 windowsUpgradeInstructions(g, upgradeURI) 30 } 31 } 32 33 func linuxUpgradeInstructions(g *GlobalContext) { 34 upgradeInstructions, err := linuxUpgradeInstructionsString() 35 if err == nil { 36 printUpgradeCommand(g, upgradeInstructions) 37 } 38 } 39 40 func linuxUpgradeInstructionsString() (string, error) { 41 hasPackageManager := func(name string) bool { 42 // Not all package managers are in /usr/bin. (openSUSE for example puts 43 // Yast in /usr/sbin.) Better to just do the full check now than to get 44 // confused later. 45 _, err := exec.LookPath(name) 46 return err == nil 47 } 48 49 packageName := "keybase" 50 51 var start string 52 if hasPackageManager("apt-get") { 53 start = "sudo apt-get update; sudo apt-get install " + packageName 54 } else if hasPackageManager("dnf") { 55 start = "sudo dnf upgrade " + packageName 56 } else if hasPackageManager("yum") { 57 start = "sudo yum upgrade " + packageName 58 } else if hasPackageManager("pacman") { 59 if len(PrereleaseBuild) > 0 { 60 start = "pacaur -S keybase-bin" 61 } else { 62 start = "sudo pacman -Syu" 63 } 64 } else { 65 return "", fmt.Errorf("Unhandled Linux upgrade instruction.") 66 } 67 68 complete := start + " && run_keybase" 69 return complete, nil 70 } 71 72 func darwinUpgradeInstructions(g *GlobalContext, upgradeURI string) { 73 packageName := "keybase" 74 if DefaultRunMode == DevelRunMode { 75 packageName = "keybase/beta/kbdev" 76 } else if DefaultRunMode == StagingRunMode { 77 packageName = "keybase/beta/kbstage" 78 } 79 80 if IsBrewBuild { 81 printUpgradeCommand(g, "brew update && brew upgrade "+packageName) 82 } else { 83 g.Log.Warning(" Please download a new version from " + upgradeURI) 84 } 85 // TODO: non-brew update instructions 86 } 87 88 func windowsUpgradeInstructions(g *GlobalContext, upgradeURI string) { 89 90 g.Log.Warning("To upgrade, download the latest Keybase installer from " + upgradeURI) 91 } 92 func printUpgradeCommand(g *GlobalContext, command string) { 93 g.Log.Warning("To upgrade, run the following command:") 94 g.Log.Warning(" " + command) 95 }