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