예제 #1
0
// GenDataArchive generates the 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
	}
	dwh := NewTarWriterHelper(dataTgzw.Writer)
	//NOTE: files only for now
	err = dwh.AddFilesOrDirs(dgen.DataFiles)
	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
}
예제 #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
}
예제 #3
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.Control, Deb: dgen.DebWriter}
	//templateVars.Deb = dgen.DebWriter

	cwh := NewTarWriterHelper(controlTgzw.Writer)
	err = dgen.GenControlFile(cwh, 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 = cwh.AddFile(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 = cwh.AddBytes(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
}
예제 #4
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
}
예제 #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
	}
	twh := NewTarWriterHelper(tgzw.Writer)
	err = twh.AddFilesOrDirs(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
}
예제 #6
0
func Test_buildBinaryDeb(t *testing.T) {

	pkg := deb.NewControlDefault("testpkg", "me", "me@a", "Dummy package for doing nothing", "testpkg is package ", true)
	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.NewWriters(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.Writer) 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
		}
		err = os.MkdirAll(deb.DistDirDefault, 0777)
		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)
		}
	}
}
예제 #7
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))
	if err != nil {
		return err
	}
	defer tgzw.Close()
	twh := NewTarWriterHelper(tgzw.Writer)
	resourceDir := spgen.BuildParams.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 = twh.AddFile(resourcePath, DebianDir+"/"+debianFile)
			if err != nil {
				return err
			}
		} else {
			controlData, err := TemplateFileOrString(filepath.Join(templateDir, debianFilePath+TplExtension), defaultTemplateStr, templateVars)
			if err != nil {
				return err
			}
			err = twh.AddBytes(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.DebianDir, scriptName)
		_, err = os.Stat(resourcePath)
		if err == nil {
			err = twh.AddFile(resourcePath, DebianDir+"/"+scriptName)
			if err != nil {
				return err
			}
		} else {
			templatePath := filepath.Join(spgen.BuildParams.TemplateDir, "source", 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 = twh.AddBytes(scriptData, DebianDir+"/"+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
}