Exemple #1
0
func upgradeCommand(args []string) {
	fs := flag.NewFlagSet("upgrade", flag.ExitOnError)
	force := fs.Bool("force", false, "Perform upgrade to same or older version")
	disableAuto := fs.Bool("disable-auto", false, "Disable automatic upgrades")
	enableAuto := fs.Bool("enable-auto", false, "Enable automatic upgrades")
	fs.Usage = usageFor(fs, msgUpgradeUsage)
	fs.Parse(args)
	args = fs.Args()

	if *disableAuto || *enableAuto {
		upgrades := "yes"
		if *disableAuto {
			upgrades = "no"
		}
		moleIni.Set("upgrades", "automatic", upgrades)
		saveMoleIni()
		okf("Automatic upgrades set to %q", upgrades)
		return
	}

	build, err := latestBuild()
	fatalErr(err)

	bd := time.Unix(int64(build.BuildStamp), 0)
	isNewer := bd.Sub(buildDate).Seconds() > 0
	if *force || isNewer {
		infoln(msgDownloadingUpgrade)

		err = upgrade.UpgradeTo(build)
		fatalErr(err)
		okf(msgUpgraded, build.Version)
	} else {
		okln(msgLatest)
	}
}
Exemple #2
0
func autoUpgrade() {
	if moleIni.Get("upgrades", "automatic") == "no" {
		debugln("automatic upgrades disabled")
		return
	}

	// Only do the actual upgrade once we've been running for a while
	time.Sleep(10 * time.Second)
	build, err := latestBuild()
	if err == nil {
		bd := time.Unix(int64(build.BuildStamp), 0)
		if isNewer := bd.Sub(buildDate).Seconds() > 0; isNewer {
			err = upgrade.UpgradeTo(build)
			if err == nil {
				if moleIni.Get("upgrades", "automatic") != "yes" {
					infoln(msgAutoUpgrades)
				}
				okf(msgUpgraded, build.Version)
			} else {
				warnln("Automatic upgrade failed:", err)
			}
		}
	}
}