mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-25 06:56:12 +00:00
Compare commits
3
Commits
1895fabfb0
...
9912b173ff
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9912b173ff
|
||
|
|
879c832f60
|
||
|
|
2c91a9332b
|
@@ -7,12 +7,13 @@ SYSCONFDIR := $(PREFIX)/etc
|
|||||||
GO ?= go
|
GO ?= go
|
||||||
|
|
||||||
# Build-time variables
|
# Build-time variables
|
||||||
|
VERSION ?= $(shell git describe --tags --dirty)
|
||||||
ROOT_COMPILATION_UID ?= 65534
|
ROOT_COMPILATION_UID ?= 65534
|
||||||
ROOT_COMPILATION_GID ?= 65534
|
ROOT_COMPILATION_GID ?= 65534
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd src/bpm; $(GO) build $(GOFLAGS) -ldflags "-w -X 'git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib.rootCompilationUID=$(ROOT_COMPILATION_UID)' -X 'git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib.rootCompilationGID=$(ROOT_COMPILATION_GID)'" -o ../../build/bpm git.enumerated.dev/bubble-package-manager/bpm/src/bpm
|
cd src/bpm; $(GO) build $(GOFLAGS) -ldflags "-w -X 'git.enumerated.dev/bubble-package-manager/bpm/src/bpm/config.BpmVersion=$(VERSION)' -X 'git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib.rootCompilationUID=$(ROOT_COMPILATION_UID)' -X 'git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib.rootCompilationGID=$(ROOT_COMPILATION_GID)'" -o ../../build/bpm git.enumerated.dev/bubble-package-manager/bpm/src/bpm
|
||||||
|
|
||||||
install: build/bpm config/
|
install: build/bpm config/
|
||||||
# Create directory
|
# Create directory
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
var BpmVersion = "dev"
|
||||||
+21
-3
@@ -14,6 +14,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.enumerated.dev/bubble-package-manager/bpm/src/bpm/config"
|
||||||
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
||||||
|
|
||||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||||
@@ -25,8 +26,6 @@ import (
|
|||||||
/* A simple-to-use package manager */
|
/* A simple-to-use package manager */
|
||||||
/* ------------------------------------------------------- */
|
/* ------------------------------------------------------- */
|
||||||
|
|
||||||
var bpmVer = "0.6.1"
|
|
||||||
|
|
||||||
var currentFlagSet *flag.FlagSet
|
var currentFlagSet *flag.FlagSet
|
||||||
|
|
||||||
var exitCode = 0
|
var exitCode = 0
|
||||||
@@ -46,7 +45,7 @@ func main() {
|
|||||||
switch subcommand {
|
switch subcommand {
|
||||||
case "v", "version":
|
case "v", "version":
|
||||||
fmt.Println("Bubble Package Manager (BPM)")
|
fmt.Println("Bubble Package Manager (BPM)")
|
||||||
fmt.Println("Version: " + bpmVer)
|
fmt.Println("Version: " + config.BpmVersion)
|
||||||
case "q", "query":
|
case "q", "query":
|
||||||
// Setup flags and help
|
// Setup flags and help
|
||||||
currentFlagSet = flag.NewFlagSet("query", flag.ExitOnError)
|
currentFlagSet = flag.NewFlagSet("query", flag.ExitOnError)
|
||||||
@@ -162,6 +161,11 @@ func main() {
|
|||||||
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "Compile source packages and convert them to binary ones", os.Args[2:])
|
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "Compile source packages and convert them to binary ones", os.Args[2:])
|
||||||
|
|
||||||
compilePackage()
|
compilePackage()
|
||||||
|
case "p", "vercmp":
|
||||||
|
currentFlagSet = flag.NewFlagSet("compile", flag.ExitOnError)
|
||||||
|
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "Compare two version numbers", os.Args[2:])
|
||||||
|
|
||||||
|
compareVersions()
|
||||||
default:
|
default:
|
||||||
listSubcommands()
|
listSubcommands()
|
||||||
}
|
}
|
||||||
@@ -1268,6 +1272,19 @@ func compilePackage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func compareVersions() {
|
||||||
|
if currentFlagSet.NArg() < 2 {
|
||||||
|
log.Printf("Error: vercmp subcommand requires 2 arguments")
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
v1 := currentFlagSet.Arg(0)
|
||||||
|
v2 := currentFlagSet.Arg(1)
|
||||||
|
|
||||||
|
fmt.Println(bpmlib.CompareVersions(v1, v2))
|
||||||
|
}
|
||||||
|
|
||||||
func listSubcommands() {
|
func listSubcommands() {
|
||||||
fmt.Printf("Usage: %s <subcommand> [options]\n", os.Args[0])
|
fmt.Printf("Usage: %s <subcommand> [options]\n", os.Args[0])
|
||||||
fmt.Println("Description: Manage system packages")
|
fmt.Println("Description: Manage system packages")
|
||||||
@@ -1282,6 +1299,7 @@ func listSubcommands() {
|
|||||||
fmt.Println(" u, update Update installed packages")
|
fmt.Println(" u, update Update installed packages")
|
||||||
fmt.Println(" o, owner Show what packages own the specified paths")
|
fmt.Println(" o, owner Show what packages own the specified paths")
|
||||||
fmt.Println(" c, compile Compile source packages and convert them to binary ones")
|
fmt.Println(" c, compile Compile source packages and convert them to binary ones")
|
||||||
|
fmt.Println(" p, vercmp Compare package version numbers")
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupFlagsAndHelp(flagset *flag.FlagSet, usage, desc string, args []string) {
|
func setupFlagsAndHelp(flagset *flag.FlagSet, usage, desc string, args []string) {
|
||||||
|
|||||||
@@ -416,7 +416,7 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
|||||||
if installedInfo == nil {
|
if installedInfo == nil {
|
||||||
return nil, fmt.Errorf("could not get package info for package (%s)", pkg)
|
return nil, fmt.Errorf("could not get package info for package (%s)", pkg)
|
||||||
} else {
|
} else {
|
||||||
comparison := ComparePackageVersions(*entry.Info, *installedInfo)
|
comparison := CompareVersions(entry.Info.GetFullVersion(), installedInfo.GetFullVersion())
|
||||||
if comparison > 0 {
|
if comparison > 0 {
|
||||||
operation.AppendAction(&FetchPackageAction{
|
operation.AppendAction(&FetchPackageAction{
|
||||||
InstallationReason: GetInstallationReason(pkg, rootDir),
|
InstallationReason: GetInstallationReason(pkg, rootDir),
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
|||||||
if installedInfo == nil {
|
if installedInfo == nil {
|
||||||
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%t\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Install", installationReasonStr, pkgInfo.Type == "source")
|
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%t\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Install", installationReasonStr, pkgInfo.Type == "source")
|
||||||
} else {
|
} else {
|
||||||
comparison := ComparePackageVersions(*pkgInfo, *installedInfo)
|
comparison := CompareVersions(pkgInfo.GetFullVersion(), installedInfo.GetFullVersion())
|
||||||
if comparison < 0 {
|
if comparison < 0 {
|
||||||
fmt.Fprintf(writer, "%s\t%s -> %s\t%s\t%s\t%t\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), "Downgrade", installationReasonStr, pkgInfo.Type == "source")
|
fmt.Fprintf(writer, "%s\t%s -> %s\t%s\t%s\t%t\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), "Downgrade", installationReasonStr, pkgInfo.Type == "source")
|
||||||
} else if comparison > 0 {
|
} else if comparison > 0 {
|
||||||
|
|||||||
+15
-19
@@ -17,7 +17,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
version "github.com/knqyf263/go-rpm-version"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -121,13 +120,6 @@ const (
|
|||||||
InstallationReasonUnknown InstallationReason = "unknown"
|
InstallationReasonUnknown InstallationReason = "unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ComparePackageVersions(info1, info2 PackageInfo) int {
|
|
||||||
v1 := version.NewVersion(info1.GetFullVersion())
|
|
||||||
v2 := version.NewVersion(info2.GetFullVersion())
|
|
||||||
|
|
||||||
return v1.Compare(v2)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInstallationReason(pkg, rootDir string) InstallationReason {
|
func GetInstallationReason(pkg, rootDir string) InstallationReason {
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
@@ -625,17 +617,6 @@ func (bpmpkg *BPMPackage) CreateReadableInfo(rootDir string, humanReadableSize b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string) error {
|
func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string) error {
|
||||||
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
|
||||||
err := executePackageScript(filename, rootDir, verbose, "pre_install.sh")
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Warning: %s\n", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err := executePackageScript(filename, rootDir, verbose, "pre_update.sh")
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Warning: %s\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
seenHardlinks := make(map[string]string)
|
seenHardlinks := make(map[string]string)
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -811,6 +792,20 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
packageInstalled := IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir)
|
packageInstalled := IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir)
|
||||||
|
|
||||||
|
// Run pre-* package scripts
|
||||||
|
if !packageInstalled {
|
||||||
|
err := executePackageScript(filename, rootDir, verbose, "pre_install.sh")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: %s\n", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err := executePackageScript(filename, rootDir, verbose, "pre_update.sh")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if package is installed and remove current files
|
// Check if package is installed and remove current files
|
||||||
if packageInstalled {
|
if packageInstalled {
|
||||||
// Fetching and reversing package file entry list
|
// Fetching and reversing package file entry list
|
||||||
@@ -992,6 +987,7 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
|
|||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run post-* package scripts
|
||||||
if !packageInstalled {
|
if !packageInstalled {
|
||||||
err = executePackageScript(filename, rootDir, verbose, "post_install.sh")
|
err = executePackageScript(filename, rootDir, verbose, "post_install.sh")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
version "github.com/knqyf263/go-rpm-version"
|
||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -132,3 +133,10 @@ func bytesToHumanReadable(b int64) string {
|
|||||||
}
|
}
|
||||||
return fmt.Sprintf("%.1fYiB", bf)
|
return fmt.Sprintf("%.1fYiB", bf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CompareVersions(version1, version2 string) int {
|
||||||
|
v1 := version.NewVersion(version1)
|
||||||
|
v2 := version.NewVersion(version2)
|
||||||
|
|
||||||
|
return v1.Compare(v2)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user