3 Commits
Author SHA1 Message Date
EnumDev 1b6585424f Remove old BPM archives when creating new one 2025-09-05 20:56:57 +03:00
EnumDev c9627e1068 Add gitignore template 2025-09-05 20:46:12 +03:00
EnumDev aae5299b8a Add 'list packages' flag to bpm-repo 2025-09-05 19:42:33 +03:00
4 changed files with 86 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
# Exclude bpm archives
*.bpm
+12
View File
@@ -93,6 +93,18 @@ func createArchive() string {
log.Fatalf("Error: could not unmarshal pkg.info file")
}
// Remove old BPM archives in current directory
oldArchives, err := filepath.Glob("*.bpm")
if err != nil {
log.Printf("Warning: could not search for old BPM archives: %s", err)
}
for _, bpmArchive := range oldArchives {
err = os.Remove(bpmArchive)
if err != nil {
log.Printf("Warning: could not remove old BPM archive (%s): %s", bpmArchive, err)
}
}
// Create filename
filename := fmt.Sprintf("%s-%s-%d-%s-src.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision, pkgInfo.Arch)
+55
View File
@@ -5,8 +5,11 @@ import (
"bufio"
"fmt"
"log"
"maps"
"os"
"path"
"slices"
"sort"
"strings"
flag "github.com/spf13/pflag"
@@ -14,6 +17,7 @@ import (
var createRepo = flag.BoolP("create", "c", false, "Create a new BPM repository")
var updateDatabases = flag.BoolP("update-databases", "u", false, "Update update source and binary databases in current repository")
var listPackages = flag.BoolP("list", "l", false, "List packages")
func main() {
// Setup flags and help
@@ -48,6 +52,14 @@ func main() {
}
bpmutilsshared.UpdateDatabases(repo)
} else if *listPackages {
// Get current database
repo := bpmutilsshared.GetRepository()
if repo == "" {
log.Fatal("Error: this command may only be run inside a BPM repository")
}
listPacakges(repo)
} else {
bpmutilsshared.ShowHelp()
}
@@ -67,3 +79,46 @@ func createRepository(name, description string) {
fmt.Println("Repository created successfully!")
}
func listPacakges(repo string) {
// Read databases
sourceDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "source/database.bpmdb"))
if err != nil {
return
}
binaryDatabase, err := bpmutilsshared.ReadDatabase(path.Join(repo, "binary/database.bpmdb"))
if err != nil {
binaryDatabase = &bpmutilsshared.BPMDatabase{}
}
// Sort database entries
entriesSorted := slices.Collect(maps.Values(sourceDatabase.Entries))
sort.Slice(entriesSorted, func(i, j int) bool {
return entriesSorted[i].PackageInfo.Name < entriesSorted[j].PackageInfo.Name
})
// Loop through each entry
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 {
additionalText := ""
if binaryEntry, ok := binaryDatabase.Entries[entry.PackageInfo.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", entry.PackageInfo.Name, entry.PackageInfo.Version, entry.PackageInfo.Revision, additionalText)
}
}
}
+17
View File
@@ -4,6 +4,7 @@ import (
bpmutilsshared "bpm-utils-shared"
"bufio"
"fmt"
"io"
"log"
"os"
"os/exec"
@@ -163,5 +164,21 @@ func createDirectory() {
if err != nil {
log.Fatalf("Error: could not initialize git repository: %s", err)
}
// Copy default gitignore
defaultGitignoreFile, err := os.Open("/etc/bpm-utils/gitignore.default")
if err != nil {
return
}
defer defaultGitignoreFile.Close()
newGitignoreFile, err := os.OpenFile(path.Join(*directory, ".gitignore"), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("Error: could not create .gitignore file: %s", err)
}
_, err = io.Copy(newGitignoreFile, defaultGitignoreFile)
if err != nil {
log.Fatalf("Error: could not copy data to .gitignore file: %s", err)
}
}
}