Esempio n. 1
0
// CheckForUpdate checks the equinox.io api if there is an update available
// NOTE: if equinox says there is a new update, but the version number IS NOT
// larger, we interpret that as no update (you may have gotten a newer version
// by building it yourself).
func CheckForUpdate() (*check.Result, error) {
	param := check.Params{
		AppVersion: Version,
		AppId:      updateAppID,
		Channel:    "stable",
	}

	up, err := update.New().VerifySignatureWithPEM([]byte(updatePubKey))
	if err != nil {
		return nil, fmt.Errorf("Failed to parse public key: %v", err)
	}

	res, err := param.CheckForUpdate(updateEndpointURL, up)
	if err != nil {
		return res, err
	}

	newer, err := versionIsNewer(res.Version)
	if err != nil {
		return nil, err
	}
	if !newer {
		return nil, ErrNoUpdateAvailable
	}
	return res, err
}
Esempio n. 2
0
// Apply cheks if the running process is able to update itself
// and than updates to the passed release
func Apply(rel *check.Result) error {
	if err := update.New().CanUpdate(); err != nil {
		return err
	}

	if err, errRecover := rel.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)
		}
		return err
	}

	return nil
}