remove old update code
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Dec 29, 2015 at 07:13 UTC
f3f776067acdc54c4ce84d0f8471648cc5ea3061
4 files changed
-547
cmd/ipfs/ipfs.go
-3
@@ -104,8 +104,5 @@ var cmdDetailsMap = map[*cmds.Command]cmdDetails{
104
commandsClientCmd: {doesNotUseRepo: true},
105
commands.CommandsDaemonCmd: {doesNotUseRepo: true},
106
commands.VersionCmd: {doesNotUseConfigAsInput: true, doesNotUseRepo: true}, // must be permitted to run before init
107
- commands.UpdateCmd: {preemptsAutoUpdate: true, cannotRunOnDaemon: true},
108
- commands.UpdateCheckCmd: {preemptsAutoUpdate: true},
109
- commands.UpdateLogCmd: {preemptsAutoUpdate: true},
107
commands.LogCmd: {cannotRunOnClient: true},
108
}
core/commands/update.go
deleted
-182
@@ -1,182 +0,0 @@
1
-package commands
2
-
3
-import (
4
- "bytes"
5
- "errors"
6
- "fmt"
7
- "io"
8
-
9
- cmds "github.com/ipfs/go-ipfs/commands"
10
- "github.com/ipfs/go-ipfs/core"
11
- "github.com/ipfs/go-ipfs/updates"
12
-)
13
-
14
-type UpdateOutput struct {
15
- OldVersion string
16
- NewVersion string
17
-}
18
-
19
-var UpdateCmd = &cmds.Command{
20
- Helptext: cmds.HelpText{
21
- Tagline: "Downloads and installs updates for IPFS (disabled)",
22
- ShortDescription: `ipfs update is disabled until we can deploy the binaries to you over ipfs itself.
23
-
24
- please use 'go get -u github.com/ipfs/go-ipfs/cmd/ipfs' until then.`,
25
- },
26
-}
27
-
28
-// TODO: unexported until we can deploy the binaries over ipfs
29
-var updateCmd = &cmds.Command{
30
- Helptext: cmds.HelpText{
31
- Tagline: "Downloads and installs updates for IPFS",
32
- ShortDescription: "ipfs update is a utility command used to check for updates and apply them.",
33
- },
34
-
35
- Run: func(req cmds.Request, res cmds.Response) {
36
- n, err := req.InvocContext().GetNode()
37
- if err != nil {
38
- res.SetError(err, cmds.ErrNormal)
39
- return
40
- }
41
-
42
- output, err := updateApply(n)
43
- if err != nil {
44
- res.SetError(err, cmds.ErrNormal)
45
- return
46
- }
47
- res.SetOutput(output)
48
- },
49
- Type: UpdateOutput{},
50
- Subcommands: map[string]*cmds.Command{
51
- "check": UpdateCheckCmd,
52
- "log": UpdateLogCmd,
53
- },
54
- Marshalers: cmds.MarshalerMap{
55
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
56
- v := res.Output().(*UpdateOutput)
57
- buf := new(bytes.Buffer)
58
- if v.NewVersion != v.OldVersion {
59
- buf.WriteString(fmt.Sprintf("Successfully updated to IPFS version '%s' (from '%s')\n",
60
- v.NewVersion, v.OldVersion))
61
- } else {
62
- buf.WriteString(fmt.Sprintf("Already updated to latest version ('%s')\n", v.NewVersion))
63
- }
64
- return buf, nil
65
- },
66
- },
67
-}
68
-
69
-var UpdateCheckCmd = &cmds.Command{
70
- Helptext: cmds.HelpText{
71
- Tagline: "Checks if updates are available",
72
- ShortDescription: "'ipfs update check' checks if any updates are available for IPFS.\nNothing will be downloaded or installed.",
73
- },
74
-
75
- Run: func(req cmds.Request, res cmds.Response) {
76
- n, err := req.InvocContext().GetNode()
77
- if err != nil {
78
- res.SetError(err, cmds.ErrNormal)
79
- return
80
- }
81
-
82
- output, err := updateCheck(n)
83
- if err != nil {
84
- res.SetError(err, cmds.ErrNormal)
85
- return
86
- }
87
- res.SetOutput(output)
88
- },
89
- Type: UpdateOutput{},
90
- Marshalers: cmds.MarshalerMap{
91
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
92
- v := res.Output().(*UpdateOutput)
93
- buf := new(bytes.Buffer)
94
- if v.NewVersion != v.OldVersion {
95
- buf.WriteString(fmt.Sprintf("A new version of IPFS is available ('%s', currently running '%s')\n",
96
- v.NewVersion, v.OldVersion))
97
- } else {
98
- buf.WriteString(fmt.Sprintf("Already updated to latest version ('%s')\n", v.NewVersion))
99
- }
100
- return buf, nil
101
- },
102
- },
103
-}
104
-
105
-var UpdateLogCmd = &cmds.Command{
106
- Helptext: cmds.HelpText{
107
- Tagline: "List the changelog for the latest versions of IPFS",
108
- ShortDescription: "This command is not yet implemented.",
109
- },
110
-
111
- Run: func(req cmds.Request, res cmds.Response) {
112
- n, err := req.InvocContext().GetNode()
113
- if err != nil {
114
- res.SetError(err, cmds.ErrNormal)
115
- return
116
- }
117
-
118
- output, err := updateLog(n)
119
- if err != nil {
120
- res.SetError(err, cmds.ErrNormal)
121
- return
122
- }
123
- res.SetOutput(output)
124
- },
125
-}
126
-
127
-// updateApply applies an update of the ipfs binary and shuts down the node if successful
128
-func updateApply(n *core.IpfsNode) (*UpdateOutput, error) {
129
- // TODO: 'force bool' param that stops the daemon (if running) before update
130
-
131
- output := &UpdateOutput{
132
- OldVersion: updates.Version,
133
- }
134
-
135
- u, err := updates.CheckForUpdate()
136
- if err != nil {
137
- return nil, err
138
- }
139
-
140
- if u == nil {
141
- output.NewVersion = updates.Version
142
- return output, nil
143
- }
144
-
145
- output.NewVersion = u.Version
146
-
147
- if n.OnlineMode() {
148
- return nil, errors.New(`You must stop the IPFS daemon before updating.`)
149
- }
150
-
151
- if err = updates.Apply(u); err != nil {
152
- return nil, err
153
- }
154
-
155
- return output, nil
156
-}
157
-
158
-// updateCheck checks wether there is an update available
159
-func updateCheck(n *core.IpfsNode) (*UpdateOutput, error) {
160
- output := &UpdateOutput{
161
- OldVersion: updates.Version,
162
- }
163
-
164
- u, err := updates.CheckForUpdate()
165
- if err != nil {
166
- return nil, err
167
- }
168
-
169
- if u == nil {
170
- output.NewVersion = updates.Version
171
- return output, nil
172
- }
173
-
174
- output.NewVersion = u.Version
175
- return output, nil
176
-}
177
-
178
-// updateLog lists the version available online
179
-func updateLog(n *core.IpfsNode) (interface{}, error) {
180
- // TODO
181
- return nil, errors.New("Not yet implemented")
182
-}
updates/updates.go
deleted
-302
@@ -1,302 +0,0 @@
1
-package updates
2
-
3
-import (
4
- "errors"
5
- "fmt"
6
- "os"
7
- "time"
8
-
9
- config "github.com/ipfs/go-ipfs/repo/config"
10
- fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
11
- logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
12
-
13
- semver "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
14
- update "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update"
15
- check "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update/check"
16
-)
17
-
18
-const (
19
- // Version is the current application's version literal
20
- Version = config.CurrentVersionNumber
21
-
22
- updateEndpointURL = "https://api.equinox.io/1/Updates"
23
- updateAppID = "ap_YM8nz6rGm1UPg_bf63Lw6Vjz49"
24
-
25
- // this is @jbenet's equinox.io public key.
26
- updatePubKey = `-----BEGIN RSA PUBLIC KEY-----
27
-MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxnwPPE4LNMjTfW/NRz1z
28
-8uAPpwGYSzac+cwZbHbL5xFOxeX301GCdISaMm+Q8OEJqLyXfjYSuRwx00fDzWDD
29
-ajBQOsxO08gTy1i/ow5YdEO+nYeVKO08fQFqVqdTz09BCgzt9iQJTEMeiq1kSWNo
30
-al8usHD4SsNTxwDpSlok5UKWCHcr7D/TWX5A4B5A6ae9HSEcMB4Aum83k63Vzgm1
31
-WTUvK0ed1zd0/KcHqIU36VZpVg4PeV4SWnOBnldQ98CWg/Mnqp3+lXMWYWTmXeX6
32
-xj8JqOGpebzlxeISKE6fDBtrLxUbFTt3DNshl7S5CUGuc5H1MF1FTAyi+8u/nEZB
33
-cQIDAQAB
34
------END RSA PUBLIC KEY-----`
35
-
36
-/*
37
-
38
-You can verify the key above (updatePubKey) is indeed controlled
39
-by @jbenet, ipfs author, with the PGP signed message below. You
40
-can verify it in the commandline, or keybase.io.
41
-
42
------BEGIN PGP SIGNED MESSAGE-----
43
-Hash: SHA512
44
-
45
-I hereby certify that I control the private key matching the
46
-following public key. This is a key used for go-ipfs auto-updates
47
-over equinox.io. - @jbenet
48
-
49
-- -----BEGIN RSA PUBLIC KEY-----
50
-MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxnwPPE4LNMjTfW/NRz1z
51
-8uAPpwGYSzac+cwZbHbL5xFOxeX301GCdISaMm+Q8OEJqLyXfjYSuRwx00fDzWDD
52
-ajBQOsxO08gTy1i/ow5YdEO+nYeVKO08fQFqVqdTz09BCgzt9iQJTEMeiq1kSWNo
53
-al8usHD4SsNTxwDpSlok5UKWCHcr7D/TWX5A4B5A6ae9HSEcMB4Aum83k63Vzgm1
54
-WTUvK0ed1zd0/KcHqIU36VZpVg4PeV4SWnOBnldQ98CWg/Mnqp3+lXMWYWTmXeX6
55
-xj8JqOGpebzlxeISKE6fDBtrLxUbFTt3DNshl7S5CUGuc5H1MF1FTAyi+8u/nEZB
56
-cQIDAQAB
57
-- -----END RSA PUBLIC KEY-----
58
------BEGIN PGP SIGNATURE-----
59
-Version: Keybase OpenPGP v1.1.3
60
-Comment: https://keybase.io/crypto
61
-
62
-wsFcBAABCgAGBQJUSCX8AAoJEFYC7bhkX9ftBcwQAJuYGSECSKFATJ1wK+zAGUH5
63
-xEbX+yaCYj0PwzJO4Ntu2ifK68ANacKy/GiXdJYeQk7pq21UT0fcn0Uq39URu+Xb
64
-lk3t1YZazjY7wB03jBjcMIaO2TUsWbGIBZAEZjyVDDctDUM0krCd1GIOw6Fbndva
65
-pevlGIA55ewvXYxcWdRyOGWiqd9DKNnmi9UF0XsdpCtDFSkdjnqkqbTRxF6Jw5gI
66
-EAF2E7mU8emDTNgtpCs0ACmEUXVVEEhF9TuR/YdX1m/715TYkkYCii6uV9vSVQd8
67
-nOrDDTrWSjlF6Ms+dYGCheWIjKQcykn9IW021AzVN1P7Mt9qtmDNfZ0VQL3zl/fs
68
-zZ1IHBW7BzriQ4GzWXg5GWpTSz/REvUEfKNVuDV9jX7hv67B5H6qTL5+2zljPEKv
69
-lCas04cCMmEpJUj4qK95hdKQzKJ8b7MrRf/RFYyViRGdxvR+lgGqJ7Yca8es2kCe
70
-XV6c+i6a7X89YL6ZVU+1MlvPwngu0VG+VInH/w9KrNYrLFhfVRiruRbkBkHDXjnU
71
-b4kPqaus+7g0DynCk7A2kTMa3cgtO20CZ9MBJFEPqRRHHksjHVmlxPb42bB348aR
72
-UVsWkRRYOmRML7avTgkX8WFsmdZ1d7E7aQLYnCIel85+5iP7hWyNtEMsAHk02XCL
73
-AAb7RaEDNJOa7qvUFecB
74
-=mzPY
75
------END PGP SIGNATURE-----
76
-
77
-
78
-*/
79
-
80
-)
81
-
82
-var log = logging.Logger("updates")
83
-
84
-var currentVersion *semver.Version
85
-
86
-// ErrNoUpdateAvailable returned when a check fails to find a newer update.
87
-var ErrNoUpdateAvailable = check.NoUpdateAvailable
88
-
89
-func init() {
90
- var err error
91
- currentVersion, err = parseVersion()
92
- if err != nil {
93
- log.Fatalf("invalid version number in code (must be semver): %q", Version)
94
- }
95
- log.Infof("go-ipfs Version: %s", currentVersion)
96
-}
97
-
98
-func parseVersion() (*semver.Version, error) {
99
- return semver.NewVersion(Version)
100
-}
101
-
102
-// CheckForUpdate checks the equinox.io api if there is an update available
103
-// NOTE: if equinox says there is a new update, but the version number IS NOT
104
-// larger, we interpret that as no update (you may have gotten a newer version
105
-// by building it yourself).
106
-func CheckForUpdate() (*check.Result, error) {
107
- param := check.Params{
108
- AppVersion: Version,
109
- AppId: updateAppID,
110
- Channel: "stable",
111
- }
112
-
113
- up, err := update.New().VerifySignatureWithPEM([]byte(updatePubKey))
114
- if err != nil {
115
- return nil, fmt.Errorf("Failed to parse public key: %v", err)
116
- }
117
-
118
- res, err := param.CheckForUpdate(updateEndpointURL, up)
119
- if err != nil {
120
- return res, err
121
- }
122
-
123
- newer, err := versionIsNewer(res.Version)
124
- if err != nil {
125
- return nil, err
126
- }
127
- if !newer {
128
- return nil, ErrNoUpdateAvailable
129
- }
130
- return res, err
131
-}
132
-
133
-// Apply cheks if the running process is able to update itself
134
-// and than updates to the passed release
135
-func Apply(rel *check.Result) error {
136
- if err := update.New().CanUpdate(); err != nil {
137
- return err
138
- }
139
-
140
- if err, errRecover := rel.Update(); err != nil {
141
- err = fmt.Errorf("Update failed: %v\n", err)
142
- if errRecover != nil {
143
- err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover)
144
- }
145
- return err
146
- }
147
-
148
- return nil
149
-}
150
-
151
-// ShouldAutoUpdate decides wether a new version should be applied
152
-// checks against config setting and new version string. returns false in case of error
153
-func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool {
154
- if setting == config.AutoUpdateNever {
155
- return false
156
- }
157
-
158
- nv, err := semver.NewVersion(newVer)
159
- if err != nil {
160
- log.Infof("could not parse version string: %s", err)
161
- return false
162
- }
163
-
164
- n := nv.Slice()
165
- c := currentVersion.Slice()
166
-
167
- switch setting {
168
-
169
- case config.AutoUpdatePatch:
170
- if n[0] < c[0] {
171
- return false
172
- }
173
-
174
- if n[1] < c[1] {
175
- return false
176
- }
177
-
178
- return n[2] > c[2]
179
-
180
- case config.AutoUpdateMinor:
181
- if n[0] != c[0] {
182
- return false
183
- }
184
-
185
- return n[1] > c[1] || (n[1] == c[1] && n[2] > c[2])
186
-
187
- case config.AutoUpdateMajor:
188
- for i := 0; i < 3; i++ {
189
- if n[i] < c[i] {
190
- return false
191
- }
192
- }
193
- return true
194
- }
195
-
196
- return false
197
-}
198
-
199
-// CliCheckForUpdates is the automatic update check from the commandline.
200
-func CliCheckForUpdates(cfg *config.Config, repoPath string) error {
201
-
202
- // if config says not to, don't check for updates
203
- if !cfg.Version.ShouldCheckForUpdate() {
204
- log.Info("update check skipped.")
205
- return nil
206
- }
207
-
208
- log.Info("checking for update")
209
- u, err := CheckForUpdate()
210
- // if there is no update available, record it, and exit. NB: only record
211
- // if we checked successfully.
212
- if err == ErrNoUpdateAvailable {
213
- log.Infof("No update available, checked on %s", time.Now())
214
- r, err := fsrepo.Open(repoPath)
215
- if err != nil {
216
- return err
217
- }
218
- if err := recordUpdateCheck(cfg); err != nil {
219
- return err
220
- }
221
- // NB: r's Config may be newer than cfg. This overwrites regardless.
222
- r.SetConfig(cfg)
223
- if err := r.Close(); err != nil {
224
- return err
225
- }
226
- return nil
227
- }
228
-
229
- // if another, unexpected error occurred, note it.
230
- if err != nil {
231
- log.Debugf("Error while checking for update: %v", err)
232
- return nil
233
- }
234
-
235
- // there is an update available
236
-
237
- // if we autoupdate
238
- if cfg.Version.AutoUpdate != config.AutoUpdateNever {
239
- // and we should auto update
240
- if ShouldAutoUpdate(cfg.Version.AutoUpdate, u.Version) {
241
- log.Infof("Applying update %s", u.Version)
242
-
243
- if err = Apply(u); err != nil {
244
- log.Debug(err)
245
- return nil
246
- }
247
-
248
- // BUG(cryptix): no good way to restart yet. - tracking https://github.com/inconshreveable/go-update/issues/5
249
- fmt.Printf("update %v applied. please restart.\n", u.Version)
250
- os.Exit(0)
251
- }
252
- }
253
-
254
- // autoupdate did not exit, so regular notices.
255
- switch cfg.Version.Check {
256
- case config.CheckError:
257
- return fmt.Errorf(errShouldUpdate, Version, u.Version)
258
- case config.CheckWarn:
259
- // print the warning
260
- fmt.Printf("New version available: %s\n", u.Version)
261
- default: // ignore
262
- }
263
- return nil
264
-}
265
-
266
-func versionIsNewer(version string) (bool, error) {
267
- nv, err := semver.NewVersion(version)
268
- if err != nil {
269
- return false, fmt.Errorf("could not parse version string: %s", err)
270
- }
271
-
272
- cv := currentVersion
273
- newer := !nv.LessThan(*cv) && nv.String() != cv.String()
274
- return newer, nil
275
-}
276
-
277
-var errShouldUpdate = `
278
-Your go-ipfs version is: %s
279
-There is a new version available: %s
280
-Since this is alpha software, it is strongly recommended you update.
281
-
282
-To update, run:
283
-
284
- ipfs update apply
285
-
286
-To disable this notice, run:
287
-
288
- ipfs config Version.Check warn
289
-
290
-`
291
-
292
-// recordUpdateCheck is called to record that an update check was performed,
293
-// showing that the running version is the most recent one.
294
-func recordUpdateCheck(cfg *config.Config) error {
295
- cfg.Version.CheckDate = time.Now()
296
-
297
- if cfg.Version.CheckPeriod == "" {
298
- // CheckPeriod was not initialized for some reason (e.g. config file broken)
299
- return errors.New("config.Version.CheckPeriod not set. config broken?")
300
- }
301
- return nil
302
-}
updates/updates_test.go
deleted
-60
@@ -1,60 +0,0 @@
1
-package updates
2
-
3
-import (
4
- "testing"
5
-
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
7
- "github.com/ipfs/go-ipfs/repo/config"
8
-)
9
-
10
-// TestParseVersion just makes sure that we dont commit a bad version number
11
-func TestParseVersion(t *testing.T) {
12
- _, err := parseVersion()
13
- if err != nil {
14
- t.Fatal(err)
15
- }
16
-}
17
-
18
-func TestShouldAutoUpdate(t *testing.T) {
19
- tests := []struct {
20
- setting config.AutoUpdateSetting
21
- currV, newV string
22
- should bool
23
- }{
24
- {config.AutoUpdateNever, "0.0.1", "1.0.0", false},
25
- {config.AutoUpdateNever, "0.0.1", "0.1.0", false},
26
- {config.AutoUpdateNever, "0.0.1", "0.0.1", false},
27
- {config.AutoUpdateNever, "0.0.1", "0.0.2", false},
28
-
29
- {config.AutoUpdatePatch, "0.0.1", "1.0.0", false},
30
- {config.AutoUpdatePatch, "0.0.1", "0.1.0", false},
31
- {config.AutoUpdatePatch, "0.0.1", "0.0.1", false},
32
- {config.AutoUpdatePatch, "0.0.2", "0.0.1", false},
33
- {config.AutoUpdatePatch, "0.0.1", "0.0.2", true},
34
-
35
- {config.AutoUpdateMinor, "0.1.1", "1.0.0", false},
36
- {config.AutoUpdateMinor, "0.1.1", "0.2.0", true},
37
- {config.AutoUpdateMinor, "0.1.1", "0.1.2", true},
38
- {config.AutoUpdateMinor, "0.2.1", "0.1.9", false},
39
- {config.AutoUpdateMinor, "0.1.2", "0.1.1", false},
40
-
41
- {config.AutoUpdateMajor, "1.0.0", "2.0.0", true},
42
- {config.AutoUpdateMajor, "1.0.0", "1.1.0", true},
43
- {config.AutoUpdateMajor, "1.0.0", "1.0.1", true},
44
- {config.AutoUpdateMajor, "2.0.0", "1.0.0", false}, // don't downgrade
45
- {config.AutoUpdateMajor, "2.5.0", "2.4.0", false},
46
- {config.AutoUpdateMajor, "2.0.2", "2.0.1", false},
47
- }
48
-
49
- for i, tc := range tests {
50
- var err error
51
- currentVersion, err = semver.NewVersion(tc.currV)
52
- if err != nil {
53
- t.Fatalf("Could not parse test version: %v", err)
54
- }
55
-
56
- if tc.should != ShouldAutoUpdate(tc.setting, tc.newV) {
57
- t.Fatalf("#%d failed for %+v", i, tc)
58
- }
59
- }
60
-}