diff --git a/examples/yap/PKGBUILD b/examples/yap/PKGBUILD index 4a028e3..903bb22 100644 --- a/examples/yap/PKGBUILD +++ b/examples/yap/PKGBUILD @@ -8,9 +8,12 @@ pkgdesc__debian="Package software with ease for Debian" pkgdesc__fedora="Package software with ease for Fedora" pkgdesc__rocky="Package software with ease for Rocky" pkgdesc__ubuntu="Package software with ease for Ubuntu" -maintainer="Example " +maintainer="The Yap Packager " +copyright=( + "2023, The Yap Project " +) arch=('x86_64') -license=('GPLv3') +license=('GPL-3.0-only') section=misc priority=optional url="https://github.com/M0Rf30/${pkgname}" @@ -57,7 +60,7 @@ package() { "${pkgdir}/usr/share/fish/vendor_completions.d/${pkgname}.fish" install -Dm 644 -t \ - "${pkgdir}/usr/share/licenses/${pkgname}/GPL3" LICENSE.md + "${pkgdir}/usr/share/licenses/${pkgname}" LICENSE.md install -Dm 644 -t \ "${pkgdir}/usr/share/doc/${pkgname}" README.md } diff --git a/go.mod b/go.mod index 703c11c..f0c6972 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.19 require ( github.com/cavaliergopher/grab/v3 v3.0.1 + github.com/github/go-spdx/v2 v2.2.0 github.com/go-git/go-git/v5 v5.10.0 github.com/go-playground/validator/v10 v10.16.0 github.com/mholt/archiver/v4 v4.0.0-alpha.8 diff --git a/go.sum b/go.sum index f86f89a..052924c 100644 --- a/go.sum +++ b/go.sum @@ -66,6 +66,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/github/go-spdx/v2 v2.2.0 h1:yBBLMasHA70Ujd35OpL/OjJOWWVNXcJGbars0GinGRI= +github.com/github/go-spdx/v2 v2.2.0/go.mod h1:hMCrsFgT0QnCwn7G8gxy/MxMpy67WgZrwFeISTn0o6w= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= diff --git a/pkg/debian/constants.go b/pkg/dpkg/constants.go similarity index 70% rename from pkg/debian/constants.go rename to pkg/dpkg/constants.go index 57b39a1..60cb48b 100644 --- a/pkg/debian/constants.go +++ b/pkg/dpkg/constants.go @@ -1,4 +1,4 @@ -package debian +package dpkg var buildEnvironmentDeps = []string{ "build-essential", @@ -7,7 +7,7 @@ var buildEnvironmentDeps = []string{ "ca-certificates", } -var DebianArchs = map[string]string{ +var DebArchs = map[string]string{ "any": "all", "x86_64": "amd64", "i686": "386", @@ -21,7 +21,6 @@ const specFile = ` {{- /* Mandatory fields */ -}} Package: {{.PkgName}} Version: {{ if .Epoch}}{{ .Epoch }}:{{ end }}{{.PkgVer}} - {{- if .PreRelease}}~{{ .PreRelease }}{{- end }} {{- if .PkgRel}}-{{ .PkgRel }}{{- end }} Section: {{.Section}} Priority: {{.Priority}} @@ -55,3 +54,19 @@ case $1 in *) exit;; esac ` + +const copyrightFile = `Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: {{.PkgName}} +Upstream-Contact: {{.Maintainer}} +{{- if .URL}} +Source: {{.URL}} +{{- end }} +Files: * +{{- if .Copyright}} +Copyright: {{ range .Copyright}}{{ . }} + {{ end }}{{- end }} +{{- if .License}} +{{- range .License}} +License: {{ . }}{{- end }} +{{- end }} +` diff --git a/pkg/debian/debian.go b/pkg/dpkg/dpkg.go similarity index 77% rename from pkg/debian/debian.go rename to pkg/dpkg/dpkg.go index e675ac1..ba193c5 100644 --- a/pkg/debian/debian.go +++ b/pkg/dpkg/dpkg.go @@ -1,4 +1,4 @@ -package debian +package dpkg import ( "bytes" @@ -16,33 +16,33 @@ import ( "github.com/otiai10/copy" ) -// Debian represents a Debian package. +// Deb represents a Deb package. // // It contains the directory path of the package and the PKGBUILD struct, which // contains the metadata and build instructions for the package. -type Debian struct { +type Deb struct { debDir string PKGBUILD *pkgbuild.PKGBUILD } -// getArch updates the architecture field in the Debian struct. +// getArch updates the architecture field in the Deb struct. // -// It iterates over the architecture values in the PKGBUILD field of the Debian struct -// and replaces them with the corresponding values from the DebianArchs map. -func (d *Debian) getArch() { +// It iterates over the architecture values in the PKGBUILD field of the Deb struct +// and replaces them with the corresponding values from the DebArchs map. +func (d *Deb) getArch() { for index, arch := range d.PKGBUILD.Arch { - d.PKGBUILD.Arch[index] = DebianArchs[arch] + d.PKGBUILD.Arch[index] = DebArchs[arch] } } -// createConfFiles creates the conffiles file in the Debian package. +// createConfFiles creates the conffiles file in the Deb package. // // It iterates over the Backup field of the PKGBUILD struct and adds each name // to the data string. The data string is then written to the conffiles file // located at the debDir path. // // Returns an error if there was a problem creating or writing to the file. -func (d *Debian) createConfFiles() error { +func (d *Deb) createConfFiles() error { var err error if len(d.PKGBUILD.Backup) == 0 { return err @@ -68,11 +68,21 @@ func (d *Debian) createConfFiles() error { return nil } -// createDebconfTemplate creates a Debian package configuration file template. +func (d *Deb) createCopyrightFile() error { + if len(d.PKGBUILD.License) == 0 { + return nil + } + + copyrightFilePath := filepath.Join(d.debDir, "copyright") + + return d.PKGBUILD.CreateSpec(copyrightFilePath, copyrightFile) +} + +// createDebconfTemplate creates a Deb package configuration file template. // // It does not take any parameters. // It returns an error if there was an issue creating the template. -func (d *Debian) createDebconfTemplate() error { +func (d *Deb) createDebconfTemplate() error { var err error if d.PKGBUILD.DebTemplate == "" { return err @@ -89,10 +99,10 @@ func (d *Debian) createDebconfTemplate() error { return nil } -// createDebconfConfig creates a Debian configuration file. +// createDebconfConfig creates a Deb configuration file. // // It takes no parameters and returns an error. -func (d *Debian) createDebconfConfig() error { +func (d *Deb) createDebconfConfig() error { var err error if d.PKGBUILD.DebConfig == "" { return err @@ -109,11 +119,11 @@ func (d *Debian) createDebconfConfig() error { return nil } -// createScripts generates and writes the scripts for the Debian package. +// createScripts generates and writes the scripts for the Deb package. // // It takes no parameters. // It returns an error if there was an issue generating or writing the scripts. -func (d *Debian) createScripts() error { +func (d *Deb) createScripts() error { scripts := map[string]string{ "preinst": d.PKGBUILD.PreInst, "postinst": d.PKGBUILD.PostInst, @@ -147,14 +157,14 @@ func (d *Debian) createScripts() error { return nil } -// dpkgDeb generates Debian package files from the given artifact path. +// dpkgDeb generates Deb package files from the given artifact path. // // It takes a string parameter `artifactPath` which represents the path where the -// Debian package files will be generated. +// Deb package files will be generated. // -// The function returns an error if there was an issue generating the Debian package +// The function returns an error if there was an issue generating the Deb package // files. -func (d *Debian) dpkgDeb(artifactPath string) error { +func (d *Deb) dpkgDeb(artifactPath string) error { var err error for _, arch := range d.PKGBUILD.Arch { @@ -177,11 +187,11 @@ func (d *Debian) dpkgDeb(artifactPath string) error { return nil } -// Prepare prepares the Debian package by installing its dependencies using apt-get. +// Prepare prepares the Deb package by installing its dependencies using apt-get. // // makeDepends: a slice of strings representing the dependencies to be installed. // Returns an error if there was a problem installing the dependencies. -func (d *Debian) Prepare(makeDepends []string) error { +func (d *Deb) Prepare(makeDepends []string) error { args := []string{ "--assume-yes", "install", @@ -195,11 +205,11 @@ func (d *Debian) Prepare(makeDepends []string) error { return nil } -// Strip strips binaries from the Debian package. +// Strip strips binaries from the Deb package. // // It does not take any parameters. // It returns an error if there is any issue during stripping. -func (d *Debian) Strip() error { +func (d *Deb) Strip() error { var err error var tmplBytesBuffer bytes.Buffer @@ -228,15 +238,15 @@ func (d *Debian) Strip() error { return nil } -// Update updates the Debian package list. +// Update updates the Deb package list. // -// It calls the GetUpdates method of the PKGBUILD field of the Debian struct +// It calls the GetUpdates method of the PKGBUILD field of the Deb struct // to retrieve any updates using the "apt-get" command and the "update" argument. // If an error occurs during the update, it is returned. // // Returns: // - error: An error if the update fails. -func (d *Debian) Update() error { +func (d *Deb) Update() error { err := d.PKGBUILD.GetUpdates("apt-get", "update") if err != nil { return err @@ -245,16 +255,16 @@ func (d *Debian) Update() error { return nil } -// createDebResources creates the Debian package resources. +// createDebResources creates the Deb package resources. // -// It creates the necessary directories and files for the Debian package. +// It creates the necessary directories and files for the Deb package. // It also sets the installed size of the package based on the size of the package directory. // It generates the control file for the package. // It creates the scripts for the package. // It creates the debconf template file. // It creates the debconf config file. // It returns an error if any of the operations fail. -func (d *Debian) createDebResources() error { +func (d *Deb) createDebResources() error { d.debDir = filepath.Join(d.PKGBUILD.PackageDir, "DEBIAN") err := utils.ExistsMakeDir(d.debDir) @@ -274,6 +284,11 @@ func (d *Debian) createDebResources() error { return err } + err = d.createCopyrightFile() + if err != nil { + return err + } + err = d.createScripts() if err != nil { return err @@ -292,10 +307,10 @@ func (d *Debian) createDebResources() error { return nil } -// Build builds the Debian package. +// Build builds the Deb package. // // It takes the artifactsPath as a parameter and returns an error if any. -func (d *Debian) Build(artifactsPath string) error { +func (d *Deb) Build(artifactsPath string) error { var err error d.getArch() @@ -329,7 +344,7 @@ func (d *Debian) Build(artifactsPath string) error { return nil } -func (d *Debian) Install(artifactsPath string) error { +func (d *Deb) Install(artifactsPath string) error { var err error for _, arch := range d.PKGBUILD.Arch { @@ -348,11 +363,11 @@ func (d *Debian) Install(artifactsPath string) error { return nil } -// PrepareEnvironment prepares the environment for the Debian package. +// PrepareEnvironment prepares the environment for the Deb package. // // It takes a boolean parameter `golang` which indicates whether or not to set up Go. // It returns an error if there was a problem during the environment preparation. -func (d *Debian) PrepareEnvironment(golang bool) error { +func (d *Deb) PrepareEnvironment(golang bool) error { var err error args := []string{ @@ -373,7 +388,7 @@ func (d *Debian) PrepareEnvironment(golang bool) error { return nil } -func (d *Debian) getRelease() { +func (d *Deb) getRelease() { if d.PKGBUILD.Codename != "" { d.PKGBUILD.PkgRel += d.PKGBUILD.Codename } else { diff --git a/pkg/packer/packer.go b/pkg/packer/packer.go index de5fad0..f490564 100644 --- a/pkg/packer/packer.go +++ b/pkg/packer/packer.go @@ -5,10 +5,10 @@ import ( "github.com/M0Rf30/yap/pkg/apk" "github.com/M0Rf30/yap/pkg/constants" - "github.com/M0Rf30/yap/pkg/debian" + "github.com/M0Rf30/yap/pkg/dpkg" "github.com/M0Rf30/yap/pkg/pacman" "github.com/M0Rf30/yap/pkg/pkgbuild" - "github.com/M0Rf30/yap/pkg/redhat" + "github.com/M0Rf30/yap/pkg/rpm" ) // Packer is the common interface implemented by all package managers. @@ -47,11 +47,11 @@ func GetPackageManager(pkgBuild *pkgbuild.PKGBUILD, distro string) Packer { PKGBUILD: pkgBuild, } case "debian": - return &debian.Debian{ + return &dpkg.Deb{ PKGBUILD: pkgBuild, } case "redhat": - return &redhat.Redhat{ + return &rpm.RPM{ PKGBUILD: pkgBuild, } default: diff --git a/pkg/pkgbuild/pkgbuild.go b/pkg/pkgbuild/pkgbuild.go index cfb8730..eeace5e 100644 --- a/pkg/pkgbuild/pkgbuild.go +++ b/pkg/pkgbuild/pkgbuild.go @@ -10,6 +10,7 @@ import ( "github.com/M0Rf30/yap/pkg/constants" "github.com/M0Rf30/yap/pkg/utils" + "github.com/github/go-spdx/v2/spdxexp" ) // Verbose is a flag to enable verbose output. @@ -23,6 +24,7 @@ type PKGBUILD struct { Backup []string Build string Conflicts []string + Copyright []string DebConfig string DebTemplate string Depends []string @@ -168,8 +170,25 @@ func (pkgBuild *PKGBUILD) Init() { // Validate checks that mandatory items are correctly provided by the PKGBUILD // file. func (pkgBuild *PKGBUILD) Validate() { + var isValid = true + + if !pkgBuild.validateLicense() { + isValid = false + + fmt.Printf("%s%s ❌ :: %sinvalid SPDX license identifier%s\n", + pkgBuild.PkgName, + string(constants.ColorBlue), + string(constants.ColorYellow), + string(constants.ColorWhite)) + + fmt.Println("You can find valid SPDX license identifiers here") + fmt.Println("🌐 https://spdx.org/licenses/") + } + if len(pkgBuild.SourceURI) != len(pkgBuild.HashSums) { - log.Fatalf("%s%s ❌ :: %snumber of sources and hashsums differs%s\n", + isValid = false + + fmt.Printf("%s%s ❌ :: %snumber of sources and hashsums differs%s\n", pkgBuild.PkgName, string(constants.ColorBlue), string(constants.ColorYellow), @@ -177,12 +196,18 @@ func (pkgBuild *PKGBUILD) Validate() { } if pkgBuild.Package == "" { - log.Fatalf("%s%s ❌ :: %smissing package() function%s\n", + isValid = false + + fmt.Printf("%s%s ❌ :: %smissing package() function%s\n", pkgBuild.PkgName, string(constants.ColorBlue), string(constants.ColorYellow), string(constants.ColorWhite)) } + + if !isValid { + os.Exit(1) + } } // mapArrays reads an array name and its content and maps them to the PKGBUILD @@ -191,6 +216,8 @@ func (pkgBuild *PKGBUILD) mapArrays(key string, data any) { switch key { case "arch": pkgBuild.Arch = data.([]string) + case "copyright": + pkgBuild.Copyright = data.([]string) case "license": pkgBuild.License = data.([]string) case "depends": @@ -258,6 +285,7 @@ func (pkgBuild *PKGBUILD) mapVariables(key string, data any) { case "pkgdesc": pkgBuild.PkgDesc = data.(string) case "maintainer": + err = os.Setenv(key, data.(string)) pkgBuild.Maintainer = data.(string) case "section": pkgBuild.Section = data.(string) @@ -295,7 +323,7 @@ func (pkgBuild *PKGBUILD) parseDirective(input string) (string, int, error) { // If there are more than two elements in the split array, return an error. if len(split) != 2 { - return key, 0, fmt.Errorf("pack: Invalid use of '__' directive in '%w'", nil) + return key, 0, fmt.Errorf("invalid use of '__' directive in '%w'", nil) } // If the FullDistroName is empty, return the key and a priority of 0. @@ -346,3 +374,14 @@ func (pkgBuild *PKGBUILD) setMainFolders() { string(constants.ColorYellow)) } } + +// validateLicense validates the license of the PKGBUILD. +// +// It takes no parameters and returns a boolean indicating whether the license +// is valid, and a slice of strings containing any errors encountered during +// validation. +func (pkgBuild *PKGBUILD) validateLicense() bool { + isValid, _ := spdxexp.ValidateLicenses(pkgBuild.License) + + return isValid +} diff --git a/pkg/project/project.go b/pkg/project/project.go index 63ffcd2..90cb973 100644 --- a/pkg/project/project.go +++ b/pkg/project/project.go @@ -87,7 +87,7 @@ func (mpc *MultipleProject) BuildAll() error { } for _, proj := range mpc.Projects { - fmt.Printf("%s🚀 :: %sMaking package: %s%s %s-%s\n", + fmt.Printf("%s🚀 :: %sMaking package: %s\t%s %s-%s\n", string(constants.ColorBlue), string(constants.ColorYellow), string(constants.ColorWhite), diff --git a/pkg/project/project_test.go b/pkg/project/project_test.go index a2c0f2c..19d7ab7 100644 --- a/pkg/project/project_test.go +++ b/pkg/project/project_test.go @@ -20,7 +20,7 @@ pkgdesc__rocky="Http file server written with Go for Rocky" pkgdesc__ubuntu="Http file server written with Go for Ubuntu" maintainer="Example " arch=("all") -license=("GPLv3") +license=("GPL-3.0-only") section="utils" priority="optional" url="https://github.com/M0Rf30/${pkgname}" diff --git a/pkg/redhat/constants.go b/pkg/rpm/constants.go similarity index 97% rename from pkg/redhat/constants.go rename to pkg/rpm/constants.go index 7537bd2..abc981a 100644 --- a/pkg/redhat/constants.go +++ b/pkg/rpm/constants.go @@ -1,4 +1,4 @@ -package redhat +package rpm const ( Communications = "Applications/Communications" @@ -102,6 +102,8 @@ License: CUSTOM {{- if .Maintainer}} Packager: {{.Maintainer}} {{- end }} +{{- if .Copyright}} +Vendor: {{ range .Copyright}}{{ . }}; {{ end }}{{- end }} {{- with .Provides}} Provides: {{join .}} {{- end }} diff --git a/pkg/redhat/redhat.go b/pkg/rpm/rpm.go similarity index 75% rename from pkg/redhat/redhat.go rename to pkg/rpm/rpm.go index ec5745f..98cfda5 100644 --- a/pkg/redhat/redhat.go +++ b/pkg/rpm/rpm.go @@ -1,4 +1,4 @@ -package redhat +package rpm import ( "fmt" @@ -12,13 +12,13 @@ import ( "github.com/otiai10/copy" ) -// Redhat represents a Redhat package. +// RPM represents a RPM package. // // It contains the directory path of the package and the PKGBUILD struct, which // contains the metadata and build instructions for the package. -type Redhat struct { +type RPM struct { PKGBUILD *pkgbuild.PKGBUILD - redhatDir string + RPMDir string buildDir string buildRootDir string rpmsDir string @@ -27,17 +27,17 @@ type Redhat struct { srpmsDir string } -// Build builds the Redhat package. +// Build builds the RPM package. // // It takes the artifactsPath as a parameter and returns an error. -func (r *Redhat) Build(artifactsPath string) error { +func (r *RPM) Build(artifactsPath string) error { r.getArch() r.getGroup() r.getRelease() r.PKGBUILD.PkgDest, _ = filepath.Abs(artifactsPath) - err := utils.RemoveAll(r.redhatDir) + err := utils.RemoveAll(r.RPMDir) if err != nil { return err } @@ -78,13 +78,13 @@ func (r *Redhat) Build(artifactsPath string) error { return nil } -// Install installs the Redhat package to the specified artifacts path. +// Install installs the RPM package to the specified artifacts path. // // It takes the following parameter: // - artifactsPath: The path to the directory where the artifacts are stored. // // It returns an error if there was an issue during the installation process. -func (r *Redhat) Install(artifactsPath string) error { +func (r *RPM) Install(artifactsPath string) error { for _, arch := range r.PKGBUILD.Arch { pkgName := r.PKGBUILD.PkgName + "-" + @@ -109,11 +109,11 @@ func (r *Redhat) Install(artifactsPath string) error { return nil } -// PrepareEnvironment prepares the environment for the Redhat struct. +// PrepareEnvironment prepares the environment for the RPM struct. // // It takes a boolean parameter `golang` which indicates whether or not to set up the Go environment. // It returns an error if there was an issue with the environment preparation. -func (r *Redhat) PrepareEnvironment(golang bool) error { +func (r *RPM) PrepareEnvironment(golang bool) error { var err error args := []string{ @@ -135,11 +135,11 @@ func (r *Redhat) PrepareEnvironment(golang bool) error { return nil } -// Prepare prepares the Redhat instance by installing the required dependencies. +// Prepare prepares the RPM instance by installing the required dependencies. // // makeDepends is a slice of strings representing the dependencies to be installed. // It returns an error if there is any issue during the installation process. -func (r *Redhat) Prepare(makeDepends []string) error { +func (r *RPM) Prepare(makeDepends []string) error { args := []string{ "-y", "install", @@ -153,21 +153,21 @@ func (r *Redhat) Prepare(makeDepends []string) error { return nil } -// Update updates the Redhat object. +// Update updates the RPM object. // // It takes no parameters. // It returns an error. -func (r *Redhat) Update() error { +func (r *RPM) Update() error { return nil } -// getFiles retrieves the files from the Redhat package directory and populates the PKGBUILD.Files field. +// getFiles retrieves the files from the RPM package directory and populates the PKGBUILD.Files field. // // It iterates over the files in the package directory and adds them to the PKGBUILD.Files slice. // It also handles the backup paths specified in the PKGBUILD.Backup field. // // Returns an error if there is any issue while walking the directory or retrieving the files. -func (r *Redhat) getFiles() error { +func (r *RPM) getFiles() error { backup := set.NewSet() paths := set.NewSet() @@ -222,30 +222,30 @@ func (r *Redhat) getFiles() error { return nil } -// getArch updates the architecture values in the Redhat struct. +// getArch updates the architecture values in the RPM struct. // // It does not take any parameters. // It does not return anything. -func (r *Redhat) getArch() { +func (r *RPM) getArch() { for index, arch := range r.PKGBUILD.Arch { r.PKGBUILD.Arch[index] = RPMArchs[arch] } } -// getGroup updates the section of the Redhat struct with the corresponding +// getGroup updates the section of the RPM struct with the corresponding // value from the RPMGroups map. // // No parameters. // No return types. -func (r *Redhat) getGroup() { +func (r *RPM) getGroup() { r.PKGBUILD.Section = RPMGroups[r.PKGBUILD.Section] } -// getRelease updates the release information of the Redhat struct. +// getRelease updates the release information of the RPM struct. // // It appends the RPMDistros[r.PKGBUILD.Distro] and r.PKGBUILD.Codename to // r.PKGBUILD.PkgRel if r.PKGBUILD.Codename is not empty. -func (r *Redhat) getRelease() { +func (r *RPM) getRelease() { if r.PKGBUILD.Codename != "" { r.PKGBUILD.PkgRel = r.PKGBUILD.PkgRel + RPMDistros[r.PKGBUILD.Distro] + @@ -253,23 +253,23 @@ func (r *Redhat) getRelease() { } } -// makeDirs creates the necessary directories for the Redhat struct. +// makeDirs creates the necessary directories for the RPM struct. // // It does not take any parameters. // It returns an error if any directory creation fails. -func (r *Redhat) makeDirs() error { +func (r *RPM) makeDirs() error { var err error - r.redhatDir = filepath.Join(r.PKGBUILD.StartDir, "redhat") - r.buildDir = filepath.Join(r.redhatDir, "BUILD") - r.buildRootDir = filepath.Join(r.redhatDir, "BUILDROOT") - r.rpmsDir = filepath.Join(r.redhatDir, "RPMS") - r.sourcesDir = filepath.Join(r.redhatDir, "SOURCES") - r.specsDir = filepath.Join(r.redhatDir, "SPECS") - r.srpmsDir = filepath.Join(r.redhatDir, "SRPMS") + r.RPMDir = filepath.Join(r.PKGBUILD.StartDir, "RPM") + r.buildDir = filepath.Join(r.RPMDir, "BUILD") + r.buildRootDir = filepath.Join(r.RPMDir, "BUILDROOT") + r.rpmsDir = filepath.Join(r.RPMDir, "RPMS") + r.sourcesDir = filepath.Join(r.RPMDir, "SOURCES") + r.specsDir = filepath.Join(r.RPMDir, "SPECS") + r.srpmsDir = filepath.Join(r.RPMDir, "SRPMS") for _, path := range []string{ - r.redhatDir, + r.RPMDir, r.buildDir, r.buildRootDir, r.rpmsDir, @@ -286,20 +286,20 @@ func (r *Redhat) makeDirs() error { return nil } -// rpmBuild builds an RPM package using the Redhat package manager. +// rpmBuild builds an RPM package using the RPM package manager. // // It executes the 'rpmbuild' command with the necessary options and arguments // to build the RPM package. The package is built using the specified -// specifications file and the resulting package is stored in the Redhat directory. +// specifications file and the resulting package is stored in the RPM directory. // // Returns an error if the 'rpmbuild' command fails to execute or if there // are any errors during the package building process. -func (r *Redhat) rpmBuild() error { +func (r *RPM) rpmBuild() error { err := utils.Exec(r.specsDir, "rpmbuild", "--define", "_topdir "+ - r.redhatDir, + r.RPMDir, "-bb", r.PKGBUILD.PkgName+ ".spec") diff --git a/pkg/source/source.go b/pkg/source/source.go index 672cd62..1198a50 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -70,7 +70,7 @@ func (src *Source) Get() error { return errors.New("unsupported source type") } - if err := src.validate(sourceFilePath); err != nil { + if err := src.validateSource(sourceFilePath); err != nil { return err } @@ -85,11 +85,12 @@ func (src *Source) Get() error { return nil } -// extract is a function that extracts a source file to a specified directory. +// extract extracts the contents of a source file to the specified source +// directory. // -// It takes no parameters. -// It returns an error if there was a problem opening the source file or -// extracting it. +// sourceFilePath: The path to the source file to be extracted. Returns: An +// error if there was a problem opening the source file or extracting its +// contents. func (src *Source) extract(sourceFilePath string) error { dlFile, err := os.Open(filepath.Clean(sourceFilePath)) if err != nil { @@ -200,17 +201,17 @@ func (src *Source) symlinkSources(symlinkSource string) error { return nil } -// validate checks the integrity of the source files. +// validateSource checks the integrity of the source files. // // It takes the source file path as a parameter and returns an error if any. -func (src *Source) validate(sourceFilePath string) error { +func (src *Source) validateSource(sourceFilePath string) error { info, err := os.Stat(sourceFilePath) if err != nil { return fmt.Errorf("failed to open file for hash: %w", err) } if src.Hash == "SKIP" || info.IsDir() { - fmt.Printf("%s:: %sSkip integrity check for %s%s\n", + fmt.Printf("%s:: %sSkip integrity check for %s\t%s\n", string(constants.ColorBlue), string(constants.ColorYellow), string(constants.ColorWhite), @@ -247,7 +248,7 @@ func (src *Source) validate(sourceFilePath string) error { return errors.Wrapf(errors.New("hash verification failed"), src.SourceItemPath) } - fmt.Printf("%s:: %sintegrity check for %s%s\n", + fmt.Printf("%s:: %sintegrity check for %s\t%s\n", string(constants.ColorBlue), string(constants.ColorYellow), string(constants.ColorWhite),