Skip to content

Commit

Permalink
chore: add more compability with previous versions
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed Nov 11, 2024
1 parent 58bbb9f commit 31d22d4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/yap/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ url="https://github.com/M0Rf30/${pkgname}"
makedepends=(
'upx'
)
makedepends__dpkg=(
makedepends__apt=(
'upx-ucl'
)
source=(
Expand Down
2 changes: 1 addition & 1 deletion pkg/apk/apk.go → pkg/abuild/abuild.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apk
package abuild

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion pkg/apk/constants.go → pkg/abuild/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apk
package abuild

var (
APKArchs = map[string]string{
Expand Down
33 changes: 17 additions & 16 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,28 @@ var (
}

DistroToPackageManager = map[string]string{
"almalinux": "rpm",
"almalinux": "yum",
"alpine": "apk",
"amzn": "rpm",
"arch": "makepkg",
"centos": "rpm",
"debian": "dpkg",
"fedora": "rpm",
"linuxmint": "dpkg",
"ol": "rpm",
"opensuse-leap": "rpm",
"pop": "dpkg",
"rhel": "rpm",
"rocky": "rpm",
"ubuntu": "dpkg",
"amzn": "yum",
"arch": "pacman",
"centos": "yum",
"debian": "apt",
"fedora": "yum",
"linuxmint": "apt",
"ol": "yum",
"opensuse-leap": "zypper",
"pop": "apt",
"rhel": "yum",
"rocky": "yum",
"ubuntu": "apt",
}

Packers = [...]string{
"apk",
"dpkg",
"makepkg",
"rpm",
"apt",
"pacman",
"yum",
"zypper",
}

Distros = []string{}
Expand Down
18 changes: 9 additions & 9 deletions pkg/makepkg/makepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/M0Rf30/yap/pkg/utils"
)

// Makepkg represents a package manager for the Makepkg distribution.
// Pkg represents a package manager for the Pkg distribution.
//
// It contains methods for building, installing, and updating packages.
type Makepkg struct {
type Pkg struct {
PKGBUILD *pkgbuild.PKGBUILD
pacmanDir string
}
Expand All @@ -22,7 +22,7 @@ type Makepkg struct {
//
// The method calls the internal pacmanBuild function to perform the actual build process.
// It returns an error if the build process encounters any issues.
func (m *Makepkg) BuildPackage(_ string) error {
func (m *Pkg) BuildPackage(_ string) error {
return m.pacmanBuild()
}

Expand All @@ -32,7 +32,7 @@ func (m *Makepkg) BuildPackage(_ string) error {
// The method initializes the pacmanDir, resolves the package destination, and creates
// the PKGBUILD and post-installation script files if necessary. It returns an error
// if any stem fails.
func (m *Makepkg) PrepareFakeroot(artifactsPath string) error {
func (m *Pkg) PrepareFakeroot(artifactsPath string) error {
m.pacmanDir = m.PKGBUILD.StartDir

m.PKGBUILD.PkgDest, _ = filepath.Abs(artifactsPath)
Expand Down Expand Up @@ -62,7 +62,7 @@ func (m *Makepkg) PrepareFakeroot(artifactsPath string) error {
//
// artifactsPath: the path where the package artifacts are located.
// error: an error if the installation fails.
func (m *Makepkg) Install(artifactsPath string) error {
func (m *Pkg) Install(artifactsPath string) error {
pkgName := m.PKGBUILD.PkgName + "-" +
m.PKGBUILD.PkgVer +
"-" +
Expand All @@ -88,7 +88,7 @@ func (m *Makepkg) Install(artifactsPath string) error {
//
// makeDepends is a slice of strings representing the dependencies to be included.
// It returns an error if there is any issue getting the dependencies.
func (m *Makepkg) Prepare(makeDepends []string) error {
func (m *Pkg) Prepare(makeDepends []string) error {
args := []string{
"-S",
"--noconfirm",
Expand All @@ -101,7 +101,7 @@ func (m *Makepkg) Prepare(makeDepends []string) error {
//
// It takes a boolean parameter `golang` which indicates whether the environment should be prepared for Golang.
// It returns an error if there is any issue in preparing the environment.
func (m *Makepkg) PrepareEnvironment(golang bool) error {
func (m *Pkg) PrepareEnvironment(golang bool) error {
args := []string{
"-S",
"--noconfirm",
Expand All @@ -121,7 +121,7 @@ func (m *Makepkg) PrepareEnvironment(golang bool) error {
//
// It retrieves the updates using the GetUpdates method of the PKGBUILD struct.
// It returns an error if there is any issue during the update process.
func (m *Makepkg) Update() error {
func (m *Pkg) Update() error {
return m.PKGBUILD.GetUpdates("pacman", "-Sy")
}

Expand All @@ -131,6 +131,6 @@ func (m *Makepkg) Update() error {
// The error is returned as is.
// Returns:
// - error: An error if any occurred during the execution of the makepkg command.
func (m *Makepkg) pacmanBuild() error {
func (m *Pkg) pacmanBuild() error {
return utils.Exec(true, m.pacmanDir, "makepkg", "-ef")
}
18 changes: 11 additions & 7 deletions pkg/packer/packer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package packer

import (
"github.com/M0Rf30/yap/pkg/apk"
"github.com/M0Rf30/yap/pkg/abuild"
"github.com/M0Rf30/yap/pkg/constants"
"github.com/M0Rf30/yap/pkg/dpkg"
"github.com/M0Rf30/yap/pkg/makepkg"
Expand Down Expand Up @@ -41,18 +41,22 @@ func GetPackageManager(pkgBuild *pkgbuild.PKGBUILD, distro string) Packer {
pkgManager := constants.DistroToPackageManager[distro]
switch pkgManager {
case "apk":
return &apk.Apk{
return &abuild.Apk{
PKGBUILD: pkgBuild,
}
case "makepkg":
return &makepkg.Makepkg{
case "apt":
return &dpkg.Deb{
PKGBUILD: pkgBuild,
}
case "dpkg":
return &dpkg.Deb{
case "pacman":
return &makepkg.Pkg{
PKGBUILD: pkgBuild,
}
case "yum":
return &rpm.RPM{
PKGBUILD: pkgBuild,
}
case "rpm":
case "zypper":
return &rpm.RPM{
PKGBUILD: pkgBuild,
}
Expand Down

0 comments on commit 31d22d4

Please sign in to comment.