예제 #1
0
func (r *Repo) signDeb(debPath string) error {
	if !r.Config.Sign {
		return nil
	}
	d, err := deb.Open(debPath)
	if err != nil {
		log.Printf("Failed to open deb '%s': %s\n", debPath, err)
		return err
	}
	defer d.Close()
	err = d.Sign(r.Config.GpgKey)
	if err != nil {
		log.Printf("Failed to sign deb '%s': %s\n", debPath, err)
		return err
	}
	return nil
}
예제 #2
0
func (r *Repo) parseDeb(debPath string) error {
	pkg := Package{}

	d, err := deb.Open(debPath)
	if err != nil {
		log.Printf("Failed to open deb '%s': %s\n", debPath, err)
		return err
	}
	defer d.Close()

	info, err := d.Control("control")
	if err != nil {
		log.Printf("Failed to parse deb '%s': %s\n", debPath, err)
		return err
	}

	if len(info) != 1 {
		log.Printf("%s: Expected 1 paragraph in .deb control file, not %d\n", debPath, len(info))
		return fmt.Errorf("%s/1 paragraphs in control: %s", len(info), debPath)
	}

	version := info[0]["Version"]
	pkgName := info[0]["Package"]
	arch := info[0]["Architecture"]

	pkg.Description = info[0]["Description"]
	pkg.Control = info[0]
	delete(pkg.Control, "Description")

	if version == "" {
		log.Printf("deb did not include version info: %s\n", debPath)
		return fmt.Errorf("no version in %s", debPath)
	}
	if pkgName == "" {
		log.Printf("deb did not include package name: %s\n", debPath)
		return fmt.Errorf("no package name in %s", debPath)
	}
	if arch == "" {
		log.Printf("deb did not include architecture: %s\n", debPath)
		return fmt.Errorf("no architecture in %s", debPath)
	}
	base := fmt.Sprintf("pool/main/%s/%s/", pkgName[0:1], pkgName)
	debName := fmt.Sprintf("%s_%s_%s.deb", pkgName, version, arch)
	pkg.Filename = filepath.Join(base, debName)
	filename := filepath.Join(repoPath, r.Name, pkg.Filename)
	f, err := os.Open(debPath)
	if err != nil {
		log.Printf("Failed to open '%s': %s\n", debPath, err)
		return err
	}
	defer f.Close()
	destDir := filepath.Dir(filename)
	if destDir != "." {
		err = os.MkdirAll(destDir, 0755)
		if err != nil {
			log.Printf("Failed to create '%s': %s\n", destDir, err)
			return err
		}
	}
	w, err := os.Create(filename)
	if err != nil {
		log.Printf("Failed to open '%s': %s\n", filename, err)
		return err
	}
	hw := NewHashWriter(w)
	defer w.Close()
	size, err := io.Copy(hw, f)
	if err != nil {
		log.Printf("Failed to copy '%s' -> '%s': %s\n", debPath, filename, err)
		return err
	}
	pkg.Size = uint64(size)
	pkg.Sha1 = hw.Sha1()
	pkg.Sha256 = hw.Sha256()
	pkg.Md5 = hw.Md5()

	var pkgs map[string]PackageSet
	switch strings.ToLower(arch) {
	case "i386":
		pkgs = r.Packages.I386
	case "amd64":
		pkgs = r.Packages.Amd64
	case "source":
		pkgs = r.Packages.Source
	default:
		log.Printf("Unsupported architecture: %s\n", arch)
		return fmt.Errorf("Unsupported arch: %s", arch)
	}

	set, found := pkgs[pkgName]
	if !found {
		set = make(PackageSet)
	}
	set[version] = pkg
	pkgs[pkgName] = set

	return r.Save()
}