mirror of
https://github.com/EnumeratedDev/bpm-utils.git
synced 2026-09-26 15:36:13 +00:00
Compare commits
7
Commits
9625b5d7af
...
7.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4217626dde
|
||
|
|
d7da13034c | ||
|
|
cdb044d751
|
||
|
|
60b0f4489e
|
||
|
|
65c32d628f
|
||
|
|
4ff4a74fa3
|
||
|
|
f6ef60aa40
|
@@ -0,0 +1,32 @@
|
|||||||
|
# This is the source.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 output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
|
||||||
|
|
||||||
|
# The prepare function is executed in the root of the temp directory
|
||||||
|
# This function is used for putting downloaded files to the correct location or applying patches
|
||||||
|
prepare() {
|
||||||
|
cd "$BPM_SOURCE"
|
||||||
|
# Fetch cargo dependencies
|
||||||
|
cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
|
||||||
|
}
|
||||||
|
|
||||||
|
# The build function is executed in the source directory
|
||||||
|
# This function is used to compile the source code
|
||||||
|
build() {
|
||||||
|
cargo build --release --frozen --workspace
|
||||||
|
}
|
||||||
|
|
||||||
|
# The check function is executed in the source directory
|
||||||
|
# This function is used to run tests to verify the package has been compiled correctly
|
||||||
|
check() {
|
||||||
|
cargo test --frozen
|
||||||
|
}
|
||||||
|
|
||||||
|
# The package function is executed in the source directory
|
||||||
|
# This function is used to move the compiled files into the output directory
|
||||||
|
package() {
|
||||||
|
find target/release -maxdepth 1 -type f -executable -exec install -Dm755 -t "$BPM_OUTPUT"/usr/bin {} +
|
||||||
|
|
||||||
|
# Install package license
|
||||||
|
install -Dm644 "$BPM_SOURCE"/LICENSE "$BPM_OUTPUT"/usr/share/licenses/$NAME/LICENSE
|
||||||
|
}
|
||||||
@@ -169,7 +169,7 @@ func compilePackage(archive string) {
|
|||||||
if *yesAll {
|
if *yesAll {
|
||||||
args = append(args, "-y")
|
args = append(args, "-y")
|
||||||
}
|
}
|
||||||
args = append(args, "--fd=3")
|
args = append(args, "--output-fd=3")
|
||||||
args = append(args, archive)
|
args = append(args, archive)
|
||||||
cmd := exec.Command("bpm", args...)
|
cmd := exec.Command("bpm", args...)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
@@ -208,7 +208,7 @@ func compilePackage(archive string) {
|
|||||||
outputPkgs := make(map[string]string)
|
outputPkgs := make(map[string]string)
|
||||||
for _, line := range strings.Split(strings.TrimSpace(string(cmdOutput)), "\n") {
|
for _, line := range strings.Split(strings.TrimSpace(string(cmdOutput)), "\n") {
|
||||||
// Read generated package info
|
// Read generated package info
|
||||||
pkgInfo, err := bpmutilsshared.ReadPacakgeInfo(line)
|
pkgInfo, err := bpmutilsshared.ReadPacakgeInfoFromTarball(line)
|
||||||
|
|
||||||
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
|
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
|
||||||
// Remove old package from binary dir
|
// Remove old package from binary dir
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
bpmutilsshared "bpm-utils-shared"
|
bpmutilsshared "bpm-utils-shared"
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
@@ -176,6 +177,10 @@ func checkVersionsFunc(repo string) {
|
|||||||
log.Fatalf("Could not read package info: %s", err)
|
log.Fatalf("Could not read package info: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Checking version for package (%s)...\n", pkgInfo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
// Check cached latest version
|
// Check cached latest version
|
||||||
latestVersion := ""
|
latestVersion := ""
|
||||||
if cachedVersion, ok := cachedVersions[pkgInfo.Name]; ok && !force && time.Since(time.UnixMilli(cachedVersion.Timestamp)).Milliseconds() < 604800000 {
|
if cachedVersion, ok := cachedVersions[pkgInfo.Name]; ok && !force && time.Since(time.UnixMilli(cachedVersion.Timestamp)).Milliseconds() < 604800000 {
|
||||||
@@ -188,7 +193,9 @@ func checkVersionsFunc(repo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute check-version.sh script
|
// Execute check-version.sh script
|
||||||
cmd := exec.Command("bash", "-e", path.Join(dir, "check-version.sh"))
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
cmd := exec.CommandContext(ctx, "bash", "-e", path.Join(dir, "check-version.sh"))
|
||||||
cmd.Environ()
|
cmd.Environ()
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -261,6 +268,7 @@ func checkVersionsFunc(repo string) {
|
|||||||
for _, pkg := range pkgsWithoutScript {
|
for _, pkg := range pkgsWithoutScript {
|
||||||
log.Printf("Warning: package (%s) has no check-version.sh script\n", pkg)
|
log.Printf("Warning: package (%s) has no check-version.sh script\n", pkg)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Print errors
|
// Print errors
|
||||||
keys = slices.Collect(maps.Keys(pkgsWithError))
|
keys = slices.Collect(maps.Keys(pkgsWithError))
|
||||||
@@ -268,7 +276,6 @@ func checkVersionsFunc(repo string) {
|
|||||||
for _, pkg := range keys {
|
for _, pkg := range keys {
|
||||||
log.Printf("Error: check-version.sh script for package (%s) failed: %s", pkg, pkgsWithError[pkg])
|
log.Printf("Error: check-version.sh script for package (%s) failed: %s", pkg, pkgsWithError[pkg])
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Print summary
|
// Print summary
|
||||||
fmt.Println("----- Summary -----")
|
fmt.Println("----- Summary -----")
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ func createDirectory() {
|
|||||||
Downloads: []bpmutilsshared.PackageDownload{
|
Downloads: []bpmutilsshared.PackageDownload{
|
||||||
{
|
{
|
||||||
Url: "https://wwww.my-url.com/file.tar.gz",
|
Url: "https://wwww.my-url.com/file.tar.gz",
|
||||||
|
ExtractTo: "${BPM_SOURCE}",
|
||||||
ExtractStripComponents: 1,
|
ExtractStripComponents: 1,
|
||||||
ExtractToBPMSource: true,
|
|
||||||
Checksum: "replaceme",
|
Checksum: "replaceme",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func GenerateDatabase(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get package info
|
// Get package info
|
||||||
entry.PackageInfo, err = ReadPacakgeInfo(packagePath)
|
entry.PackageInfo, err = ReadPacakgeInfoFromTarball(packagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import (
|
|||||||
|
|
||||||
type PackageInfo struct {
|
type PackageInfo struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description,omitempty"`
|
||||||
Version string `yaml:"version"`
|
Version string `yaml:"version,omitempty"`
|
||||||
Revision int `yaml:"revision,omitempty"`
|
Revision int `yaml:"revision,omitempty"`
|
||||||
Url string `yaml:"url,omitempty"`
|
Url string `yaml:"url,omitempty"`
|
||||||
License string `yaml:"license,omitempty"`
|
License string `yaml:"license,omitempty"`
|
||||||
@@ -34,32 +34,23 @@ type PackageInfo struct {
|
|||||||
type PackageDownload struct {
|
type PackageDownload struct {
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
Type string `yaml:"type,omitempty"`
|
Type string `yaml:"type,omitempty"`
|
||||||
NoExtract bool `yaml:"no_extract,omitempty"`
|
|
||||||
ExtractToBPMSource bool `yaml:"extract_to_bpm_source,omitempty"`
|
|
||||||
ExtractStripComponents int `yaml:"extract_strip_components,omitempty"`
|
|
||||||
GitBranch string `yaml:"git_branch,omitempty"`
|
|
||||||
Filepath string `yaml:"filepath,omitempty,omitempty"`
|
Filepath string `yaml:"filepath,omitempty,omitempty"`
|
||||||
|
|
||||||
|
// Archive options
|
||||||
|
NoExtract bool `yaml:"no_extract,omitempty"`
|
||||||
|
ExtractTo string `yaml:"extract_to,omitempty"`
|
||||||
|
ExtractStripComponents int `yaml:"extract_strip_components,omitempty"`
|
||||||
|
|
||||||
|
// Git options
|
||||||
|
CloneTo string `yaml:"clone_to,omitempty"`
|
||||||
|
GitBranch string `yaml:"git_branch,omitempty"`
|
||||||
|
|
||||||
Checksum string `yaml:"checksum,omitempty"`
|
Checksum string `yaml:"checksum,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadPacakgeInfo(path string) (*PackageInfo, error) {
|
func ReadPackageInfo(data []byte) (*PackageInfo, error) {
|
||||||
// Extract package info using tar
|
|
||||||
cmd := exec.Command("tar", "-x", "-f", path, "pkg.info", "-O")
|
|
||||||
output, err := cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
pkgInfo := &PackageInfo{
|
pkgInfo := &PackageInfo{
|
||||||
Name: "",
|
|
||||||
Description: "",
|
|
||||||
Version: "",
|
|
||||||
Revision: 1,
|
Revision: 1,
|
||||||
Url: "",
|
|
||||||
License: "",
|
|
||||||
Arch: "",
|
|
||||||
OutputArch: "",
|
|
||||||
Type: "",
|
|
||||||
Keep: make([]string, 0),
|
Keep: make([]string, 0),
|
||||||
Depends: make([]string, 0),
|
Depends: make([]string, 0),
|
||||||
MakeDepends: make([]string, 0),
|
MakeDepends: make([]string, 0),
|
||||||
@@ -72,7 +63,23 @@ func ReadPacakgeInfo(path string) (*PackageInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal yaml
|
// Unmarshal yaml
|
||||||
err = yaml.Unmarshal(output, pkgInfo)
|
err := yaml.Unmarshal(data, pkgInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkgInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadPacakgeInfoFromTarball(path string) (*PackageInfo, error) {
|
||||||
|
// Extract package info using tar
|
||||||
|
cmd := exec.Command("tar", "-x", "-f", path, "pkg.info", "-O")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgInfo, err := ReadPackageInfo(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -81,35 +88,13 @@ func ReadPacakgeInfo(path string) (*PackageInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ReadPacakgeInfoFromFile(path string) (*PackageInfo, error) {
|
func ReadPacakgeInfoFromFile(path string) (*PackageInfo, error) {
|
||||||
// Extract package info using tar
|
// Read data from file
|
||||||
output, err := os.ReadFile(path)
|
output, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgInfo := &PackageInfo{
|
pkgInfo, err := ReadPackageInfo(output)
|
||||||
Name: "",
|
|
||||||
Description: "",
|
|
||||||
Version: "",
|
|
||||||
Revision: 1,
|
|
||||||
Url: "",
|
|
||||||
License: "",
|
|
||||||
Arch: "",
|
|
||||||
OutputArch: "",
|
|
||||||
Type: "",
|
|
||||||
Keep: make([]string, 0),
|
|
||||||
Depends: make([]string, 0),
|
|
||||||
OptionalDepends: make([]string, 0),
|
|
||||||
MakeDepends: make([]string, 0),
|
|
||||||
Conflicts: make([]string, 0),
|
|
||||||
Replaces: make([]string, 0),
|
|
||||||
Provides: make([]string, 0),
|
|
||||||
Downloads: make([]PackageDownload, 0),
|
|
||||||
SplitPackages: make([]*PackageInfo, 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal yaml
|
|
||||||
err = yaml.Unmarshal(output, pkgInfo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -170,7 +155,7 @@ func (pkgDownload *PackageDownload) CalculateChecksum(pkgInfo *PackageInfo) (str
|
|||||||
return "", fmt.Errorf("'git_branch' field cannot be empty")
|
return "", fmt.Errorf("'git_branch' field cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("sh", "-c", fmt.Sprintf("git ls-remote --refs %s | grep 'refs/.*/%s$' | awk '{print $1}'", pkgDownload.Url, gitBranch))
|
cmd := exec.Command("sh", "-c", fmt.Sprintf("git ls-remote -bt %s | grep -E 'refs/.*/%s(\\^\\{\\})?$' | tail -n1 | awk '{print $1}'", pkgDownload.Url, gitBranch))
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
checksum, err := cmd.Output()
|
checksum, err := cmd.Output()
|
||||||
|
|||||||
Reference in New Issue
Block a user