Exemple #1
0
func (g *GenKey) Export() (err error) {
	id, err := GetId()
	if err != nil {
		return
	}

	data, err := utils.ExecOutput(g.Root,
		"gpg", "-a", "--export-secret-keys", id)
	if err != nil {
		return
	}

	err = utils.CreateWrite(filepath.Join(g.Root, "sign.key"), data)
	if err != nil {
		return
	}

	data, err = utils.ExecOutput(g.Root,
		"gpg", "-a", "--export", id)
	if err != nil {
		return
	}

	err = utils.CreateWrite(filepath.Join(g.Root, "sign.pub"), data)
	if err != nil {
		return
	}

	return
}
Exemple #2
0
func (d *Debian) createScripts() (err error) {
	scripts := map[string][]string{
		"preinst":  d.Pack.PreInst,
		"postinst": d.Pack.PostInst,
		"prerm":    d.Pack.PreRm,
		"postrm":   d.Pack.PostRm,
	}

	for name, script := range scripts {
		if len(script) == 0 {
			continue
		}

		data := strings.Join(script, "\n")
		if name == "prerm" || name == "postrm" {
			data = removeHeader + data
		}

		path := filepath.Join(d.debDir, name)

		err = utils.CreateWrite(path, data)
		if err != nil {
			return
		}

		err = utils.Chmod(path, 0755)
		if err != nil {
			return
		}
	}

	return
}
Exemple #3
0
func (d *Debian) createMd5Sums() (err error) {
	path := filepath.Join(d.debDir, "md5sums")

	err = utils.CreateWrite(path, d.sums)
	if err != nil {
		return
	}

	return
}
Exemple #4
0
func createScript(path string, cmds []string) (err error) {
	data := "set -e\n"
	for _, cmd := range cmds {
		data += cmd + "\n"
	}

	err = utils.CreateWrite(path, data)
	if err != nil {
		return
	}

	return
}
Exemple #5
0
func (p *Project) InitProject() (err error) {
	exists, err := utils.Exists(p.confPath)
	if err != nil {
		return
	}

	if !exists {
		err = utils.CreateWrite(p.confPath, `{\n    "name": "pacur"\n}\n`)
		if err != nil {
			return
		}
	}

	return
}
Exemple #6
0
func (p *Pacman) createInstall() (exists bool, err error) {
	data := ""

	if len(p.Pack.PreInst) > 0 {
		data += "pre_install() {\n"
		for _, line := range p.Pack.PreInst {
			data += fmt.Sprintf("    %s\n", line)
		}
		data += "}\n"
	}

	if len(p.Pack.PostInst) > 0 {
		data += "post_install() {\n"
		for _, line := range p.Pack.PostInst {
			data += fmt.Sprintf("    %s\n", line)
		}
		data += "}\n"
	}

	if len(p.Pack.PreRm) > 0 {
		data += "pre_remove() {\n"
		for _, line := range p.Pack.PreRm {
			data += fmt.Sprintf("    %s\n", line)
		}
		data += "}\n"
	}

	if len(p.Pack.PostRm) > 0 {
		data += "post_remove() {\n"
		for _, line := range p.Pack.PostRm {
			data += fmt.Sprintf("    %s\n", line)
		}
		data += "}\n"
	}

	exists = len(data) > 0
	if exists {
		path := filepath.Join(p.pacmanDir, p.Pack.PkgName+".install")
		err = utils.CreateWrite(path, data)
		if err != nil {
			return
		}
	}

	return
}
Exemple #7
0
func (d *Debian) createControl() (err error) {
	path := filepath.Join(d.debDir, "control")

	data := ""

	data += fmt.Sprintf("Package: %s\n", d.Pack.PkgName)
	data += fmt.Sprintf("Version: %s-0%s%s~%s\n",
		d.Pack.PkgVer, d.Pack.Distro, d.Pack.PkgRel, d.Pack.Release)
	data += fmt.Sprintf("Architecture: %s\n", d.Pack.Arch)
	data += fmt.Sprintf("Maintainer: %s\n", d.Pack.Maintainer)
	data += fmt.Sprintf("Installed-Size: %d\n", d.installSize)

	if len(d.Pack.Depends) > 0 {
		data += fmt.Sprintf("Depends: %s\n",
			strings.Join(d.Pack.Depends, ", "))
	}

	if len(d.Pack.Depends) > 0 {
		data += fmt.Sprintf("Conflicts: %s\n",
			strings.Join(d.Pack.Conflicts, ", "))
	}

	if len(d.Pack.OptDepends) > 0 {
		data += fmt.Sprintf("Recommends: %s\n",
			strings.Join(d.Pack.OptDepends, ", "))
	}

	data += fmt.Sprintf("Section: %s\n", d.Pack.Section)
	data += fmt.Sprintf("Priority: %s\n", d.Pack.Priority)
	data += fmt.Sprintf("Homepage: %s\n", d.Pack.Url)
	data += fmt.Sprintf("Description: %s\n", d.Pack.PkgDesc)

	for _, line := range d.Pack.PkgDescLong {
		if line == "" {
			line = "."
		}
		data += fmt.Sprintf("  %s\n", line)
	}

	err = utils.CreateWrite(path, data)
	if err != nil {
		return
	}

	return
}
Exemple #8
0
func (g *GenKey) createConf() (path string, err error) {
	path = filepath.Join(g.Root, "genkey")

	err = utils.CreateWrite(path, "%no-protection\n"+
		"Key-Type: 1\n"+
		"Key-Length: 4096\n"+
		"Subkey-Type: 1\n"+
		"Subkey-Length: 4096\n"+
		fmt.Sprintf("Name-Real: %s\n", g.Name)+
		fmt.Sprintf("Name-Email: %s\n", g.Email)+
		"Expire-Date: 0\n"+
		"%commit\n")
	if err != nil {
		return
	}

	return
}
Exemple #9
0
func (d *Debian) createConfFiles() (err error) {
	if len(d.Pack.Backup) == 0 {
		return
	}

	path := filepath.Join(d.debDir, "conffiles")

	data := ""
	for _, name := range d.Pack.Backup {
		if !strings.HasPrefix(name, "/") {
			name = "/" + name
		}
		data += name + "\n"
	}

	err = utils.CreateWrite(path, data)
	if err != nil {
		return
	}

	return
}
Exemple #10
0
func CreateRedhatConf() (err error) {
	name, err := GetName()
	if err != nil {
		return
	}

	data := fmt.Sprintf("%%_signature gpg\n%%_gpg_name %s\n", name)

	usr, err := user.Current()
	if err != nil {
		err = &LookupError{
			errors.Wrap(err, "signing: Failed to get current user"),
		}
		return
	}

	err = utils.CreateWrite(filepath.Join(usr.HomeDir, ".rpmmacros"), data)
	if err != nil {
		return
	}

	return
}
Exemple #11
0
func (p *Pacman) createMake() (err error) {
	path := filepath.Join(p.pacmanDir, "PKGBUILD")

	installExists, err := p.createInstall()
	if err != nil {
		return
	}

	data := ""
	data += fmt.Sprintf("# Maintainer: %s\n\n", p.Pack.Maintainer)
	data += fmt.Sprintf("pkgname=%s\n", strconv.Quote(p.Pack.PkgName))
	data += fmt.Sprintf("pkgver=%s\n", strconv.Quote(p.Pack.PkgVer))
	data += fmt.Sprintf("pkgrel=%s\n", strconv.Quote(p.Pack.PkgRel))
	data += fmt.Sprintf("pkgdesc=%s\n", strconv.Quote(p.Pack.PkgDesc))
	data += fmt.Sprintf("arch=(%s)\n",
		strconv.Quote(convertPacman(p.Pack.Arch)))

	data += "license=(\n"
	for _, item := range p.Pack.License {
		data += fmt.Sprintf("    %s\n", strconv.Quote(item))
	}
	data += ")\n"

	data += fmt.Sprintf("url=%s\n", strconv.Quote(p.Pack.Url))

	if len(p.Pack.Depends) > 0 {
		data += "depends=(\n"
		for _, item := range p.Pack.Depends {
			data += fmt.Sprintf("    %s\n", strconv.Quote(item))
		}
		data += ")\n"
	}

	if len(p.Pack.OptDepends) > 0 {
		data += "optdepends=(\n"
		for _, item := range p.Pack.OptDepends {
			data += fmt.Sprintf("    %s\n", strconv.Quote(item))
		}
		data += ")\n"
	}

	if len(p.Pack.Provides) > 0 {
		data += "provides=(\n"
		for _, item := range p.Pack.Provides {
			data += fmt.Sprintf("    %s\n", strconv.Quote(item))
		}
		data += ")\n"
	}

	if len(p.Pack.Conflicts) > 0 {
		data += "conflicts=(\n"
		for _, item := range p.Pack.Conflicts {
			data += fmt.Sprintf("    %s\n", strconv.Quote(item))
		}
		data += ")\n"
	}

	if installExists {
		data += fmt.Sprintf("install=%s\n",
			strconv.Quote(p.Pack.PkgName+".install"))
	}

	data += "options=(\"emptydirs\")\n"

	if len(p.Pack.Backup) > 0 {
		data += "backup=(\n"
		for _, item := range p.Pack.Backup {
			if strings.HasPrefix(item, "/") {
				item = item[1:]
			}
			data += fmt.Sprintf("    %s\n", strconv.Quote(item))
		}
		data += ")\n"
	}

	data += "package() {\n"
	data += fmt.Sprintf("    rsync -a -A -X %s/ ${pkgdir}/\n",
		p.Pack.PackageDir)
	data += "}\n"

	err = utils.CreateWrite(path, data)
	if err != nil {
		return
	}

	fmt.Println(data)

	return
}
Exemple #12
0
func (m *Mirror) createDebian() (err error) {
	outDir := filepath.Join(m.Root, "apt")
	confDir := filepath.Join(m.Root, "conf")
	confPath := filepath.Join(confDir, "distributions")

	err = utils.MkdirAll(confDir)
	if err != nil {
		return
	}

	data := "Codename: " + m.Release + "\n" +
		"Components: main\nArchitectures: i386 amd64\n"

	if m.Signing {
		id, e := signing.GetId()
		if e != nil {
			err = e
			return
		}

		data += fmt.Sprintf("SignWith: %s\n", id)

		err = utils.CreateWrite(filepath.Join(confDir, "options"),
			"ask-passphrase\n")
		if err != nil {
			return
		}
	}

	err = utils.CreateWrite(confPath, data)
	if err != nil {
		return
	}

	err = utils.MkdirAll(outDir)
	if err != nil {
		return
	}

	match, ok := constants.ReleasesMatch[m.Distro+"-"+m.Release]
	if !ok {
		err = &BuildError{
			errors.Newf("mirror: Failed to find match for '%s'",
				m.Distro+"-"+m.Release),
		}
		return
	}

	debs, err := utils.FindMatch(m.Root, match)
	if err != nil {
		return
	}

	for _, deb := range debs {
		err = utils.Exec(m.Root, "reprepro", "--outdir", outDir,
			"includedeb", m.Release, deb)
		if err != nil {
			return
		}
	}

	return
}
Exemple #13
0
func (r *Redhat) createSpec(files []string) (err error) {
	path := filepath.Join(r.specsDir, r.Pack.PkgName+".spec")

	data := ""
	data += fmt.Sprintf("Name: %s\n", r.Pack.PkgName)
	data += fmt.Sprintf("Summary: %s\n", r.Pack.PkgDesc)
	data += fmt.Sprintf("Version: %s\n", r.Pack.PkgVer)
	data += fmt.Sprintf("Release: %s", r.Pack.PkgRel) + "%{?dist}\n"
	data += fmt.Sprintf("Group: %s\n", ConvertSection(r.Pack.Section))
	data += fmt.Sprintf("URL: %s\n", r.Pack.Url)
	data += fmt.Sprintf("License: %s\n", r.Pack.License)
	data += fmt.Sprintf("Packager: %s\n", r.Pack.Maintainer)

	for _, pkg := range r.Pack.Provides {
		data += fmt.Sprintf("Provides: %s\n", pkg)
	}

	for _, pkg := range r.Pack.Conflicts {
		data += fmt.Sprintf("Conflicts: %s\n", pkg)
	}

	for _, pkg := range r.Pack.Depends {
		data += fmt.Sprintf("Requires: %s\n", pkg)
	}

	for _, pkg := range r.Pack.MakeDepends {
		data += fmt.Sprintf("BuildRequires: %s\n", pkg)
	}

	data += "\n"

	if len(r.Pack.PkgDescLong) > 0 {
		data += "%description\n"
		for _, line := range r.Pack.PkgDescLong {
			data += line + "\n"
		}
		data += "\n"
	}

	data += "%install\n"
	data += fmt.Sprintf("rsync -a -A -X %s/ $RPM_BUILD_ROOT/\n",
		r.Pack.PackageDir)
	data += "\n"

	data += "%files\n"
	if len(files) == 0 {
		data += "/\n"
	} else {
		for _, line := range files {
			data += line + "\n"
		}
	}
	data += "\n"

	if len(r.Pack.PreInst) > 0 {
		data += "%pre\n"
		for _, line := range r.Pack.PreInst {
			data += line + "\n"
		}
		data += "\n"
	}

	if len(r.Pack.PostInst) > 0 {
		data += "%post\n"
		for _, line := range r.Pack.PostInst {
			data += line + "\n"
		}
		data += "\n"
	}

	if len(r.Pack.PreRm) > 0 {
		data += "%preun\n"
		for _, line := range r.Pack.PreRm {
			data += line + "\n"
		}
		data += "\n"
	}

	if len(r.Pack.PostRm) > 0 {
		data += "%postun\n"
		for _, line := range r.Pack.PostRm {
			data += line + "\n"
		}
	}

	err = utils.CreateWrite(path, data)
	if err != nil {
		return
	}

	fmt.Println(data)

	return
}