Example #1
0
func (s *SnapTestSuite) buildFramework(c *C) string {
	allSystemctl := []string{}
	systemd.SystemctlCmd = func(cmd ...string) ([]byte, error) {
		allSystemctl = append(allSystemctl, cmd[0])
		return nil, nil
	}

	tmpdir := c.MkDir()
	appg := filepath.Join(tmpdir, "meta", "framework-policy", "apparmor", "policygroups")
	c.Assert(os.MkdirAll(appg, 0755), IsNil)
	c.Assert(ioutil.WriteFile(filepath.Join(appg, "one"), []byte("hello"), 0644), IsNil)

	yaml := []byte(`name: hello
version: 1.0.1
type: framework
`)

	yamlFile := filepath.Join(tmpdir, "meta", "package.yaml")
	c.Assert(ioutil.WriteFile(yamlFile, yaml, 0644), IsNil)
	readmeMd := filepath.Join(tmpdir, "meta", "readme.md")
	c.Assert(ioutil.WriteFile(readmeMd, []byte("blah\nx"), 0644), IsNil)
	m, err := parsePackageYamlData(yaml, false)
	c.Assert(err, IsNil)
	snapName := fmt.Sprintf("%s_%s_all.snap", m.Name, m.Version)
	d := squashfs.New(snapName)
	c.Assert(d.Build(tmpdir), IsNil)
	defer os.Remove(snapName)

	_, err = installClick(snapName, 0, nil, testOrigin)
	c.Assert(err, IsNil)

	return snapName
}
Example #2
0
func (x *snapBuild) Execute(args []string) error {
	authID := x.Positional.AuthorityID
	if authID == "" {
		return fmt.Errorf("missing devel/authority-id")
	}
	authKey, err := findPublicKey(db, authID)
	if err != nil {
		return err
	}

	snapFile := x.Positional.SnapFile
	if snapFile == "" {
		return fmt.Errorf("missing snap-file")
	}
	snap := squashfs.New(snapFile)
	nameParts := strings.SplitN(snap.Name(), "_", 2)
	snapID := nameParts[0] // XXX: cheat/guess
	size, hashDigest, err := snap.HashDigest(crypto.SHA256)
	if err != nil {
		return fmt.Errorf("failed to hash snap: %v", err)
	}
	formattedDigest, err := asserts.EncodeDigest(crypto.SHA256, hashDigest)
	if err != nil {
		return err
	}

	now := time.Now().UTC()
	headers := map[string]string{
		"authority-id": strings.Split(authID, "/")[0],
		"snap-id":      snapID,
		"snap-digest":  formattedDigest,
		"snap-size":    fmt.Sprintf("%d", size),
		"grade":        "devel",
		"timestamp":    now.Format(time.RFC3339),
	}
	snapDecl, err := db.Sign(asserts.SnapBuildType, headers, nil, authKey.ID())
	if err != nil {
		return err
	}
	os.Stdout.Write(asserts.Encode(snapDecl))
	return nil
}
Example #3
0
// BuildSquashfsSnap the given sourceDirectory and return the generated
// snap file
func BuildSquashfsSnap(sourceDir, targetDir string) (string, error) {
	// create build dir
	buildDir, err := ioutil.TempDir("", "snappy-build-")
	if err != nil {
		return "", err
	}
	defer os.RemoveAll(buildDir)

	snapName, err := prepare(sourceDir, targetDir, buildDir)
	if err != nil {
		return "", err
	}

	d := squashfs.New(snapName)
	if err = d.Build(buildDir); err != nil {
		return "", err
	}

	return snapName, nil
}
Example #4
0
func (s *SnapTestSuite) TestInstallChecksForClashes(c *C) {
	// creating the thing by hand (as build refuses to)...
	tmpdir := c.MkDir()
	os.MkdirAll(filepath.Join(tmpdir, "meta"), 0755)
	yaml := []byte(`name: hello
version: 1.0.1
services:
 - name: foo
binaries:
 - name: foo
`)
	yamlFile := filepath.Join(tmpdir, "meta", "package.yaml")
	c.Assert(ioutil.WriteFile(yamlFile, yaml, 0644), IsNil)
	readmeMd := filepath.Join(tmpdir, "meta", "readme.md")
	c.Assert(ioutil.WriteFile(readmeMd, []byte("blah\nx"), 0644), IsNil)
	m, err := parsePackageYamlData(yaml, false)
	c.Assert(err, IsNil)
	snapName := fmt.Sprintf("%s_%s_all.snap", m.Name, m.Version)
	d := squashfs.New(snapName)
	c.Assert(d.Build(tmpdir), IsNil)

	_, err = installClick(snapName, 0, nil, testOrigin)
	c.Assert(err, ErrorMatches, ".*binary and service both called foo.*")
}