github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/core/commands/update.go (about) 1 package commands 2 3 import ( 4 "errors" 5 "fmt" 6 "io" 7 "os" 8 9 "github.com/jbenet/go-ipfs/core" 10 "github.com/jbenet/go-ipfs/updates" 11 ) 12 13 // UpdateApply applys an update of the ipfs binary and shuts down the node if successful 14 func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { 15 fmt.Fprintln(out, "Current Version:", updates.Version) 16 u, err := updates.CheckForUpdate() 17 if err != nil { 18 return err 19 } 20 21 if u == nil { 22 fmt.Fprintln(out, "No update available") 23 return nil 24 } 25 fmt.Fprintln(out, "New Version:", u.Version) 26 27 _, onDaemon := opts["onDaemon"] 28 force := opts["force"].(bool) 29 if onDaemon && !force { 30 return fmt.Errorf(`Error: update must stop running ipfs service. 31 You may want to abort the update, or shut the service down manually. 32 To shut it down automatically, run: 33 34 ipfs update --force 35 `) 36 } 37 38 if err = updates.Apply(u); err != nil { 39 fmt.Fprint(out, err.Error()) 40 return fmt.Errorf("Couldn't apply update: %v", err) 41 } 42 43 fmt.Fprintln(out, "Updated applied!") 44 if onDaemon { 45 if force { 46 fmt.Fprintln(out, "Shutting down ipfs service.") 47 os.Exit(1) // is there a cleaner shutdown routine? 48 } else { 49 fmt.Fprintln(out, "You can now restart the ipfs service.") 50 } 51 } 52 53 return nil 54 } 55 56 // UpdateCheck checks wether there is an update available 57 func UpdateCheck(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { 58 fmt.Fprintln(out, "Current Version:", updates.Version) 59 u, err := updates.CheckForUpdate() 60 if err != nil { 61 return err 62 } 63 64 if u == nil { 65 fmt.Fprintln(out, "No update available") 66 return nil 67 } 68 69 fmt.Fprintln(out, "New Version:", u.Version) 70 return nil 71 } 72 73 // UpdateLog lists the version available online 74 func UpdateLog(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { 75 return errors.New("Not yet implemented") 76 }