Example #1
0
func (i *Install) Run() error {
	defer i.RevertOnFailure()

	var err error
	i.CurrentVers, err = GetCurrentVersion()
	if err != nil {
		return err
	}

	if i.CurrentVers == "none" {
		stump.VLog("no pre-existing ipfs installation found")
	} else if i.CurrentVers == i.TargetVers {
		stump.Log("Already have version %s installed, skipping.", i.TargetVers)
		i.Succeeded = true
		return nil
	}

	err = i.DownloadNewBinary()
	if err != nil {
		return err
	}

	if !i.NoCheck {
		stump.Log("binary downloaded, verifying...")
		err = test.TestBinary(i.TmpBinPath, i.TargetVers)
		if err != nil {
			return err
		}
	} else {
		stump.Log("skipping tests since '--no-check' was passed")
	}

	err = i.MaybeStash()
	if err != nil {
		return err
	}

	err = i.SelectGoodInstallLoc()
	if err != nil {
		return err
	}

	stump.Log("installing new binary to %s", i.InstallPath)
	err = InstallBinaryTo(i.TmpBinPath, i.InstallPath)
	if err != nil {
		// in case of error here, replace old binary
		stump.Error("Install failed: ", err)

		return err
	}

	err = i.postInstallMigrationCheck()
	if err != nil {
		stump.Error("Migration Failed: ", err)
		return err
	}

	i.Succeeded = true
	return nil
}
Example #2
0
func testRefsList(tdir, bin string) error {
	stump.VLog("  - checking that file shows up in ipfs refs local")
	c := exec.Command(bin, "refs", "local")
	c.Env = []string{"IPFS_PATH=" + tdir}
	out, err := c.CombinedOutput()
	if err != nil {
		stump.Error("testfileadd fail: %s", err)
		stump.Error(string(out))
		return err
	}

	hashes := strings.Split(string(out), "\n")
	exp := "QmTFJQ68kaArzsqz2Yjg1yMyEA5TXTfNw6d9wSFhxtBxz2"
	var found bool
	for _, h := range hashes {
		if h == exp {
			found = true
			break
		}
	}
	if !found {
		return fmt.Errorf("expected to see %s in the local refs!", exp)
	}

	return nil
}
Example #3
0
func testFileAdd(tdir, bin string) error {
	stump.VLog("  - checking that we can add and cat a file")
	text := "hello world! This node should work"
	data := bytes.NewBufferString(text)
	c := exec.Command(bin, "add", "-q", "--progress=false")
	c.Env = []string{"IPFS_PATH=" + tdir}
	c.Stdin = data
	out, err := c.CombinedOutput()
	if err != nil {
		stump.Error("testfileadd fail: %s", err)
		stump.Error(string(out))
		return err
	}

	hash := strings.Trim(string(out), "\n \t\r")
	fiout, err := runCmd(tdir, bin, "cat", hash)
	if err != nil {
		return err
	}

	if fiout != text {
		return fmt.Errorf("add/cat check failed")
	}

	return nil
}
Example #4
0
func GetMigrations() (string, error) {
	latest, err := GetLatestVersion(util.IpfsVersionPath, migrations)
	if err != nil {
		return "", fmt.Errorf("getting latest version of fs-repo-migrations: %s", err)
	}

	dir, err := ioutil.TempDir("", "ipfs-update-migrate")
	if err != nil {
		return "", fmt.Errorf("tempdir: %s", err)
	}

	out := filepath.Join(dir, migrations)

	err = GetBinaryForVersion(migrations, migrations, util.IpfsVersionPath, latest, out)
	if err != nil {
		stump.Error("getting migrations binary: %s", err)

		stump.Log("could not find or install fs-repo-migrations, please manually install it")
		stump.Log("before running ipfs-update again.")
		return "", fmt.Errorf("failed to find migrations binary")
	}

	err = os.Chmod(out, 0755)
	if err != nil {
		return "", err
	}

	return out, nil
}
Example #5
0
func (d *daemon) Close() error {
	err := d.p.Kill()
	if err != nil {
		stump.Error("error killing daemon: %s", err)
		return err
	}

	_, err = d.p.Wait()
	if err != nil {
		stump.Error("error waiting on killed daemon: %s", err)
		return err
	}

	d.stderr.Close()
	d.stdout.Close()
	return nil
}
Example #6
0
func httpFetch(url string) (io.ReadCloser, error) {
	stump.VLog("fetching url: %s", url)
	resp, err := httpGet(url)
	if err != nil {
		return nil, err
	}

	if resp.StatusCode >= 400 {
		stump.Error("fetching resource: %s", resp.Status)
		mes, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			return nil, fmt.Errorf("error reading error body: %s", err)
		}

		return nil, fmt.Errorf("%s: %s", resp.Status, string(mes))
	}

	return newLimitReadCloser(resp.Body, fetchSizeLimit), nil
}
Example #7
0
func TestBinary(bin, version string) error {
	_, err := os.Stat(bin)
	if err != nil {
		return err
	}

	// make sure binary is executable
	err = os.Chmod(bin, 0755)
	if err != nil {
		return err
	}

	staging := filepath.Join(util.IpfsDir(), "update-staging")
	err = os.MkdirAll(staging, 0755)
	if err != nil {
		return fmt.Errorf("error creating test staging directory: %s", err)
	}

	tdir, err := ioutil.TempDir(staging, "test")
	if err != nil {
		return err
	}

	err = os.MkdirAll(tdir, 0755)
	if err != nil {
		return fmt.Errorf("error creating test staging directory: %s", err)
	}

	defer func(dir string) {
		// defer cleanup, bound param to avoid mistakes
		err = os.RemoveAll(dir)
		if err != nil {
			stump.Error("error cleaning up staging directory: ", err)
		}
	}(tdir)

	stump.VLog("  - running init in '%s' with new binary", tdir)
	_, err = runCmd(tdir, bin, "init")
	if err != nil {
		return fmt.Errorf("error initializing with new binary: %s", err)
	}

	stump.VLog("  - checking new binary outputs correct version")
	rversion, err := runCmd(tdir, bin, "version")
	if err != nil {
		return err
	}

	parts := strings.Fields(rversion)
	if !versionMatch(parts[len(parts)-1], version[1:]) {
		return fmt.Errorf("version didnt match")
	}

	if util.BeforeVersion("v0.3.8", version) {
		stump.Log("== skipping tests with daemon, versions before 0.3.8 do not support port zero ==")
		return nil
	}

	// set up ports in config so we dont interfere with an already running daemon
	stump.VLog("  - tweaking test config to avoid external interference")
	err = tweakConfig(tdir)
	if err != nil {
		return err
	}

	stump.VLog("  - starting up daemon")
	daemon, err := StartDaemon(tdir, bin)
	if err != nil {
		return fmt.Errorf("error starting daemon: %s", err)
	}
	defer func() {
		stump.VLog("  - killing test daemon")
		err := daemon.Close()
		if err != nil {
			stump.VLog("  - error killing test daemon: %s (continuing anyway)", err)
		}
		stump.Log("success!")
	}()

	// test some basic things against the daemon
	err = testFileAdd(tdir, bin)
	if err != nil {
		return fmt.Errorf("test file add: %s", err)
	}

	err = testRefsList(tdir, bin)
	if err != nil {
		return fmt.Errorf("test refs list: %s", err)
	}

	return nil
}
Example #8
0
	Action: func(c *cli.Context) error {
		oldbinpath, err := selectRevertBin()
		if err != nil {
			return err
		}

		stump.Log("Reverting to %s.", oldbinpath)
		oldpath, err := ioutil.ReadFile(filepath.Join(util.IpfsDir(), "old-bin", "path-old"))
		if err != nil {
			stump.Fatal("path for previous installation could not be read: ", err)
		}

		binpath := string(oldpath)
		err = InstallBinaryTo(oldbinpath, binpath)
		if err != nil {
			stump.Error("failed to move old binary: %s", oldbinpath)
			stump.Error("to path: %s", binpath)
			stump.Fatal(err)
		}
		stump.Log("\nRevert complete.")
		return nil
	},
}

var cmdFetch = cli.Command{
	Name:      "fetch",
	Usage:     "Fetch a given version of ipfs. Default: latest.",
	ArgsUsage: "<version>",
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "output",