mirror of
https://github.com/EnumeratedDev/bpm-utils.git
synced 2026-09-17 11:26:12 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f84dd4bc3
|
||
|
|
e1daa498e8
|
||
|
|
68ffb7972f
|
||
|
|
9114bb4148
|
||
|
|
5dbdfdd4c1
|
@@ -33,7 +33,7 @@ Creating a package for BPM with these utilities is simple
|
|||||||
bpm-setup -D my_package
|
bpm-setup -D my_package
|
||||||
```
|
```
|
||||||
2) This will create a directory named `my_package` containing all files required for bpm package creation
|
2) This will create a directory named `my_package` containing all files required for bpm package creation
|
||||||
3) You may wish to edit the pkg.info metedata file inside the newly created directory to include dependencies or add/change other information. Here's an example of what a metedata file could look like
|
3) You may wish to edit the info.yml metedata file inside the newly created directory to include dependencies or add/change other information. Here's an example of what a metedata file could look like
|
||||||
```yaml
|
```yaml
|
||||||
name: my_package
|
name: my_package
|
||||||
description: My package's description
|
description: My package's description
|
||||||
@@ -61,9 +61,9 @@ downloads:
|
|||||||
checksum: 9d19c8884cb22a594ba06a4caa6a3088e15ddfd4f3ede8c3b9e8f5cbb5a4a7a8
|
checksum: 9d19c8884cb22a594ba06a4caa6a3088e15ddfd4f3ede8c3b9e8f5cbb5a4a7a8
|
||||||
```
|
```
|
||||||
|
|
||||||
4) If you would like to bundle patches or other files with your package place them in the 'source-files' directory. They will be extracted to the same location as the source.sh file during compilation
|
4) If you would like to bundle patches or other files with your package place them in the 'source-files' directory. They will be extracted to the same location as the recipe.sh file during compilation
|
||||||
5) You now need to edit your source.sh file which contains the compilation instructions for your package, the default source template comments should explain the basic process of compiling your program and how to edit it
|
5) You now need to edit your recipe.sh file which contains the compilation instructions for your package, the default source template comments should explain the basic process of compiling your program and how to edit it
|
||||||
6) When you are done editing your source.sh script run the following command to create a BPM source package archive. You may run the `bpm-package` command with no arguments to get an explanation of what each flag does
|
6) When you are done editing your recipe.sh script run the following command to create a BPM source package archive. You may run the `bpm-package` command with no arguments to get an explanation of what each flag does
|
||||||
```
|
```
|
||||||
bpm-package
|
bpm-package
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
# This is the recipe.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
# This is the recipe.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
# This is the recipe.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
# This is the recipe.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
# This is the recipe.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
# This is the recipe.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
# This is the recipe.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
||||||
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
|
||||||
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
# This function is used for putting downloaded files to the correct location or applying patches
|
# This function is used for putting downloaded files to the correct location or applying patches
|
||||||
prepare() {
|
prepare() {
|
||||||
cd "$BPM_SOURCE"
|
cd "$BPM_SOURCE"
|
||||||
cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
|
cargo fetch --locked --target "$(rustc --print host-tuple)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# The build function is executed in the source directory
|
# The build function is executed in the source directory
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ require (
|
|||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/drone/envsubst v1.0.3 // indirect
|
require (
|
||||||
|
github.com/drone/envsubst v1.0.3 // indirect
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
||||||
|
)
|
||||||
|
|
||||||
replace bpm-utils-shared => ../bpm-utils-shared
|
replace bpm-utils-shared => ../bpm-utils-shared
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
|||||||
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
||||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
|||||||
+50
-45
@@ -26,8 +26,7 @@ var keepCompilationFiles = flag.BoolP("keep", "k", false, "Keep compilation file
|
|||||||
var installDepends = flag.BoolP("depends", "d", false, "Install package dependencies for compilation")
|
var installDepends = flag.BoolP("depends", "d", false, "Install package dependencies for compilation")
|
||||||
var installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
|
var installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
|
||||||
var compilationJobs = flag.IntP("jobs", "j", 0, "Set the amount of concurrent processes to use for source package compilation")
|
var compilationJobs = flag.IntP("jobs", "j", 0, "Set the amount of concurrent processes to use for source package compilation")
|
||||||
var moveToBinaryDir = flag.BoolP("move", "m", false, "Move output packages to the current repository's binary directory")
|
var updateInfo = flag.BoolP("update-info", "u", false, "Update the info.yml file")
|
||||||
var updateInfo = flag.BoolP("update-info", "u", false, "Update the pkg.info file")
|
|
||||||
var signPackage = flag.BoolP("sign", "s", false, "Sign package using GPG")
|
var signPackage = flag.BoolP("sign", "s", false, "Sign package using GPG")
|
||||||
var yesAll = flag.BoolP("yes", "y", false, "Accept all confirmation prompts")
|
var yesAll = flag.BoolP("yes", "y", false, "Accept all confirmation prompts")
|
||||||
|
|
||||||
@@ -44,17 +43,21 @@ func main() {
|
|||||||
if *compile {
|
if *compile {
|
||||||
compilePackage(outputFile)
|
compilePackage(outputFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
|
bpmutilsshared.UpdateDatabases(repo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runChecks() {
|
func runChecks() {
|
||||||
// Check if pkg.info file exists
|
// Check if info.yml file exists
|
||||||
if stat, err := os.Stat("pkg.info"); err != nil || !stat.Mode().IsRegular() {
|
if stat, err := os.Stat("info.yml"); err != nil || !stat.Mode().IsRegular() {
|
||||||
log.Fatalf("Error: pkg.info does not exist or is not a regular file")
|
log.Fatalf("Error: info.yml does not exist or is not a regular file")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if source.sh file exists
|
// Check if recipe.sh file exists
|
||||||
if stat, err := os.Stat("source.sh"); err != nil || !stat.Mode().IsRegular() {
|
if stat, err := os.Stat("recipe.sh"); err != nil || !stat.Mode().IsRegular() {
|
||||||
log.Fatalf("Error: pkg.info does not exist or is not a regular file")
|
log.Fatalf("Error: info.yml does not exist or is not a regular file")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +71,7 @@ func createArchive() string {
|
|||||||
filesToInclude := make([]string, 0)
|
filesToInclude := make([]string, 0)
|
||||||
|
|
||||||
// Include base files
|
// Include base files
|
||||||
filesToInclude = append(filesToInclude, "pkg.info", "source.sh")
|
filesToInclude = append(filesToInclude, "info.yml", "recipe.sh")
|
||||||
|
|
||||||
// Check if non-empty source-files directory exists and include it
|
// Check if non-empty source-files directory exists and include it
|
||||||
if stat, err := os.Stat("source-files"); err == nil && stat.IsDir() {
|
if stat, err := os.Stat("source-files"); err == nil && stat.IsDir() {
|
||||||
@@ -87,13 +90,13 @@ func createArchive() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read pkg.info file
|
// Read info.yml file
|
||||||
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromFile("pkg.info")
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromFile("info.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not read package info: %s", err)
|
log.Fatalf("Error: could not read package info: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update pkg.info file
|
// Update info.yml file
|
||||||
if *updateInfo {
|
if *updateInfo {
|
||||||
// Update download checksums
|
// Update download checksums
|
||||||
for i, download := range pkgInfo.Downloads {
|
for i, download := range pkgInfo.Downloads {
|
||||||
@@ -125,51 +128,56 @@ func createArchive() string {
|
|||||||
log.Fatalf("Could not marshal package info: %s", err)
|
log.Fatalf("Could not marshal package info: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stat pkg.info
|
// Stat info.yml
|
||||||
stat, err := os.Stat("pkg.info")
|
stat, err := os.Stat("info.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not stat pkg.info: %s", err)
|
log.Fatalf("Could not stat info.yml: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write package info back to file
|
// Write package info back to file
|
||||||
err = os.WriteFile("pkg.info", data.Bytes(), stat.Mode().Perm())
|
err = os.WriteFile("info.yml", data.Bytes(), stat.Mode().Perm())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not write package info to pkg.info: %s", err)
|
log.Fatalf("Could not write package info to info.yml: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove old BPM archives in current directory
|
// Remove old package from source dir
|
||||||
oldArchives, err := filepath.Glob("*.bpm")
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
if err != nil {
|
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb")); err == nil {
|
||||||
log.Printf("Warning: could not search for old BPM archives: %s", err)
|
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
||||||
}
|
pkgFilepath := path.Join(repo, "source", entry.Filepath)
|
||||||
for _, bpmArchive := range oldArchives {
|
err := os.Remove(pkgFilepath)
|
||||||
err = os.Remove(bpmArchive)
|
if err != nil {
|
||||||
if err != nil {
|
log.Printf("Warning: could not remove old source package (%s): %s", pkgFilepath, err)
|
||||||
log.Printf("Warning: could not remove old BPM archive (%s): %s", bpmArchive, err)
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove old BPM archive signatures in current directory
|
// Remove package signature
|
||||||
oldSignatures, err := filepath.Glob("*.sig")
|
if _, err := os.Stat(pkgFilepath + ".sig"); err == nil {
|
||||||
if err != nil {
|
err := os.Remove(pkgFilepath + ".sig")
|
||||||
log.Printf("Warning: could not search for old BPM archive signatures: %s", err)
|
if err != nil {
|
||||||
}
|
log.Printf("Warning: could not remove old source package signature (%s): %s", pkgFilepath+".str", err)
|
||||||
for _, signature := range oldSignatures {
|
}
|
||||||
err = os.Remove(signature)
|
}
|
||||||
if err != nil {
|
}
|
||||||
log.Printf("Warning: could not remove old BPM archive signature (%s): %s", signature, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create filename
|
// Create filename
|
||||||
filename := fmt.Sprintf("%s-%s-%d-%s-src.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision, pkgInfo.Arch)
|
filename := fmt.Sprintf("%s-%s-%d-%s-src.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision, pkgInfo.Arch)
|
||||||
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
|
// Create source directory
|
||||||
|
os.MkdirAll(path.Join(repo, "source", pkgInfo.Arch), 0755)
|
||||||
|
|
||||||
|
filename = path.Join(repo, "source", pkgInfo.Arch, filename)
|
||||||
|
}
|
||||||
|
|
||||||
// Create archive using tar
|
// Create archive using tar
|
||||||
args := make([]string, 0)
|
cmd := exec.Command("tar", "cf", filename,
|
||||||
args = append(args, "-c", "--owner=0", "--group=0", "--no-same-owner", "-f", filename)
|
"--sort=name",
|
||||||
args = append(args, filesToInclude...)
|
"--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime",
|
||||||
cmd := exec.Command("tar", args...)
|
"--mtime=UTC 1970-01-01",
|
||||||
|
"--owner=0", "--group=0", "--numeric-owner")
|
||||||
|
cmd.Args = append(cmd.Args, filesToInclude...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
@@ -263,7 +271,7 @@ func compilePackage(archive string) {
|
|||||||
// Read generated package info
|
// Read generated package info
|
||||||
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
||||||
|
|
||||||
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
|
if repo := bpmutilsshared.GetRepository(); repo != "" {
|
||||||
// Remove old package from binary dir
|
// Remove old package from binary dir
|
||||||
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb")); err == nil {
|
if database, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb")); err == nil {
|
||||||
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
if entry, ok := database.Entries[pkgInfo.Name]; ok {
|
||||||
@@ -296,9 +304,6 @@ func compilePackage(archive string) {
|
|||||||
outputPkgs[pkgInfo.Name] = line
|
outputPkgs[pkgInfo.Name] = line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
|
|
||||||
bpmutilsshared.UpdateDatabases(repo)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign package
|
// Sign package
|
||||||
if *signPackage {
|
if *signPackage {
|
||||||
|
|||||||
+4
-1
@@ -8,6 +8,9 @@ require (
|
|||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/drone/envsubst v1.0.3 // indirect
|
require (
|
||||||
|
github.com/drone/envsubst v1.0.3 // indirect
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
||||||
|
)
|
||||||
|
|
||||||
replace bpm-utils-shared => ../bpm-utils-shared
|
replace bpm-utils-shared => ../bpm-utils-shared
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
|||||||
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
||||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
|||||||
+171
-80
@@ -147,7 +147,7 @@ func createRepository(name, description string) {
|
|||||||
log.Fatalf("Error: could not write to file: %s", err)
|
log.Fatalf("Error: could not write to file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Mkdir(path.Join(name, "source"), 0755)
|
err = os.Mkdir(path.Join(name, "recipes"), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create directory: %s", err)
|
log.Fatalf("Error: could not create directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -185,15 +185,15 @@ func checkVersionsFunc(repo string) {
|
|||||||
directories := make([]string, 0)
|
directories := make([]string, 0)
|
||||||
if currentFlagSet.NArg() > 0 {
|
if currentFlagSet.NArg() > 0 {
|
||||||
for _, dir := range currentFlagSet.Args() {
|
for _, dir := range currentFlagSet.Args() {
|
||||||
if _, err := os.Stat(path.Join(repo, "source", dir, "pkg.info")); err != nil {
|
if _, err := os.Stat(path.Join(repo, "recipes", dir, "info.yml")); err != nil {
|
||||||
log.Fatalf("Error: could not find pkg.info file in directory (%s): %s", dir, err)
|
log.Fatalf("Error: could not find info.yml file in directory (%s): %s", dir, err)
|
||||||
}
|
}
|
||||||
directories = append(directories, path.Join(repo, "source", dir))
|
directories = append(directories, path.Join(repo, "recipes", dir))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Loop through each directory with a 'pkg.info' file
|
// Loop through each directory with a 'info.yml' file
|
||||||
err := filepath.Walk(path.Join(repo, "source"), func(path string, info fs.FileInfo, err error) error {
|
err := filepath.Walk(path.Join(repo, "recipes"), func(path string, info fs.FileInfo, err error) error {
|
||||||
if filepath.Base(path) == "pkg.info" {
|
if filepath.Base(path) == "info.yml" {
|
||||||
directories = append(directories, filepath.Dir(path))
|
directories = append(directories, filepath.Dir(path))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -212,7 +212,7 @@ func checkVersionsFunc(repo string) {
|
|||||||
}, 0)
|
}, 0)
|
||||||
pkgsUpToDate := 0
|
pkgsUpToDate := 0
|
||||||
for _, dir := range directories {
|
for _, dir := range directories {
|
||||||
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromFile(path.Join(dir, "pkg.info"))
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromFile(path.Join(dir, "info.yml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not read package info: %s", err)
|
log.Fatalf("Could not read package info: %s", err)
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ func checkVersionsFunc(repo string) {
|
|||||||
encoder.Encode(pkgInfo)
|
encoder.Encode(pkgInfo)
|
||||||
|
|
||||||
// Write package information
|
// Write package information
|
||||||
err := os.WriteFile(path.Join(dir, "pkg.info"), data.Bytes(), 0644)
|
err := os.WriteFile(path.Join(dir, "info.yml"), data.Bytes(), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Warning: could not write new version for package (%s) to file: %s", pkgInfo.Name, err)
|
log.Printf("Warning: could not write new version for package (%s) to file: %s", pkgInfo.Name, err)
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,11 @@ func checkVersionsFunc(repo string) {
|
|||||||
keys := slices.Collect(maps.Keys(pkgsWithUpdates))
|
keys := slices.Collect(maps.Keys(pkgsWithUpdates))
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
for _, pkg := range keys {
|
for _, pkg := range keys {
|
||||||
fmt.Printf("Update available for package (%s): %s -> %s", pkg, pkgsWithUpdates[pkg].OldVersion, pkgsWithUpdates[pkg].NewVersion)
|
if bpmutilsshared.CompareVersions(pkgsWithUpdates[pkg].NewVersion, pkgsWithUpdates[pkg].OldVersion) >= 0 {
|
||||||
|
fmt.Printf("Update available for package (%s): %s -> %s", pkg, pkgsWithUpdates[pkg].OldVersion, pkgsWithUpdates[pkg].NewVersion)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Downgrade(?) available for package (%s): %s -> %s", pkg, pkgsWithUpdates[pkg].OldVersion, pkgsWithUpdates[pkg].NewVersion)
|
||||||
|
}
|
||||||
if cachedVersions[pkg].OnHold {
|
if cachedVersions[pkg].OnHold {
|
||||||
fmt.Print(" (On hold)")
|
fmt.Print(" (On hold)")
|
||||||
}
|
}
|
||||||
@@ -375,8 +379,8 @@ func holdPackage(repo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure package exists
|
// Ensure package exists
|
||||||
if _, err := os.Stat(path.Join(repo, "source", pkgName, "pkg.info")); err != nil {
|
if _, err := os.Stat(path.Join(repo, "recipes", pkgName, "info.yml")); err != nil {
|
||||||
log.Fatalf("Error: could not find pkg.info file in directory (%s): %s", pkgName, err)
|
log.Fatalf("Error: could not find info.yml file in directory (%s): %s", pkgName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read version cache
|
// Read version cache
|
||||||
@@ -435,44 +439,40 @@ func holdPackage(repo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listPackagesFunc(repo string) {
|
func listPackagesFunc(repo string) {
|
||||||
|
// Read package recipes
|
||||||
|
pkgs := bpmutilsshared.ReadRepositoryRecipes(repo)
|
||||||
|
|
||||||
// Read databases
|
// Read databases
|
||||||
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
sourceDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
||||||
if err != nil {
|
binaryDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
binaryDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
for _, pkg := range pkgs {
|
||||||
if err != nil {
|
fmt.Printf("%s (%s):\n", pkg.Name, pkg.Version)
|
||||||
binaryDatabase = &bpmutilsshared.BPMDatabase{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort database entries
|
// Show source package version
|
||||||
entriesSorted := slices.Collect(maps.Values(sourceDatabase.Entries))
|
if sourceDatabase != nil {
|
||||||
sort.Slice(entriesSorted, func(i, j int) bool {
|
if entry, ok := sourceDatabase.Entries[pkg.Name]; ok {
|
||||||
return entriesSorted[i].PackageInfo.Name < entriesSorted[j].PackageInfo.Name
|
if entry.PackageInfo.Version == pkg.Version {
|
||||||
})
|
fmt.Printf(" Source package: %s\n", entry.PackageInfo.Version)
|
||||||
|
} else {
|
||||||
// Loop through each entry
|
fmt.Printf(" Source package: %s ≠ %s (Version mismatch)\n", entry.PackageInfo.Version, pkg.Version)
|
||||||
for _, entry := range entriesSorted {
|
|
||||||
if len(entry.PackageInfo.SplitPackages) > 0 {
|
|
||||||
for _, splitPkg := range entry.PackageInfo.SplitPackages {
|
|
||||||
// Handle split packages
|
|
||||||
additionalText := ""
|
|
||||||
if binaryEntry, ok := binaryDatabase.Entries[splitPkg.Name]; !ok {
|
|
||||||
additionalText += "(Binary package missing) "
|
|
||||||
} else if fmt.Sprintf("%s-%d", binaryEntry.PackageInfo.Version, binaryEntry.PackageInfo.Revision) != fmt.Sprintf("%s-%d", entry.PackageInfo.Version, entry.PackageInfo.Revision) {
|
|
||||||
additionalText += "(Binary package version mismatch) "
|
|
||||||
}
|
}
|
||||||
fmt.Printf("%s %s-%d %s\n", splitPkg.Name, entry.PackageInfo.Version, entry.PackageInfo.Revision, additionalText)
|
} else {
|
||||||
|
fmt.Println(" Source package not found!")
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
additionalText := ""
|
|
||||||
if binaryEntry, ok := binaryDatabase.Entries[entry.PackageInfo.Name]; !ok {
|
// Show binary package version
|
||||||
additionalText += "(Binary package missing) "
|
if binaryDatabase != nil {
|
||||||
} else if fmt.Sprintf("%s-%d", binaryEntry.PackageInfo.Version, binaryEntry.PackageInfo.Revision) != fmt.Sprintf("%s-%d", entry.PackageInfo.Version, entry.PackageInfo.Revision) {
|
if entry, ok := binaryDatabase.Entries[pkg.Name]; ok {
|
||||||
additionalText += "(Binary package version mismatch) "
|
if entry.PackageInfo.Version == pkg.Version {
|
||||||
|
fmt.Printf(" Binary package: %s\n", entry.PackageInfo.Version)
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" Binary package: %s ≠ %s (Version mismatch)\n", entry.PackageInfo.Version, pkg.Version)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println(" Binary package not found!")
|
||||||
}
|
}
|
||||||
fmt.Printf("%s %s-%d %s\n", entry.PackageInfo.Name, entry.PackageInfo.Version, entry.PackageInfo.Revision, additionalText)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,31 +489,33 @@ func compileAllPackagesFunc(repo string) {
|
|||||||
log.Fatalf("Error: failed to read config: %s", err)
|
log.Fatalf("Error: failed to read config: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure database is updated
|
// Read package recipes
|
||||||
bpmutilsshared.UpdateDatabases(repo)
|
pkgs := bpmutilsshared.ReadRepositoryRecipes(repo)
|
||||||
|
pkgsMap := make(map[string]bpmutilsshared.PackageInfo)
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
pkgsMap[pkg.Name] = pkg
|
||||||
|
|
||||||
|
// Add split packages
|
||||||
|
for _, splitPkg := range pkg.SplitPackages {
|
||||||
|
if _, ok := pkgsMap[splitPkg.Name]; !ok {
|
||||||
|
pkgsMap[splitPkg.Name] = pkg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Read databases
|
// Read databases
|
||||||
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error: could not read source database: %s", err)
|
|
||||||
}
|
|
||||||
binaryDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
binaryDatabase, _ := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
|
||||||
|
|
||||||
// Get all packages from database entries
|
|
||||||
packages := slices.Collect(maps.Values(sourceDatabase.Entries))
|
|
||||||
sort.Slice(packages, func(a, b int) bool {
|
|
||||||
return packages[a].PackageInfo.Name < packages[b].PackageInfo.Name
|
|
||||||
})
|
|
||||||
|
|
||||||
// Toposort packages using Depth-first search algorithm
|
// Toposort packages using Depth-first search algorithm
|
||||||
sorted := make([]bpmutilsshared.PackageInfo, 0)
|
sorted := make([]bpmutilsshared.PackageInfo, 0)
|
||||||
marked := make(map[string]int) // 0 = Unmarked, 1 = Temporary mark, 2 = Permanent mark
|
marked := make(map[string]int) // 0 = Unmarked, 1 = Temporary mark, 2 = Permanent mark
|
||||||
var visit func(pkgInfo *bpmutilsshared.PackageInfo) error
|
var visit func(pkgInfo bpmutilsshared.PackageInfo) error
|
||||||
visit = func(pkgInfo *bpmutilsshared.PackageInfo) error {
|
visit = func(pkgInfo bpmutilsshared.PackageInfo) error {
|
||||||
if mark, _ := marked[pkgInfo.Name]; mark == 2 {
|
if mark, _ := marked[pkgInfo.Name]; mark == 2 {
|
||||||
return nil
|
return nil
|
||||||
} else if mark == 1 {
|
} else if mark == 1 {
|
||||||
return fmt.Errorf("Circular dependency found!")
|
return fmt.Errorf("circular dependency found")
|
||||||
}
|
}
|
||||||
|
|
||||||
marked[pkgInfo.Name] = 1
|
marked[pkgInfo.Name] = 1
|
||||||
@@ -523,47 +525,134 @@ func compileAllPackagesFunc(repo string) {
|
|||||||
depends = append(depends, pkgInfo.MakeDepends...)
|
depends = append(depends, pkgInfo.MakeDepends...)
|
||||||
|
|
||||||
for _, depend := range depends {
|
for _, depend := range depends {
|
||||||
|
dependName, _, _ := bpmutilsshared.SplitPkgNameAndVersion(depend)
|
||||||
|
|
||||||
// Find package in repository
|
// Find package in repository
|
||||||
dependEntry, ok := sourceDatabase.Entries[depend]
|
dependInfo, ok := pkgsMap[dependName]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
// Search for virtual package
|
// Search for virtual package
|
||||||
for _, entry := range sourceDatabase.Entries {
|
for _, pkg := range pkgsMap {
|
||||||
if slices.Contains(entry.PackageInfo.Provides, depend) {
|
if slices.Contains(pkg.Provides, dependName) {
|
||||||
dependEntry = entry
|
dependInfo = pkg
|
||||||
ok = true
|
ok = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// Try to see if package exists in BPM's other repositories
|
||||||
|
err := exec.Command("bpm", "query", "-d", depend).Run()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not find package (%s) in any database", depend)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := visit(dependEntry.PackageInfo)
|
err := visit(dependInfo)
|
||||||
if err != nil && verbose {
|
if err != nil {
|
||||||
fmt.Printf("Circular dependency found! (%s -> %s)\n", pkgInfo.Name, dependEntry.PackageInfo.Name)
|
if strings.Contains(err.Error(), "circular") {
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Circular dependency found! (%s -> %s)\n", pkgInfo.Name, dependInfo.Name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Fatalf("Error: could not resolve dependencies: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
marked[pkgInfo.Name] = 2
|
marked[pkgInfo.Name] = 2
|
||||||
sorted = append(sorted, *pkgInfo)
|
sorted = append(sorted, pkgInfo)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range packages {
|
for _, pkg := range pkgs {
|
||||||
if mark, _ := marked[entry.PackageInfo.Name]; mark != 2 {
|
if mark, _ := marked[pkg.Name]; mark != 2 {
|
||||||
visit(entry.PackageInfo)
|
visit(pkg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile all packages in order
|
// Compile all packages in order
|
||||||
for _, pkgInfo := range sorted {
|
for _, pkgInfo := range sorted {
|
||||||
if modifiedOnly && binaryDatabase != nil {
|
skip := false
|
||||||
if binaryPkgInfo, ok := binaryDatabase.Entries[pkgInfo.Name]; ok && binaryPkgInfo.PackageInfo.GetFullVersion() == pkgInfo.GetFullVersion() {
|
|
||||||
continue
|
if modifiedOnly {
|
||||||
|
skip = true
|
||||||
|
|
||||||
|
// Check if required version is valid
|
||||||
|
for _, depend := range pkgInfo.Depends {
|
||||||
|
if !strings.ContainsRune(depend, '=') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dependName, _, _ := bpmutilsshared.SplitPkgNameAndVersion(depend)
|
||||||
|
|
||||||
|
if !bpmutilsshared.EvaluateDependency(depend, pkgsMap[dependName].Version) {
|
||||||
|
skip = false
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
for _, depend := range pkgInfo.MakeDepends {
|
||||||
|
if !strings.ContainsRune(depend, '=') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dependName, _, _ := bpmutilsshared.SplitPkgNameAndVersion(depend)
|
||||||
|
|
||||||
|
if !bpmutilsshared.EvaluateDependency(depend, pkgsMap[dependName].Version) {
|
||||||
|
skip = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if source database entry is not synced
|
||||||
|
if sourceDatabase != nil {
|
||||||
|
if len(pkgInfo.SplitPackages) != 0 {
|
||||||
|
sourcePkgInfo, ok := sourceDatabase.Entries[pkgInfo.Name]
|
||||||
|
if ok {
|
||||||
|
hasSplitPkg := func(name string) bool {
|
||||||
|
return slices.ContainsFunc(sourcePkgInfo.PackageInfo.SplitPackages, func(splitPkg *bpmutilsshared.PackageInfo) bool {
|
||||||
|
return name == splitPkg.Name
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, splitPkg := range pkgInfo.SplitPackages {
|
||||||
|
if !hasSplitPkg(splitPkg.Name) || sourcePkgInfo.PackageInfo.GetFullVersion() != pkgInfo.GetFullVersion() {
|
||||||
|
skip = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
skip = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if sourcePkgInfo, ok := sourceDatabase.Entries[pkgInfo.Name]; !ok || sourcePkgInfo.PackageInfo.GetFullVersion() != pkgInfo.GetFullVersion() {
|
||||||
|
skip = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if binary database entry is not synced
|
||||||
|
if binaryDatabase != nil {
|
||||||
|
if len(pkgInfo.SplitPackages) != 0 {
|
||||||
|
for _, splitPkg := range pkgInfo.SplitPackages {
|
||||||
|
if binaryPkgInfo, ok := binaryDatabase.Entries[splitPkg.Name]; !ok || binaryPkgInfo.PackageInfo.GetFullVersion() != pkgInfo.GetFullVersion() {
|
||||||
|
skip = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if binaryPkgInfo, ok := binaryDatabase.Entries[pkgInfo.Name]; !ok || binaryPkgInfo.PackageInfo.GetFullVersion() != pkgInfo.GetFullVersion() {
|
||||||
|
skip = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if skip {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if showOrder {
|
if showOrder {
|
||||||
@@ -581,23 +670,25 @@ func compileAllPackagesFunc(repo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compile source package
|
// Compile source package
|
||||||
cmd = exec.Command("bpm-package", "-cdvusmy")
|
cmd = exec.Command("bpm-package", "-cdusy")
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Dir = path.Join(repo, "source", pkgInfo.Name)
|
cmd.Dir = path.Join(repo, "recipes", pkgInfo.Name)
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
log.Fatalf("Error: could not compile package (%s): %s", pkgInfo.Name, err)
|
log.Fatalf("Error: could not compile package (%s): %s", pkgInfo.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure installed packages are up-to-date
|
// Ensure installed packages are up-to-date
|
||||||
cmd := exec.Command(config.PrivilegeEscalatorCmd, "sh", "-c", "bpm u -y")
|
if !showOrder {
|
||||||
cmd.Stdin = os.Stdin
|
cmd := exec.Command(config.PrivilegeEscalatorCmd, "sh", "-c", "bpm u -y")
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stdout = os.Stdout
|
||||||
if err := cmd.Run(); err != nil {
|
cmd.Stderr = os.Stderr
|
||||||
log.Fatalf("Error: could not update packages): %s", err)
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Fatalf("Error: could not update packages): %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ require (
|
|||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/drone/envsubst v1.0.3 // indirect
|
require (
|
||||||
|
github.com/drone/envsubst v1.0.3 // indirect
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
||||||
|
)
|
||||||
|
|
||||||
replace bpm-utils-shared => ../bpm-utils-shared
|
replace bpm-utils-shared => ../bpm-utils-shared
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
|||||||
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
||||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
|||||||
+41
-28
@@ -10,14 +10,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var directory = flag.StringP("directory", "D", "", "Path to package directory")
|
|
||||||
var name = flag.StringP("name", "n", "", "Set the package name")
|
var name = flag.StringP("name", "n", "", "Set the package name")
|
||||||
var description = flag.StringP("description", "d", "Default Package Description", "Set the description")
|
var description = flag.StringP("description", "d", "Default Package Description", "Set the description")
|
||||||
var version = flag.StringP("version", "v", "1.0", "Set the package version")
|
var version = flag.StringP("version", "v", "1.0", "Set the package version")
|
||||||
@@ -26,20 +24,35 @@ var license = flag.StringP("license", "l", "", "Set the package licenses")
|
|||||||
var template = flag.StringP("template", "t", "gnu-configure", "Set the package template")
|
var template = flag.StringP("template", "t", "gnu-configure", "Set the package template")
|
||||||
var git = flag.BoolP("git", "g", true, "Create git repository")
|
var git = flag.BoolP("git", "g", true, "Create git repository")
|
||||||
|
|
||||||
|
var directory = ""
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Setup flags and help
|
// Setup flags and help
|
||||||
setupFlagsAndHelp("bpm-setup <options>", "Sets up files and directories for BPM source package creation")
|
setupFlagsAndHelp("bpm-setup <options>", "Sets up files and directories for BPM source package creation")
|
||||||
|
|
||||||
|
// Trim package name
|
||||||
|
*name = strings.TrimSpace(*name)
|
||||||
|
|
||||||
// Show command help if no directory name is given
|
// Show command help if no directory name is given
|
||||||
if *directory == "" {
|
if *name == "" {
|
||||||
log.Println("Error: directory flag is required")
|
log.Println("Error: name flag is required")
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set package name to directory name if empty
|
// Get current repository
|
||||||
if *name == "" {
|
repo := bpmutilsshared.GetRepository()
|
||||||
*name = filepath.Base(*directory)
|
|
||||||
|
// Set directory
|
||||||
|
if repo != "" {
|
||||||
|
directory = path.Join(repo, "recipes", *name)
|
||||||
|
} else {
|
||||||
|
workDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error: could not get working directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
directory = path.Join(workDir, *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// run checks
|
// run checks
|
||||||
@@ -62,25 +75,29 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runChecks() {
|
func runChecks() {
|
||||||
if strings.TrimSpace(*directory) == "" {
|
// Check if package name is valid
|
||||||
log.Fatalf("No directory was specified!")
|
if *name == "" {
|
||||||
|
log.Fatalf("Error: no package name was specified!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.TrimSpace(*name) == "" {
|
// Check if parent directory is valid
|
||||||
log.Fatalf("No package name was specified!")
|
if _, err := os.Stat(path.Dir(directory)); err != nil {
|
||||||
|
log.Fatalf("Error: %s is not a valid directory: %s", path.Dir(directory), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if package directory exists
|
||||||
|
if _, err := os.Stat(directory); err == nil {
|
||||||
|
log.Fatalf("Error: %s already exists", directory)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if template file is valid
|
||||||
if stat, err := os.Stat(path.Join("/etc/bpm-utils/templates/", *template)); err != nil || stat.IsDir() {
|
if stat, err := os.Stat(path.Join("/etc/bpm-utils/templates/", *template)); err != nil || stat.IsDir() {
|
||||||
log.Fatalf("%s is not a valid template file!", *template)
|
log.Fatalf("Error: '%s' is not a valid template file!", *template)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func showSummary() {
|
func showSummary() {
|
||||||
absPath, err := filepath.Abs(strings.TrimSpace(*directory))
|
fmt.Printf("Setting up package directory at %s with the following information:\n", directory)
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to determine absolute path: %s", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Setting up package directory at %s with the following information:\n", absPath)
|
|
||||||
fmt.Printf("Package name: %s\n", strings.TrimSpace(*name))
|
fmt.Printf("Package name: %s\n", strings.TrimSpace(*name))
|
||||||
fmt.Printf("Package description: %s\n", *description)
|
fmt.Printf("Package description: %s\n", *description)
|
||||||
fmt.Printf("Package version: %s\n", *version)
|
fmt.Printf("Package version: %s\n", *version)
|
||||||
@@ -114,12 +131,8 @@ func createDirectory() {
|
|||||||
log.Fatalf("Error: failed to read config: %s", err)
|
log.Fatalf("Error: failed to read config: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim spaces
|
|
||||||
*directory = strings.TrimSpace(*directory)
|
|
||||||
*name = strings.TrimSpace(*name)
|
|
||||||
|
|
||||||
// Create directory
|
// Create directory
|
||||||
err = os.Mkdir(*directory, 0755)
|
err = os.Mkdir(directory, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create directory: %s", err)
|
log.Fatalf("Error: could not create directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -153,13 +166,13 @@ func createDirectory() {
|
|||||||
encoder.Encode(&pkgInfo)
|
encoder.Encode(&pkgInfo)
|
||||||
|
|
||||||
// Write package info to file
|
// Write package info to file
|
||||||
err = os.WriteFile(path.Join(*directory, "pkg.info"), buffer.Bytes(), 0644)
|
err = os.WriteFile(path.Join(directory, "info.yml"), buffer.Bytes(), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not write to pkg.info: %s", err)
|
log.Fatalf("Could not write to info.yml: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create source-files directory
|
// Create source-files directory
|
||||||
err = os.Mkdir(path.Join(*directory, "source-files"), 0755)
|
err = os.Mkdir(path.Join(directory, "source-files"), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create directory: %s", err)
|
log.Fatalf("Error: could not create directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -174,7 +187,7 @@ func createDirectory() {
|
|||||||
// Replace variables in template file
|
// Replace variables in template file
|
||||||
input = []byte(replaceVariables(string(input)))
|
input = []byte(replaceVariables(string(input)))
|
||||||
|
|
||||||
err = os.WriteFile(path.Join(*directory, "source.sh"), input, 0644)
|
err = os.WriteFile(path.Join(directory, "recipe.sh"), input, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not write to source file: %s", err)
|
log.Fatalf("Error: could not write to source file: %s", err)
|
||||||
return
|
return
|
||||||
@@ -182,7 +195,7 @@ func createDirectory() {
|
|||||||
|
|
||||||
// Create git repository
|
// Create git repository
|
||||||
if git != nil && *git {
|
if git != nil && *git {
|
||||||
err = exec.Command("git", "init", *directory).Run()
|
err = exec.Command("git", "init", directory).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not initialize git repository: %s", err)
|
log.Fatalf("Error: could not initialize git repository: %s", err)
|
||||||
}
|
}
|
||||||
@@ -193,7 +206,7 @@ func createDirectory() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer defaultGitignoreFile.Close()
|
defer defaultGitignoreFile.Close()
|
||||||
newGitignoreFile, err := os.OpenFile(path.Join(*directory, ".gitignore"), os.O_CREATE|os.O_WRONLY, 0644)
|
newGitignoreFile, err := os.OpenFile(path.Join(directory, ".gitignore"), os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not create .gitignore file: %s", err)
|
log.Fatalf("Error: could not create .gitignore file: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func GenerateDatabase(path string) error {
|
|||||||
|
|
||||||
// Get package installed size
|
// Get package installed size
|
||||||
if entry.PackageInfo.Type == "binary" {
|
if entry.PackageInfo.Type == "binary" {
|
||||||
cmd := exec.Command("tar", "xf", packagePath, "pkg.files", "-O")
|
cmd := exec.Command("tar", "xf", packagePath, "files.txt", "-O")
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -85,7 +85,7 @@ func GenerateDatabase(path string) error {
|
|||||||
}
|
}
|
||||||
stringEntry := strings.Split(line, " ")
|
stringEntry := strings.Split(line, " ")
|
||||||
if len(stringEntry) < 5 {
|
if len(stringEntry) < 5 {
|
||||||
return fmt.Errorf("pkg.files is not formatted correctly")
|
return fmt.Errorf("files.txt is not formatted correctly")
|
||||||
}
|
}
|
||||||
size, err := strconv.ParseInt(stringEntry[len(stringEntry)-1], 10, 64)
|
size, err := strconv.ParseInt(stringEntry[len(stringEntry)-1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ go 1.23
|
|||||||
require gopkg.in/yaml.v3 v3.0.1
|
require gopkg.in/yaml.v3 v3.0.1
|
||||||
|
|
||||||
require github.com/drone/envsubst v1.0.3
|
require github.com/drone/envsubst v1.0.3
|
||||||
|
|
||||||
|
require github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
|||||||
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
||||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/drone/envsubst"
|
"github.com/drone/envsubst"
|
||||||
|
version "github.com/knqyf263/go-rpm-version"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ func (pkgInfo *PackageInfo) GetFullVersion() string {
|
|||||||
|
|
||||||
func ReadPacakgeInfoFromTarball(path string) (*PackageInfo, error) {
|
func ReadPacakgeInfoFromTarball(path string) (*PackageInfo, error) {
|
||||||
// Extract package info using tar
|
// Extract package info using tar
|
||||||
cmd := exec.Command("tar", "-x", "-f", path, "pkg.info", "-O")
|
cmd := exec.Command("tar", "-x", "-f", path, "info.yml", "-O")
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -179,3 +180,69 @@ func (pkgDownload *PackageDownload) CalculateChecksum(pkgInfo *PackageInfo) (str
|
|||||||
return "", fmt.Errorf("unknown download type (%s)", pkgDownload.Type)
|
return "", fmt.Errorf("unknown download type (%s)", pkgDownload.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CompareVersions(version1, version2 string) int {
|
||||||
|
v1 := version.NewVersion(version1)
|
||||||
|
v2 := version.NewVersion(version2)
|
||||||
|
|
||||||
|
return v1.Compare(v2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SplitPkgNameAndVersion(pkg string) (string, string, string) {
|
||||||
|
if strings.Contains(pkg, ">=") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, ">=", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, ">=", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, ">") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, ">", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, ">", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, "<=") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, "<=", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, "<=", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, "<") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, "<", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, "<", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, "=") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, "=", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, "=", pkgVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkg, "", ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func EvaluateDependency(pkg, matchVersion string) bool {
|
||||||
|
_, comparisonSymbol, pkgVersion := SplitPkgNameAndVersion(pkg)
|
||||||
|
|
||||||
|
switch comparisonSymbol {
|
||||||
|
case ">=":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) >= 0
|
||||||
|
case ">":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) > 0
|
||||||
|
case "<=":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) <= 0
|
||||||
|
case "<":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) < 0
|
||||||
|
case "=":
|
||||||
|
if cutPkgVersion, ok := strings.CutSuffix(pkgVersion, "*"); ok {
|
||||||
|
return strings.HasPrefix(matchVersion, cutPkgVersion)
|
||||||
|
} else {
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) == 0
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package bpm_utils_shared
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRepository() string {
|
func GetRepository() string {
|
||||||
@@ -23,3 +24,31 @@ func GetRepository() string {
|
|||||||
}
|
}
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadRepositoryRecipes(repository string) []PackageInfo {
|
||||||
|
// Read package recipes
|
||||||
|
recipeDirs, err := os.ReadDir(path.Join(repository, "recipes"))
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgs := make([]PackageInfo, 0)
|
||||||
|
for _, dir := range recipeDirs {
|
||||||
|
pkgInfoPath := path.Join(repository, "recipes", dir.Name(), "info.yml")
|
||||||
|
if _, err := os.Stat(pkgInfoPath); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgInfo, err := ReadPacakgeInfoFromFile(pkgInfoPath)
|
||||||
|
if err == nil {
|
||||||
|
pkgs = append(pkgs, *pkgInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort package recipes
|
||||||
|
sort.Slice(pkgs, func(i, j int) bool {
|
||||||
|
return pkgs[i].Name < pkgs[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
|
return pkgs
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user