Ejemplo n.º 1
0
func (s *SquashfsTestSuite) TestInstallKernelSnapUnpacksKernel(c *C) {
	files := [][]string{
		{"vmlinuz-4.2", "I'm a kernel"},
		{"initrd.img-4.2", "...and I'm an initrd"},
	}
	snapPkg := makeTestSnapPackageWithFiles(c, packageKernel, files)
	part, err := NewSnapPartFromSnapFile(snapPkg, "origin", true)
	c.Assert(err, IsNil)

	_, err = part.Install(&MockProgressMeter{}, 0)
	c.Assert(err, IsNil)

	// this is where the kernel/initrd is unpacked
	bootdir := partition.BootloaderDir()

	// kernel is here and normalized
	vmlinuz := filepath.Join(bootdir, "ubuntu-kernel.origin_4.0-1.snap", "vmlinuz")
	content, err := ioutil.ReadFile(vmlinuz)
	c.Assert(err, IsNil)
	c.Assert(string(content), Equals, files[0][1])

	// and so is initrd
	initrd := filepath.Join(bootdir, "ubuntu-kernel.origin_4.0-1.snap", "initrd.img")
	content, err = ioutil.ReadFile(initrd)
	c.Assert(err, IsNil)
	c.Assert(string(content), Equals, files[1][1])
}
Ejemplo n.º 2
0
func doInstall(name string, flags InstallFlags, meter progress.Meter) (snapName string, err error) {
	defer func() {
		if err != nil {
			err = &ErrInstallFailed{Snap: name, OrigErr: err}
		}
	}()

	// consume local parts
	if fi, err := os.Stat(name); err == nil && fi.Mode().IsRegular() {
		// we allow unauthenticated package when in developer
		// mode
		//
		// FIXME: this is terrible, we really need a single
		//        bootloader dir like /boot or /boot/loader
		//        instead of having to query the partition code
		if provisioning.InDeveloperMode(partition.BootloaderDir()) {
			flags |= AllowUnauthenticated
		}

		return installClick(name, flags, meter, SideloadedOrigin)
	}

	// check repos next
	mStore := NewMetaStoreRepository()
	installed, err := NewMetaLocalRepository().Installed()
	if err != nil {
		return "", err
	}

	origin := ""
	idx := strings.IndexRune(name, '.')
	if idx > -1 {
		origin = name[idx+1:]
		name = name[:idx]
	}

	found, err := mStore.Details(name, origin)
	if err != nil {
		return "", err
	}

	for _, part := range found {
		cur := FindSnapsByNameAndVersion(QualifiedName(part), part.Version(), installed)
		if len(cur) != 0 {
			return "", ErrAlreadyInstalled
		}
		if PackageNameActive(part.Name()) {
			return "", ErrPackageNameAlreadyInstalled
		}

		// TODO block oem snaps here once the store supports package types

		return part.Install(meter, flags)
	}

	return "", ErrPackageNotFound
}
Ejemplo n.º 3
0
// removeKernelAssets removes the unpacked kernel/initrd for the given
// kernel snap
func removeKernelAssets(s *SnapPart, inter interacter) error {
	if s.m.Type != pkg.TypeKernel {
		return fmt.Errorf("can not remove kernel assets from snap type %q", s.Type())
	}

	// remove the kernel blob
	blobName := filepath.Base(squashfs.BlobPath(s.basedir))
	dstDir := filepath.Join(partition.BootloaderDir(), blobName)
	if err := os.RemoveAll(dstDir); err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 4
0
// extractKernelAssets extracts kernel/initrd/dtb data from the given
// SnapPart to a versionized bootloader directory so that the bootloader
// can use it.
func extractKernelAssets(s *SnapPart, inter progress.Meter, flags InstallFlags) error {
	if s.m.Type != pkg.TypeKernel {
		return fmt.Errorf("can not extract kernel assets from snap type %q", s.Type())
	}

	// FIXME: feels wrong to use the basedir here, need something better
	//
	// now do the kernel specific bits
	blobName := filepath.Base(squashfs.BlobPath(s.basedir))
	dstDir := filepath.Join(partition.BootloaderDir(), blobName)
	if err := os.MkdirAll(dstDir, 0755); err != nil {
		return err
	}
	dir, err := os.Open(dstDir)
	if err != nil {
		return err
	}
	defer dir.Close()

	for _, src := range []string{s.m.Kernel, s.m.Initrd} {
		if src == "" {
			continue
		}
		if err := s.deb.Unpack(src, dstDir); err != nil {
			return err
		}
		src = filepath.Join(dstDir, src)
		dst := filepath.Join(dstDir, dropVersionSuffix(src))
		if err := os.Rename(src, dst); err != nil {
			return err
		}
		if err := dir.Sync(); err != nil {
			return err
		}
	}
	if s.m.Dtbs != "" {
		src := filepath.Join(s.m.Dtbs, "*")
		dst := dstDir
		if err := s.deb.Unpack(src, dst); err != nil {
			return err
		}
	}

	return dir.Sync()
}
Ejemplo n.º 5
0
func (s *SquashfsTestSuite) TestInstallKernelSnapRemovesKernelAssets(c *C) {
	files := [][]string{
		{"vmlinuz-4.2", "I'm a kernel"},
		{"initrd.img-4.2", "...and I'm an initrd"},
	}
	snapPkg := makeTestSnapPackageWithFiles(c, packageKernel, files)
	part, err := NewSnapPartFromSnapFile(snapPkg, "origin", true)
	c.Assert(err, IsNil)

	_, err = part.Install(&MockProgressMeter{}, 0)
	c.Assert(err, IsNil)
	kernelAssetsDir := filepath.Join(partition.BootloaderDir(), "ubuntu-kernel.origin_4.0-1.snap")
	c.Assert(helpers.FileExists(kernelAssetsDir), Equals, true)

	// ensure uninstall cleans the kernel assets
	err = part.Uninstall(&MockProgressMeter{})
	c.Assert(err, IsNil)
	c.Assert(helpers.FileExists(kernelAssetsDir), Equals, false)
}
Ejemplo n.º 6
0
func bootloaderDirImpl() string {
	return partition.BootloaderDir()
}