Ejemplo n.º 1
0
func UpdateEris(branch string, checkGit bool, checkGo bool) {

	//check that git/go are installed
	hasGit, hasGo := CheckGitAndGo(checkGit, checkGo)
	if hasGo == false {
		log.Println("Go is not installed. Downloading eris-cli binary...")
		_, err := downloadLatestRelease()
		if err != nil {
			log.Println("Latest binary failed to download with error:", err)
			log.Println("Exiting...")
			os.Exit(1)
		}
	} else if hasGit == false {
		log.Println("Git is not installed. Please install git before continuing.")
		log.Println("Exiting...")
		os.Exit(1)
	}

	//checks for deprecated dir names and renames them
	err := MigrateDeprecatedDirs(common.DirsToMigrate, false) // false = no prompt
	if err != nil {
		log.Warnf("Directory migration error: %v", err)
		log.Warn("Continuing with update without migration")
	}

	//change pwd to eris/cli
	ChangeDirectory("src")

	if branch == "" {
		branch = "master"
	}

	CheckoutBranch(branch)
	PullBranch(branch)

	InstallEris()
	ver := version() //because version.Version will be in RAM.

	log.WithField("=>", ver).Warn("The marmots have updated Eris successfully")
}
Ejemplo n.º 2
0
func downloadLatestRelease() (string, error) {
	latestURL := "https://github.com/eris-ltd/eris-cli/releases/latest"
	resp, err := http.Get(latestURL)
	if err != nil {
		log.Printf("could not retrieve latest eris release at %s", latestURL)
	}
	latestURL = resp.Request.URL.String()
	lastPos := strings.LastIndex(latestURL, "/")
	version := latestURL[lastPos+1:]
	platform := runtime.GOOS
	arch := runtime.GOARCH
	hostURL := "https://github.com/eris-ltd/eris-cli/releases/download/" + version + "/"
	filename := "eris_" + version[1:] + "_" + platform + "_" + arch
	fileURL := hostURL + filename
	switch platform {
	case "linux":
		filename += ".tar.gz"
	default:
		filename += ".zip"
	}

	ChangeDirectory("bin")
	var erisBin string
	output, err := os.Create(filename)
	// if we dont have permissions to create a file where eris cli exists, attempt to create file within HOME folder
	if err != nil {
		erisBin := filepath.Join(common.ScratchPath, "bin")
		if _, err = os.Stat(erisBin); os.IsNotExist(err) {
			err = os.MkdirAll(erisBin, 0755)
			if err != nil {
				log.Println("Error creating directory", erisBin, "Did not download binary. Exiting...")
				return "", err
			}
		}
		err = os.Chdir(erisBin)
		if err != nil {
			log.Println("Error changing directory to", erisBin, "Did not download binary. Exiting...")
			return "", err
		}
		output, err = os.Create(filename)
		if err != nil {
			log.Println("Error creating file", erisBin, "Exiting...")
			return "", err
		}
	}
	defer output.Close()
	fileResponse, err := http.Get(fileURL)
	if err != nil {
		log.Println("Error while downloading", filename, "-", err)
		return "", err
	}
	defer fileResponse.Body.Close()
	io.Copy(output, fileResponse.Body)
	if err != nil {
		log.Println("Error saving downloaded file", filename, "-", err)
		return "", err
	}
	erisLoc, _ := exec.LookPath("eris")
	if erisBin != "" {
		log.Println("downloaded eris binary", version, "for", platform, "to", erisBin, "\n Please manually move to", erisLoc)
	} else {
		log.Println("downloaded eris binary", version, "for", platform, "to", erisLoc)
	}
	var unzip string = "tar -xvf"
	if platform != "linux" {
		unzip = "unzip"
	}
	cmd := exec.Command("bin/sh", "-c", unzip, filename)
	err = cmd.Run()
	if err != nil {
		log.Println("unzipping", filename, "failed:", err)
	}
	return filename, nil
}