mirror of
https://github.com/EnumeratedDev/bpm-utils.git
synced 2026-09-26 15:36:13 +00:00
Compare commits
3
Commits
908b9ccc12
...
1b6585424f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b6585424f | ||
|
|
c9627e1068 | ||
|
|
aae5299b8a |
@@ -0,0 +1,2 @@
|
|||||||
|
# Exclude bpm archives
|
||||||
|
*.bpm
|
||||||
@@ -93,6 +93,18 @@ func createArchive() string {
|
|||||||
log.Fatalf("Error: could not unmarshal pkg.info file")
|
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
|
// 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)
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"slices"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
@@ -14,6 +17,7 @@ import (
|
|||||||
|
|
||||||
var createRepo = flag.BoolP("create", "c", false, "Create a new BPM repository")
|
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 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() {
|
func main() {
|
||||||
// Setup flags and help
|
// Setup flags and help
|
||||||
@@ -48,6 +52,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bpmutilsshared.UpdateDatabases(repo)
|
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 {
|
} else {
|
||||||
bpmutilsshared.ShowHelp()
|
bpmutilsshared.ShowHelp()
|
||||||
}
|
}
|
||||||
@@ -67,3 +79,46 @@ func createRepository(name, description string) {
|
|||||||
|
|
||||||
fmt.Println("Repository created successfully!")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
bpmutilsshared "bpm-utils-shared"
|
bpmutilsshared "bpm-utils-shared"
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -163,5 +164,21 @@ func createDirectory() {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user