Esempio n. 1
0
func init() {
	var err error
	u, err = update.New().VerifySignatureWithPEM(publicKey)
	if err != nil {
		panic(err)
	}
}
Esempio n. 2
0
func autoUpdate(s mvc.State, token string) {
	up, err := update.New().VerifySignatureWithPEM([]byte(publicKey))
	if err != nil {
		log.Error("Failed to create update with signature: %v", err)
		return
	}

	update := func() (tryAgain bool) {
		log.Info("Checking for update")
		params := check.Params{
			AppId:      appId,
			AppVersion: version.MajorMinor(),
			UserId:     token,
		}

		result, err := params.CheckForUpdate(updateEndpoint, up)
		if err == check.NoUpdateAvailable {
			log.Info("No update available")
			return true
		} else if err != nil {
			log.Error("Error while checking for update: %v", err)
			return true
		}

		if result.Initiative == check.INITIATIVE_AUTO {
			if err := up.CanUpdate(); err != nil {
				log.Error("Can't update: insufficient permissions: %v", err)
				// tell the user to update manually
				s.SetUpdateStatus(mvc.UpdateAvailable)
			} else {
				applyUpdate(s, result)
			}
		} else if result.Initiative == check.INITIATIVE_MANUAL {
			// this is the way the server tells us to update manually
			log.Info("Server wants us to update manually")
			s.SetUpdateStatus(mvc.UpdateAvailable)
		} else {
			log.Info("Update available, but ignoring")
		}

		// stop trying after a single download attempt
		// XXX: improve this so the we can:
		// 1. safely update multiple times
		// 2. only retry after temporary errors
		return false
	}

	// try to update immediately and then at a set interval
	for {
		if tryAgain := update(); !tryAgain {
			break
		}

		time.Sleep(updateCheckInterval)
	}
}
Esempio n. 3
0
func (updater *Updater) updateTo(releaseName, version string) (err error) {
	ui.Printf("Updating gh to %s...\n", version)
	downloadURL := fmt.Sprintf("https://%s/github/hub/releases/download/%s/hub%s_%s_%s.zip", updater.Host, releaseName, version, runtime.GOOS, runtime.GOARCH)
	path, err := downloadFile(downloadURL)
	if err != nil {
		return
	}

	exec, err := unzipExecutable(path)
	if err != nil {
		return
	}

	err, _ = goupdate.New().FromFile(exec)
	if err == nil {
		ui.Println("Done!")
	}

	return
}
Esempio n. 4
0
func UpdateInit(mod *modules.Module) {
	owner := &modules.OwnerPermission{}
	mod.AddResponse(updatereg, func(r *modules.Response) {

		r.Respond("okey, " + r.Nick + "!")

		err, errRecover := update.New().FromUrl(mod.GetConfig().UpdateUrl)
		if err != nil {
			r.Respondf("Update failed: %v", err)
			if errRecover != nil {
				log.Errorf("Failed to recover bad update: %v!", errRecover)
				log.Fatalf("Program exectuable may be missing!")
			}
			return
		}

		log.Info("Update done!")
		r.Respond("update done!")

		//restart
		syscall.Kill(syscall.Getpid(), syscall.SIGUSR2)
	}, owner)
}