Exemplo n.º 1
0
// Customize intended for the target customization
// - pathToConfigDir - path to directory containing configuration XML files
func (i *image) Customize(pathToConfigDir string) error {
	if i.amountOfMappers == 0 {
		return utils.FormatError(errors.New("amount of mappers is 0.Seems Parse() hasn't been called yet."))
	}
	return content.Customize(i.slashpath, pathToConfigDir)
}
func (f *rootfsFiller) CustomizeRootfs(pathToRootfsMp string) error {
	unsquashfs, err := exec.LookPath("unsquashfs")
	if err != nil {
		unsquashfs = filepath.Join(f.pathToKitDir, "install/x86_64/bin/unsquashfs")
	}

	path := filepath.Join(pathToRootfsMp, "rootfs")
	exec.Command(unsquashfs, "-dest", path, f.pathToRootfsSquashfs).Run()
	dir, err := ioutil.ReadDir(path)
	if err != nil {
		return utils.FormatError(err)
	}
	for _, cont := range dir {
		exec.Command("cp", "-a", filepath.Join(path, cont.Name()), pathToRootfsMp).CombinedOutput()
	}
	if err := os.RemoveAll(path); err != nil {
		return utils.FormatError(err)
	}
	if f.pathToKernelModulesArchive != "" && f.pathToKernelArchive != "" {
		errCh := make(chan error, 2)
		defer close(errCh)

		go func() {
			errCh <- archutils.Extract(f.pathToKernelArchive, filepath.Join(pathToRootfsMp, "boot"))
		}()
		go func() {
			errCh <- archutils.Extract(f.pathToKernelModulesArchive, filepath.Join(pathToRootfsMp, "lib/modules"))
		}()
		if err := utils.WaitForResult(errCh, 2); err != nil {
			if !strings.Contains(err.Error(), ERROR_SKIP_B) {
				return utils.FormatError(err)
			}
		}

		modulesDir, err := filepath.Glob(filepath.Join(pathToRootfsMp, "lib/modules/*"))
		if err != nil {
			return utils.FormatError(err)
		}
		if len(modulesDir) == 0 {
			return errors.New("modules not found")
		}

		kernelVersion := filepath.Base(modulesDir[0])
		if err := os.Symlink("/boot/vmlinuz-"+kernelVersion, filepath.Join(pathToRootfsMp, "vmlinuz")); err != nil {
			return utils.FormatError(err)
		}
		if err := os.Symlink("/boot/initrd.img-"+kernelVersion, filepath.Join(pathToRootfsMp, "initrd.img")); err != nil {
			return utils.FormatError(err)
		}
	}

	pathToCommonDir := filepath.Join(f.pathToKitDir, "comp/env/common/config")
	fd, err := os.Stat(pathToCommonDir)
	if err == nil && fd.IsDir() {
		if err := content.Customize(pathToRootfsMp, pathToCommonDir); err != nil {
			return utils.FormatError(err)
		}
	}
	if f.pathToConfigDir != "" {
		if err := content.Customize(pathToRootfsMp, f.pathToConfigDir); err != nil {
			return utils.FormatError(err)
		}
	}
	return nil
}