Example #1
0
File: dumb.go Project: dz0ny/cdeb
func createDumbDeb(debPath, rootPath, controlPath string) error {
	now := time.Now()
	deb, err := os.Create(debPath)
	defer deb.Close()
	if err != nil {
		return err
	}

	dataTarGz, err := createData(now, rootPath)
	if err != nil {
		return err
	}
	rootFiles := md5data(rootPath)
	md5sums := []byte(strings.Join(rootFiles, "\n"))
	controlTarGz, err := createControl(now, controlPath, md5sums)
	if err != nil {
		return err
	}

	w := ar.NewWriter(deb)
	if err := w.WriteGlobalHeader(); err != nil {
		return fmt.Errorf("cannot write ar header to deb file: %v", err)
	}

	if err := addArFile(now, w, "debian-binary", []byte("2.0\n")); err != nil {
		return fmt.Errorf("cannot pack debian-binary: %v", err)
	}
	if err := addArFile(now, w, "control.tar.gz", controlTarGz); err != nil {
		return fmt.Errorf("cannot add control.tar.gz to deb: %v", err)
	}
	if err := addArFile(now, w, "data.tar.gz", dataTarGz); err != nil {
		return fmt.Errorf("cannot add data.tar.gz to deb: %v", err)
	}
	return nil
}
Example #2
0
File: deb.go Project: jett/godeb
func createDeb(version string, tarball io.Reader, deb io.Writer) error {
	now := time.Now()
	dataTarGz, md5sums, instSize, err := translateTarball(now, tarball)
	if err != nil {
		return err
	}
	controlTarGz, err := createControl(now, version, instSize, md5sums)
	if err != nil {
		return err
	}
	w := ar.NewWriter(deb)
	if err := w.WriteGlobalHeader(); err != nil {
		return fmt.Errorf("cannot write ar header to deb file: %v", err)
	}

	if err := addArFile(now, w, "debian-binary", []byte("2.0\n")); err != nil {
		return fmt.Errorf("cannot pack debian-binary: %v", err)
	}
	if err := addArFile(now, w, "control.tar.gz", controlTarGz); err != nil {
		return fmt.Errorf("cannot add control.tar.gz to deb: %v", err)
	}
	if err := addArFile(now, w, "data.tar.gz", dataTarGz); err != nil {
		return fmt.Errorf("cannot add data.tar.gz to deb: %v", err)
	}
	return nil
}
Example #3
0
// Build takes a build debian directory with DEBIAN/ dir and creates a
// clickdeb from it
func (d *ClickDeb) Build(sourceDir string, dataTarFinishedCallback func(dataName string) error) error {
	var err error

	// tmp
	tempdir, err := ioutil.TempDir("", "data")
	if err != nil {
		return err
	}
	defer os.RemoveAll(tempdir)

	// we use gz to support signature verification on older ubuntu releases
	// like trusty that does not support xz yet
	dataName := filepath.Join(tempdir, "data.tar.gz")
	err = tarCreate(dataName, sourceDir, func(path string) bool {
		return !strings.HasPrefix(path, filepath.Join(sourceDir, "DEBIAN"))
	})
	if err != nil {
		return err
	}

	// this allows us to add hashes
	if dataTarFinishedCallback != nil {
		if err := dataTarFinishedCallback(dataName); err != nil {
			return err
		}
	}

	// create control data (for click compat)
	controlName := filepath.Join(tempdir, "control.tar.gz")
	if err := tarCreate(controlName, filepath.Join(sourceDir, "DEBIAN"), nil); err != nil {
		return err
	}

	// create ar
	arWriter := ar.NewWriter(d.file)
	arWriter.WriteGlobalHeader()

	// debian magic
	if err := addDataToAr(arWriter, "debian-binary", []byte("2.0\n")); err != nil {
		return err
	}

	// click magic
	if err := addDataToAr(arWriter, "_click-binary", []byte("0.4\n")); err != nil {
		return err
	}

	// control file
	if err := addFileToAr(arWriter, controlName); err != nil {
		return err
	}

	// data file
	if err := addFileToAr(arWriter, dataName); err != nil {
		return err
	}

	return nil
}