forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_update.go
192 lines (166 loc) · 4.33 KB
/
cmd_update.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"fmt"
"runtime"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol"
"github.com/keybase/client/go/updater"
"github.com/keybase/client/go/updater/sources"
"github.com/keybase/go-framed-msgpack-rpc"
"golang.org/x/net/context"
)
func NewCmdUpdate(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "update",
Usage: "The updater",
ArgumentHelp: "[arguments...]",
Subcommands: []cli.Command{
NewCmdUpdateCheck(cl, g),
NewCmdUpdateCustom(cl, g),
},
}
}
func NewCmdUpdateCheck(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "check",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "f, force",
Usage: "Force update.",
},
},
ArgumentHelp: "",
Usage: "Perform an update check",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdUpdateCheckRunner(g), "check", c)
},
}
}
type CmdUpdateCheck struct {
libkb.Contextified
force bool
}
func NewCmdUpdateCheckRunner(g *libkb.GlobalContext) *CmdUpdateCheck {
return &CmdUpdateCheck{
Contextified: libkb.NewContextified(g),
}
}
func (v *CmdUpdateCheck) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
Config: true,
}
}
func (v *CmdUpdateCheck) ParseArgv(ctx *cli.Context) error {
v.force = ctx.Bool("force")
return nil
}
func (v *CmdUpdateCheck) Run() error {
protocols := []rpc.Protocol{
NewUpdateUIProtocol(v.G()),
}
if err := RegisterProtocolsWithContext(protocols, v.G()); err != nil {
return err
}
client, err := GetUpdateClient(v.G())
if err != nil {
return err
}
return client.UpdateCheck(context.TODO(), v.force)
}
func NewCmdUpdateCustom(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "custom",
Flags: []cli.Flag{
cli.StringFlag{
Name: "c, check-only",
Usage: "Only check for update.",
},
cli.StringFlag{
Name: "e, current-version",
Usage: "Current version of to override.",
},
cli.StringFlag{
Name: "d, destination-path",
Usage: "Destination of where to apply update.",
},
cli.StringFlag{
Name: "s, source",
Usage: fmt.Sprintf("Update source (%s). Default is %q.",
sources.UpdateSourcesDescription(", "),
string(sources.DefaultUpdateSourceName())),
},
cli.StringFlag{
Name: "u, url",
Usage: "Custom URL.",
},
cli.BoolFlag{
Name: "f, force",
Usage: "Force update.",
},
},
ArgumentHelp: "",
Usage: "Run the updater with custom options",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdUpdateCustomRunner(g), "run", c)
},
}
}
type CmdUpdateCustom struct {
libkb.Contextified
checkOnly bool
source string
options *keybase1.UpdateOptions
}
func NewCmdUpdateCustomRunner(g *libkb.GlobalContext) *CmdUpdateCustom {
return &CmdUpdateCustom{
Contextified: libkb.NewContextified(g),
options: updater.DefaultUpdaterOptions(g),
}
}
func (v *CmdUpdateCustom) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
Config: true,
}
}
func (v *CmdUpdateCustom) ParseArgv(ctx *cli.Context) error {
currentVersion := ctx.String("current-version")
if currentVersion != "" {
v.options.Version = currentVersion
}
destinationPath := ctx.String("destination-path")
if destinationPath != "" {
v.options.DestinationPath = destinationPath
}
v.options.Source = ctx.String("source")
v.options.Platform = runtime.GOOS
v.options.URL = ctx.String("url")
v.options.Force = ctx.Bool("force")
if v.options.DestinationPath == "" {
return fmt.Errorf("No default destination path for this environment")
}
return nil
}
func (v *CmdUpdateCustom) Run() error {
if libkb.IsBrewBuild {
return fmt.Errorf("Update is not supported for brew install. Use \"brew update && brew upgrade keybase\" instead.")
}
protocols := []rpc.Protocol{
NewUpdateUIProtocol(v.G()),
}
if err := RegisterProtocolsWithContext(protocols, v.G()); err != nil {
return err
}
client, err := GetUpdateClient(v.G())
if err != nil {
return err
}
v.G().Log.Debug("Options: %#v", *v.options)
_, err = client.Update(context.TODO(), *v.options)
return err
}