func (b *builder) extractCommand() command.Command {
	return command_adapter.New(func() error {
		return b.extractFile(b.fileReader, b.workingdirectory)
	}, func() error {
		return nil
	})
}
Beispiel #2
0
func (b *builder) createDebianCopyPrePostFilesCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("copy pre post inst rm files")
		var err error
		path := fmt.Sprintf("%s/%s_%s/DEBIAN", b.workingdirectory, b.config.Name, b.config.Version)
		if len(b.config.Postinst) > 0 {
			if err = b.copier.Copy(b.config.Postinst, fmt.Sprintf("%s/postinst", path)); err != nil {
				return err
			}
		}
		if len(b.config.Postrm) > 0 {
			if err = b.copier.Copy(b.config.Postrm, fmt.Sprintf("%s/postrm", path)); err != nil {
				return err
			}
		}
		if len(b.config.Preinst) > 0 {
			if err = b.copier.Copy(b.config.Preinst, fmt.Sprintf("%s/preinst", path)); err != nil {
				return err
			}
		}
		if len(b.config.Prerm) > 0 {
			if err = b.copier.Copy(b.config.Prerm, fmt.Sprintf("%s/prerm", path)); err != nil {
				return err
			}
		}
		glog.V(2).Infof("pre post inst rm files copied")
		return nil
	}, func() error {
		return nil
	})
}
func (b *builder) createDebianPackageCommand() command.Command {
	return command_adapter.New(func() error {
		configBuilder := debian_config_builder.NewWithConfig(b.config)
		if err := configBuilder.AddFile(joinDirs(b.workingdirectory, b.sourceDir), b.targetDir); err != nil {
			return err
		}
		return b.packageCreator.CreatePackage(configBuilder.Build())
	}, func() error {
		return nil
	})
}
func (b *builder) removeWorkingDirectoryCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("clean working directory %s", b.workingdirectory)
		if err := os.RemoveAll(b.workingdirectory); err != nil {
			return err
		}
		glog.V(2).Infof("working directory %s cleaned", b.workingdirectory)
		return nil
	}, func() error {
		return nil
	})
}
Beispiel #5
0
func (b *builder) createDebianControlCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("write debian control")
		if err := ioutil.WriteFile(fmt.Sprintf("%s/%s_%s/DEBIAN/control", b.workingdirectory, b.config.Name, b.config.Version), controlContent(*b.config), 0644); err != nil {
			return err
		}
		glog.V(2).Infof("debian control written")
		return nil
	}, func() error {
		return nil
	})
}
func (b *builder) createWorkingDirectoryCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("create working directory")
		var err error
		if b.workingdirectory, err = ioutil.TempDir("", "create-debian-package"); err != nil {
			return err
		}
		glog.V(2).Infof("working directory %s create", b.workingdirectory)
		return nil
	}, func() error {
		return os.RemoveAll(b.workingdirectory)
	})
}
Beispiel #7
0
func (b *builder) createDebianFolderCommand() command.Command {
	return command_adapter.New(func() error {
		path := fmt.Sprintf("%s/%s_%s/DEBIAN", b.workingdirectory, b.config.Name, b.config.Version)
		glog.V(2).Infof("create debian folder %s", path)
		if err := createDirectory(path); err != nil {
			return err
		}
		glog.V(2).Infof("debian folder created")
		return nil
	}, func() error {
		return nil
	})
}
Beispiel #8
0
func (b *builder) createWorkingDirectoryCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("create working directory")
		var err error
		if b.workingdirectory, err = ioutil.TempDir("", fmt.Sprintf("%s_%s", b.config.Name, b.config.Version)); err != nil {
			return err
		}
		glog.V(2).Infof("working directory %s create", b.workingdirectory)
		return nil
	}, func() error {
		return os.RemoveAll(b.workingdirectory)
	})
}
Beispiel #9
0
func (b *builder) createDebianPackageCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("create debian package")
		cmd := exec.Command("dpkg-deb", "-Zgzip", "--build", fmt.Sprintf("%s_%s", b.config.Name, b.config.Version))
		cmd.Dir = b.workingdirectory
		cmd.Stderr = os.Stderr
		//cmd.Stdout = os.Stdout
		if err := cmd.Run(); err != nil {
			return err
		}
		glog.V(2).Infof("debian package created")
		return nil
	}, func() error {
		return nil
	})
}
Beispiel #10
0
func (b *builder) createDebianConffilesCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("write debian conffiles")
		content := conffilesContent(b.config.Files)
		if len(content) > 0 {
			if err := ioutil.WriteFile(fmt.Sprintf("%s/%s_%s/DEBIAN/conffiles", b.workingdirectory, b.config.Name, b.config.Version), content, 0644); err != nil {
				return err
			}
			glog.V(2).Infof("debian conffiles written")
		} else {
			glog.V(2).Infof("no found files, skip writing")
		}
		return nil
	}, func() error {
		return nil
	})
}
Beispiel #11
0
func (b *builder) validateCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Info("validate")
		if len(b.config.Files) == 0 {
			return fmt.Errorf("add at least one file")
		}
		if len(b.config.Name) == 0 {
			return fmt.Errorf("name missing")
		}
		if len(b.config.Version) == 0 {
			return fmt.Errorf("version missing")
		}
		glog.V(2).Info("validate success")
		return nil
	}, func() error {
		return nil
	})
}
Beispiel #12
0
func (b *builder) copyDebianPackageCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("copy debian package")
		var dir string
		var err error
		if dir, err = os.Getwd(); err != nil {
			return err
		}
		source := fmt.Sprintf("%s/%s_%s.deb", b.workingdirectory, b.config.Name, b.config.Version)
		target := fmt.Sprintf("%s/%s_%s.deb", dir, b.config.Name, b.config.Version)
		if err = b.copier.Copy(source, target); err != nil {
			return err
		}
		glog.V(2).Infof("debian package copied")
		return nil
	}, func() error {
		return nil
	})
}
Beispiel #13
0
func (b *builder) copyFilesToWorkingDirectoryCommand() command.Command {
	return command_adapter.New(func() error {
		glog.V(2).Infof("copy files")
		for _, file := range b.config.Files {
			var err error
			var directory string
			var filename string
			filename = fmt.Sprintf("%s/%s_%s%s", b.workingdirectory, b.config.Name, b.config.Version, file.Target)
			if directory, err = dirOf(filename); err != nil {
				return err
			}
			if err = createDirectory(directory); err != nil {
				return err
			}
			glog.V(2).Infof("%s extract = %v", file.Source, file.Extract)
			if file.Extract {
				if strings.HasSuffix(file.Source, ".zip") {
					glog.V(2).Infof("is zip => extract")
					f, err := b.fileToReader(file.Source)
					if err != nil {
						return err
					}
					defer f.Close()
					return b.extractZipFile(f, filename)
				}
				if strings.HasSuffix(file.Source, ".tar.gz") || strings.HasSuffix(file.Source, ".tgz") {
					glog.V(2).Infof("is tar gz => extract")
					f, err := b.fileToReader(file.Source)
					if err != nil {
						return err
					}
					defer f.Close()
					return b.extractTarGz(f, filename)
				}
				return fmt.Errorf("unkown file type")
			}
			if isURL(file.Source) {
				glog.V(2).Infof("%s is url", file.Source)
				f, err := b.fileToReader(file.Source)
				if err != nil {
					return err
				}
				defer f.Close()
				var perm os.FileMode = 0644
				w, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
				if err != nil {
					return err
				}
				defer w.Close()
				if _, err = io.Copy(w, f); err != nil {
					return err
				}
			}
			if err = b.copier.Copy(file.Source, filename); err != nil {
				return err
			}
		}
		glog.V(2).Infof("all files copied")
		return nil
	}, func() error {
		return nil
	})
}