1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

implemented manual check and update (with signature verification)

This commit is contained in:
Henry
2014-10-20 15:33:46 +02:00
parent 5fa3053e19
commit 7ddf3836d0
4 changed files with 79 additions and 9 deletions

6
cmd/ipfs/equinox.yaml Normal file
View File

@ -0,0 +1,6 @@
---
equinox-account: CHANGEME
equinox-secret: CHANGEME
equinox-app: CHANGEME
channel: stable
private-key: equinox-priv

View File

@ -2,21 +2,64 @@ package commands
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"os"
"github.com/jbenet/go-ipfs/core" "github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/updates"
) )
// UpdateApply applys an update of the ipfs binary and shuts down the node if successful // UpdateApply applys an update of the ipfs binary and shuts down the node if successful
func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
return errors.New("TODOUpdateApply") fmt.Fprintln(out, "Current Version:", updates.Version)
u, err := updates.CheckForUpdate()
if err != nil {
return err
}
if u == nil {
fmt.Fprintln(out, "No update available")
return nil
}
fmt.Fprintln(out, "New Version:", u.Version)
if err = updates.AbleToApply(); err != nil {
return fmt.Errorf("Can't apply update: %v", err)
}
if err, errRecover := u.Update(); err != nil {
err = fmt.Errorf("Update failed: %v\n", err)
if errRecover != nil {
err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover)
}
fmt.Fprint(out, err.Error())
return err
}
fmt.Fprintln(out, "Updated applied! Shutting down.")
os.Exit(0)
return nil
} }
// UpdateCheck checks wether there is an update available // UpdateCheck checks wether there is an update available
func UpdateCheck(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { func UpdateCheck(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
return errors.New("TODOUpdateCheck") fmt.Fprintln(out, "Current Version:", updates.Version)
u, err := updates.CheckForUpdate()
if err != nil {
return err
}
if u == nil {
fmt.Fprintln(out, "No update available")
return nil
}
fmt.Fprintln(out, "New Version:", u.Version)
return nil
} }
// UpdateLog lists the version available online
func UpdateLog(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { func UpdateLog(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
return errors.New("TODOUpdateLog") return errors.New("Not yet implemented")
} }

View File

@ -141,6 +141,8 @@ func (dl *DaemonListener) handleConnection(conn manet.Conn) {
err = commands.Log(dl.node, command.Args, command.Opts, conn) err = commands.Log(dl.node, command.Args, command.Opts, conn)
case "unpin": case "unpin":
err = commands.Unpin(dl.node, command.Args, command.Opts, conn) err = commands.Unpin(dl.node, command.Args, command.Opts, conn)
case "updateApply":
err = commands.UpdateApply(dl.node, command.Args, command.Opts, conn)
default: default:
err = fmt.Errorf("Invalid Command: '%s'", command.Command) err = fmt.Errorf("Invalid Command: '%s'", command.Command)
} }

View File

@ -1,18 +1,26 @@
package updates package updates
import ( import (
"fmt"
"os" "os"
u "github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver" "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update" "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update/check" "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update/check"
u "github.com/jbenet/go-ipfs/util"
) )
const ( const (
Version = "0.1.0" // actual current application's version literal // Version is the current application's version literal
UpdateEndpointURL = "https://api.equinox.io/1/Updates" Version = "0.1.1"
UpdateAppID = "ap_ywkPmAR40q4EfdikN9Jh2hgIHi"
updateEndpointURL = "https://api.equinox.io/1/Updates"
updateAppID = "CHANGEME"
updatePubKey = `-----BEGIN RSA PUBLIC KEY-----
CHANGEME
-----END RSA PUBLIC KEY-----`
) )
var log = u.Logger("updates") var log = u.Logger("updates")
@ -32,12 +40,23 @@ func parseVersion() (*semver.Version, error) {
return semver.NewVersion(Version) return semver.NewVersion(Version)
} }
// CheckForUpdate checks the equinox.io api if there is an update available
func CheckForUpdate() (*check.Result, error) { func CheckForUpdate() (*check.Result, error) {
param := check.Params{ param := check.Params{
AppVersion: Version, AppVersion: Version,
AppId: UpdateAppID, AppId: updateAppID,
Channel: "stable", Channel: "stable",
} }
return param.CheckForUpdate(UpdateEndpointURL, update.New()) up, err := update.New().VerifySignatureWithPEM([]byte(updatePubKey))
if err != nil {
return nil, fmt.Errorf("Failed to parse public key: %v", err)
}
return param.CheckForUpdate(updateEndpointURL, up)
}
// AbleToApply cheks if the running process is able to update itself
func AbleToApply() error {
return update.New().CanUpdate()
} }