Exemplo n.º 1
0
// GenDataArchive generates the 'code' archive from files on the file system.
func (dgen *DebGenerator) GenDataArchive() error {
	archiveFilename := filepath.Join(dgen.BuildParams.TmpDir, dgen.DebWriter.DataArchive)
	dataTgzw, err := targz.NewWriterFromFile(archiveFilename)
	if err != nil {
		return err
	}
	err = TarAddFiles(dataTgzw.Writer, dgen.OrigFiles)
	if err != nil {
		return err
	}
	if dgen.BuildParams.IsVerbose {
		log.Printf("Added executables")
	}
	/*
		// TODO add README.debian automatically
		err = TarAddFiles(dataTgzw.Writer, dgen.DebWriter.Package.MappedFiles)
		if err != nil {
			return err
		}
	*/
	if dgen.BuildParams.IsVerbose {
		log.Printf("Added resources")
	}
	err = dataTgzw.Close()
	if err != nil {
		return err
	}
	if dgen.BuildParams.IsVerbose {
		log.Printf("Closed data archive")
	}
	return err
}
Exemplo n.º 2
0
func buildDebianArchive(spkg *deb.SourcePackage) error {
	tgzw, err := targz.NewWriterFromFile(filepath.Join(deb.DistDirDefault, spkg.DebianFileName))
	if err != nil {
		return err
	}
	// Add Control Files here !!
	err = tgzw.Close()
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 3
0
func buildOrigArchive(spkg *deb.SourcePackage) error {
	origFilePath := filepath.Join(deb.DistDirDefault, spkg.OrigFileName)
	tgzw, err := targz.NewWriterFromFile(origFilePath)
	if err != nil {
		return err
	}
	// Add Sources Here !!
	err = tgzw.Close()
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 4
0
//GenControlArchive generates control archive, using a system of templates or files.
//
//First it attempts to find the file inside BuildParams.Resources.
//If that doesn't exist, it attempts to find a template in templateDir
//Finally, it attempts to use a string-based template.
func (dgen *DebGenerator) GenControlArchive() error {
	archiveFilename := filepath.Join(dgen.BuildParams.TmpDir, dgen.DebWriter.ControlArchive)
	controlTgzw, err := targz.NewWriterFromFile(archiveFilename)
	if err != nil {
		return err
	}
	templateVars := &TemplateData{Package: dgen.DebWriter.Package, Deb: dgen.DebWriter}
	//templateVars.Deb = dgen.DebWriter

	err = dgen.GenControlFile(controlTgzw, templateVars)
	if err != nil {
		return err
	}
	if dgen.BuildParams.IsVerbose {
		log.Printf("Wrote control file to control archive")
	}
	// This is where you include Postrm/Postinst etc
	for _, scriptName := range deb.MaintainerScripts {
		resourcePath := filepath.Join(dgen.BuildParams.ResourcesDir, DebianDir, scriptName)
		_, err = os.Stat(resourcePath)
		if err == nil {
			err = TarAddFile(controlTgzw.Writer, resourcePath, scriptName)
			if err != nil {
				return err
			}
		} else {
			templatePath := filepath.Join(dgen.BuildParams.TemplateDir, DebianDir, scriptName+TplExtension)
			_, err = os.Stat(templatePath)
			//TODO handle non-EOF errors
			if err == nil {
				scriptData, err := TemplateFile(templatePath, templateVars)
				if err != nil {
					return err
				}
				err = TarAddBytes(controlTgzw.Writer, scriptData, scriptName, 0755)
				if err != nil {
					return err
				}
			}
		}
	}

	err = controlTgzw.Close()
	if err != nil {
		return err
	}
	if dgen.BuildParams.IsVerbose {
		log.Printf("Closed control archive")
	}
	return err
}
Exemplo n.º 5
0
// GenOrigArchive builds <package>.orig.tar.gz
// This contains the original upstream source code and data.
func (spgen *SourcePackageGenerator) GenOrigArchive() error {
	//TODO add/exclude resources to /usr/share
	origFilePath := filepath.Join(spgen.BuildParams.DestDir, spgen.SourcePackage.OrigFileName)
	tgzw, err := targz.NewWriterFromFile(origFilePath)
	defer tgzw.Close()
	if err != nil {
		return err
	}
	err = TarAddFiles(tgzw.Writer, spgen.OrigFiles)
	if err != nil {
		return err
	}
	err = tgzw.Close()
	if err != nil {
		return err
	}
	if spgen.BuildParams.IsVerbose {
		log.Printf("Created %s", origFilePath)
	}
	return nil
}
Exemplo n.º 6
0
// GenDebianArchive builds <package>.debian.tar.gz
// This contains all the control data, changelog, rules, etc
func (spgen *SourcePackageGenerator) GenDebianArchive() error {
	//set up template
	templateVars := NewTemplateData(spgen.SourcePackage.Package)

	// generate .debian.tar.gz (just containing debian/ directory)
	tgzw, err := targz.NewWriterFromFile(filepath.Join(spgen.BuildParams.DestDir, spgen.SourcePackage.DebianFileName))
	defer tgzw.Close()
	resourceDir := filepath.Join(spgen.BuildParams.ResourcesDir, "source", DebianDir)
	templateDir := filepath.Join(spgen.BuildParams.TemplateDir, "source", DebianDir)

	//TODO change this to iterate over specified list of files.
	for debianFile, defaultTemplateStr := range spgen.TemplateStrings {
		debianFilePath := strings.Replace(debianFile, "/", string(os.PathSeparator), -1) //fixing source/options, source/format for local files
		resourcePath := filepath.Join(resourceDir, debianFilePath)
		_, err = os.Stat(resourcePath)
		if err == nil {
			err = TarAddFile(tgzw.Writer, resourcePath, debianFile)
			if err != nil {
				return err
			}
		} else {
			controlData, err := TemplateFileOrString(filepath.Join(templateDir, debianFilePath+TplExtension), defaultTemplateStr, templateVars)
			if err != nil {
				return err
			}
			err = TarAddBytes(tgzw.Writer, controlData, DebianDir+"/"+debianFile, int64(0644))
			if err != nil {
				return err
			}
		}
	}

	// postrm/postinst etc from main store
	for _, scriptName := range deb.MaintainerScripts {
		resourcePath := filepath.Join(spgen.BuildParams.ResourcesDir, DebianDir, scriptName)
		_, err = os.Stat(resourcePath)
		if err == nil {
			err = TarAddFile(tgzw.Writer, resourcePath, scriptName)
			if err != nil {
				return err
			}
		} else {
			templatePath := filepath.Join(spgen.BuildParams.TemplateDir, DebianDir, scriptName+TplExtension)
			_, err = os.Stat(templatePath)
			//TODO handle non-EOF errors
			if err == nil {
				scriptData, err := TemplateFile(templatePath, templateVars)
				if err != nil {
					return err
				}
				err = TarAddBytes(tgzw.Writer, scriptData, scriptName, 0755)
				if err != nil {
					return err
				}
			}
		}
	}

	err = tgzw.Close()
	if err != nil {
		return err
	}

	if spgen.BuildParams.IsVerbose {
		log.Printf("Created %s", filepath.Join(spgen.BuildParams.DestDir, spgen.SourcePackage.DebianFileName))
	}
	return nil
}
Exemplo n.º 7
0
func Test_buildBinaryDeb(t *testing.T) {

	pkg := deb.NewPackage("testpkg", "0.0.2", "me", "lovely package\n")
	exesMap := map[string][]string{
		"amd64": []string{filepath.Join(deb.TempDirDefault, "a.amd64")},
		"i386":  []string{filepath.Join(deb.TempDirDefault, "a.i386")},
		"armhf": []string{filepath.Join(deb.TempDirDefault, "a.armhf")}}
	err := createExes(exesMap)
	if err != nil {
		t.Fatalf("%v", err)
	}
	artifacts, err := deb.NewDebWriters(pkg)
	if err != nil {
		t.Fatalf("Error building binary: %v", err)
	}
	artifacts[deb.ArchAmd64].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.amd64")}
	artifacts[deb.ArchI386].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.i386")}
	artifacts[deb.ArchArmhf].MappedFiles = map[string]string{"/usr/bin/a": filepath.Join(deb.TempDirDefault, "/a.armhf")}
	buildDeb := func(art *deb.DebWriter) error {
		archiveFilename := filepath.Join(deb.TempDirDefault, art.ControlArchive)
		controlTgzw, err := targz.NewWriterFromFile(archiveFilename)
		if err != nil {
			return err
		}
		controlData := []byte("Package: testpkg\n")
		//TODO add more files here ...
		header := &tar.Header{Name: "control", Size: int64(len(controlData)), Mode: int64(644), ModTime: time.Now()}
		err = controlTgzw.WriteHeader(header)
		if err != nil {
			return err
		}
		_, err = controlTgzw.Write(controlData)
		if err != nil {
			return err
		}
		err = controlTgzw.Close()
		if err != nil {
			return err
		}

		archiveFilename = filepath.Join(deb.TempDirDefault, art.DataArchive)
		dataTgzw, err := targz.NewWriterFromFile(archiveFilename)
		if err != nil {
			return err
		}
		//TODO add files here ...
		err = dataTgzw.Close()
		if err != nil {
			return err
		}
		//generate artifact here ...
		err = art.Build(deb.TempDirDefault, deb.DistDirDefault)
		if err != nil {
			return err
		}
		return nil
	}
	for arch, artifact := range artifacts {
		//build binary deb here ...
		err = buildDeb(artifact)
		if err != nil {
			t.Fatalf("Error building for '%s': %v", arch, err)
		}
	}
}