mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-25 23:16:13 +00:00
Compare commits
33
Commits
f0ea57d500
...
0.6.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f23537ba7d
|
||
|
|
6e9f16837c
|
||
|
|
271e87cb77
|
||
|
|
25ccc208d7
|
||
|
|
9c7e20d27d
|
||
|
|
6206fdbf43
|
||
|
|
9e48d97dc8
|
||
|
|
08a4e24889
|
||
|
|
4a32df6335
|
||
|
|
548b2476bd
|
||
|
|
a660039be1
|
||
|
|
44c2678ef9
|
||
|
|
2a7c6ce5d9
|
||
|
|
f98760d1dd
|
||
|
|
2ba78f16db
|
||
|
|
04a71b573b
|
||
|
|
aa229af8df
|
||
|
|
9912b173ff
|
||
|
|
879c832f60
|
||
|
|
2c91a9332b
|
||
|
|
1895fabfb0
|
||
|
|
0dfb66c6c0
|
||
|
|
dfdf38bad8
|
||
|
|
52f25c8f3f
|
||
|
|
7e372eef91
|
||
|
|
b07a7f8778
|
||
|
|
b2fc963389
|
||
|
|
b27e9fb0df
|
||
|
|
089bc61d58
|
||
|
|
fb821b3190
|
||
|
|
444b2032e2
|
||
|
|
70ba64ca6b
|
||
|
|
ed172f2805
|
@@ -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 'main.BpmVersion=$(VERSION)' -X 'github.com/EnumeratedDev/bpm/src/bpmlib.rootCompilationUID=$(ROOT_COMPILATION_UID)' -X 'github.com/EnumeratedDev/bpm/src/bpmlib.rootCompilationGID=$(ROOT_COMPILATION_GID)'" -o ../../build/bpm bpm
|
||||||
|
|
||||||
install: build/bpm config/
|
install: build/bpm config/
|
||||||
# Create directory
|
# Create directory
|
||||||
|
|||||||
+9
-6
@@ -1,20 +1,23 @@
|
|||||||
module git.enumerated.dev/bubble-package-manager/bpm/src/bpm
|
module bpm
|
||||||
|
|
||||||
go 1.23
|
go 1.24.0
|
||||||
|
|
||||||
toolchain go1.23.7
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib v0.5.0
|
github.com/EnumeratedDev/bpm/src/bpmlib v0.0.0
|
||||||
github.com/lithammer/fuzzysearch v1.1.8
|
github.com/lithammer/fuzzysearch v1.1.8
|
||||||
github.com/spf13/pflag v1.0.10
|
github.com/spf13/pflag v1.0.10
|
||||||
)
|
)
|
||||||
|
|
||||||
replace git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib => ../bpmlib
|
replace github.com/EnumeratedDev/bpm/src/bpmlib => ../bpmlib
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/drone/envsubst v1.0.3 // indirect
|
github.com/drone/envsubst v1.0.3 // indirect
|
||||||
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0 // indirect
|
||||||
|
golang.org/x/sys v0.37.0 // indirect
|
||||||
|
golang.org/x/term v0.36.0 // indirect
|
||||||
golang.org/x/text v0.9.0 // indirect
|
golang.org/x/text v0.9.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
|
||||||
|
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
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=
|
||||||
@@ -6,8 +10,20 @@ github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T
|
|||||||
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
|
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
|
||||||
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
|
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
|
||||||
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=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
@@ -26,9 +42,13 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
||||||
|
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
|
||||||
|
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
|||||||
+118
-26
@@ -14,7 +14,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
"github.com/EnumeratedDev/bpm/src/bpmlib"
|
||||||
|
|
||||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
/* A simple-to-use package manager */
|
/* A simple-to-use package manager */
|
||||||
/* ------------------------------------------------------- */
|
/* ------------------------------------------------------- */
|
||||||
|
|
||||||
var bpmVer = "0.6.1"
|
var BpmVersion = "dev"
|
||||||
|
|
||||||
var currentFlagSet *flag.FlagSet
|
var currentFlagSet *flag.FlagSet
|
||||||
|
|
||||||
@@ -37,16 +37,18 @@ func main() {
|
|||||||
log.Fatalf("Error: could not read BPM config: %s", err)
|
log.Fatalf("Error: could not read BPM config: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute subcommand
|
// Show usage if no arguments specified
|
||||||
subcommand := "help"
|
if len(os.Args) == 1 {
|
||||||
if len(os.Args) >= 2 {
|
printUsage()
|
||||||
subcommand = os.Args[1]
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subcommand := os.Args[1]
|
||||||
|
|
||||||
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: " + 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)
|
||||||
@@ -136,6 +138,7 @@ func main() {
|
|||||||
currentFlagSet.BoolP("force", "f", false, "Bypass warnings during package update")
|
currentFlagSet.BoolP("force", "f", false, "Bypass warnings during package update")
|
||||||
currentFlagSet.BoolP("yes", "y", false, "Enter 'yes' in all prompts")
|
currentFlagSet.BoolP("yes", "y", false, "Enter 'yes' in all prompts")
|
||||||
currentFlagSet.BoolP("no-sync", "n", false, "Do not sync databases")
|
currentFlagSet.BoolP("no-sync", "n", false, "Do not sync databases")
|
||||||
|
currentFlagSet.Bool("allow-downgrades", false, "Allow package downgrades")
|
||||||
currentFlagSet.BoolP("optional", "o", false, "Install all optional dependencies")
|
currentFlagSet.BoolP("optional", "o", false, "Install all optional dependencies")
|
||||||
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "Update installed packages", os.Args[2:])
|
setupFlagsAndHelp(currentFlagSet, fmt.Sprintf("bpm %s <options>", subcommand), "Update installed packages", os.Args[2:])
|
||||||
|
|
||||||
@@ -162,8 +165,14 @@ 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()
|
printUsage()
|
||||||
|
exitCode = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if exitCode != 0 {
|
if exitCode != 0 {
|
||||||
@@ -247,7 +256,14 @@ func showPackageInfo() {
|
|||||||
}
|
}
|
||||||
fmt.Println("File: " + abs)
|
fmt.Println("File: " + abs)
|
||||||
}
|
}
|
||||||
fmt.Println(bpmpkg.CreateReadableInfo(rootDir, showHumanReadableSize))
|
fmt.Println(bpmpkg.PkgInfo.CreateReadableInfo(rootDir))
|
||||||
|
if bpmpkg.PkgInfo.Type == "binary" {
|
||||||
|
if !showHumanReadableSize {
|
||||||
|
fmt.Printf("Installed size: %d\n", bpmpkg.GetInstalledSize())
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(bpmpkg.GetInstalledSize()))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,9 +301,21 @@ func showPackageList() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
installedPackages := make([]*bpmlib.BPMPackage, len(installedPackageNames))
|
installedPackages := make([]struct {
|
||||||
|
pkgInfo bpmlib.PackageInfo
|
||||||
|
installedSize int64
|
||||||
|
}, len(installedPackageNames))
|
||||||
for i, pkgName := range installedPackageNames {
|
for i, pkgName := range installedPackageNames {
|
||||||
installedPackages[i] = bpmlib.GetPackage(pkgName, rootDir)
|
pkgInfo := *bpmlib.GetPackageInfo(pkgName, rootDir)
|
||||||
|
installedSize := bpmlib.GetPackage(pkgName, rootDir).GetInstalledSize()
|
||||||
|
|
||||||
|
installedPackages[i] = struct {
|
||||||
|
pkgInfo bpmlib.PackageInfo
|
||||||
|
installedSize int64
|
||||||
|
}{
|
||||||
|
pkgInfo: pkgInfo,
|
||||||
|
installedSize: installedSize,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
databaseEntries := make([]*bpmlib.BPMDatabaseEntry, 0)
|
databaseEntries := make([]*bpmlib.BPMDatabaseEntry, 0)
|
||||||
@@ -298,8 +326,11 @@ func showPackageList() {
|
|||||||
switch sortPackages {
|
switch sortPackages {
|
||||||
case "", "name":
|
case "", "name":
|
||||||
case "size":
|
case "size":
|
||||||
slices.SortFunc(installedPackages, func(a, b *bpmlib.BPMPackage) int {
|
slices.SortFunc(installedPackages, func(a, b struct {
|
||||||
return int(b.GetInstalledSize() - a.GetInstalledSize())
|
pkgInfo bpmlib.PackageInfo
|
||||||
|
installedSize int64
|
||||||
|
}) int {
|
||||||
|
return int(b.installedSize - a.installedSize)
|
||||||
})
|
})
|
||||||
slices.SortFunc(databaseEntries, func(a, b *bpmlib.BPMDatabaseEntry) int {
|
slices.SortFunc(databaseEntries, func(a, b *bpmlib.BPMDatabaseEntry) int {
|
||||||
return int(b.InstalledSize - a.InstalledSize)
|
return int(b.InstalledSize - a.InstalledSize)
|
||||||
@@ -328,7 +359,7 @@ func showPackageList() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, pkg := range installedPackages {
|
for _, pkg := range installedPackages {
|
||||||
installationReason := bpmlib.GetInstallationReason(pkg.PkgInfo.Name, rootDir)
|
installationReason := bpmlib.GetInstallationReason(pkg.pkgInfo.Name, rootDir)
|
||||||
if installationReason == bpmlib.InstallationReasonManual && !showManual {
|
if installationReason == bpmlib.InstallationReasonManual && !showManual {
|
||||||
continue
|
continue
|
||||||
} else if installationReason == bpmlib.InstallationReasonDependency && !showDepends {
|
} else if installationReason == bpmlib.InstallationReasonDependency && !showDepends {
|
||||||
@@ -339,7 +370,7 @@ func showPackageList() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(pkg.PkgInfo.Name)
|
fmt.Println(pkg.pkgInfo.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -359,13 +390,8 @@ func showPackageList() {
|
|||||||
fmt.Println("No packages have been installed")
|
fmt.Println("No packages have been installed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for n, bpmpkg := range installedPackages {
|
for n, pkg := range installedPackages {
|
||||||
if bpmpkg == nil {
|
installationReason := bpmlib.GetInstallationReason(pkg.pkgInfo.Name, rootDir)
|
||||||
fmt.Printf("Package (%s) could not be found\n", installedPackageNames[n])
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
installationReason := bpmlib.GetInstallationReason(bpmpkg.PkgInfo.Name, rootDir)
|
|
||||||
if installationReason == bpmlib.InstallationReasonManual && !showManual {
|
if installationReason == bpmlib.InstallationReasonManual && !showManual {
|
||||||
continue
|
continue
|
||||||
} else if installationReason == bpmlib.InstallationReasonDependency && !showDepends {
|
} else if installationReason == bpmlib.InstallationReasonDependency && !showDepends {
|
||||||
@@ -379,7 +405,15 @@ func showPackageList() {
|
|||||||
if n != 0 {
|
if n != 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
fmt.Println(bpmpkg.CreateReadableInfo(rootDir, showHumanReadableSize))
|
|
||||||
|
fmt.Println(pkg.pkgInfo.CreateReadableInfo(rootDir))
|
||||||
|
if pkg.pkgInfo.Type == "binary" {
|
||||||
|
if !showHumanReadableSize {
|
||||||
|
fmt.Printf("Installed size: %d\n", pkg.installedSize)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(pkg.installedSize))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -570,6 +604,9 @@ func installPackages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get optional dependencies
|
||||||
|
optionalDepends := operation.GetOptionalDependencies()
|
||||||
|
|
||||||
// Execute operation
|
// Execute operation
|
||||||
err = operation.Execute(verbose, force)
|
err = operation.Execute(verbose, force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -586,6 +623,18 @@ func installPackages() {
|
|||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show optional dependencies
|
||||||
|
if !installOptional && len(optionalDepends) != 0 {
|
||||||
|
// List optional dependencies
|
||||||
|
fmt.Println("The following optional dependenices have been discovered:")
|
||||||
|
for dependant, depends := range optionalDepends {
|
||||||
|
fmt.Printf("%s: \n", dependant)
|
||||||
|
for _, depend := range depends {
|
||||||
|
fmt.Printf(" - %s\n", depend)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func removePackages() {
|
func removePackages() {
|
||||||
@@ -847,6 +896,7 @@ func updatePackages() {
|
|||||||
force, _ := currentFlagSet.GetBool("force")
|
force, _ := currentFlagSet.GetBool("force")
|
||||||
yesAll, _ := currentFlagSet.GetBool("yes")
|
yesAll, _ := currentFlagSet.GetBool("yes")
|
||||||
noSync, _ := currentFlagSet.GetBool("no-sync")
|
noSync, _ := currentFlagSet.GetBool("no-sync")
|
||||||
|
allowDowngrades, _ := currentFlagSet.GetBool("allow-downgrades")
|
||||||
installOptional, _ := currentFlagSet.GetBool("optional")
|
installOptional, _ := currentFlagSet.GetBool("optional")
|
||||||
|
|
||||||
// Check for required permissions
|
// Check for required permissions
|
||||||
@@ -875,14 +925,25 @@ func updatePackages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Confirmation Prompt
|
||||||
|
if !noSync && !yesAll {
|
||||||
|
if !showConfirmationPrompt("Do you wish to sync all databases?", false) {
|
||||||
|
fmt.Println("Cancelling package update...")
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create update operation
|
// Create update operation
|
||||||
operation, err := bpmlib.UpdatePackages(rootDir, !noSync, installOptional, force, verbose)
|
operation, err := bpmlib.UpdatePackages(rootDir, !noSync, allowDowngrades, installOptional, force, verbose)
|
||||||
if errors.As(err, &bpmlib.PackageNotFoundErr{}) || errors.As(err, &bpmlib.DependencyNotFoundErr{}) || errors.As(err, &bpmlib.PackageConflictErr{}) {
|
if errors.As(err, &bpmlib.PackageNotFoundErr{}) || errors.As(err, &bpmlib.DependencyNotFoundErr{}) || errors.As(err, &bpmlib.PackageConflictErr{}) {
|
||||||
log.Printf("Error: %s", err)
|
log.Printf("Error: %s", err)
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Printf("Error: could not setup operation: %s\n", err)
|
log.Printf("Error: could not setup operation: %s\n", err)
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit if operation contains no actions
|
// Exit if operation contains no actions
|
||||||
@@ -935,6 +996,9 @@ func updatePackages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get optional dependencies
|
||||||
|
optionalDepends := operation.GetOptionalDependencies()
|
||||||
|
|
||||||
// Execute operation
|
// Execute operation
|
||||||
err = operation.Execute(verbose, force)
|
err = operation.Execute(verbose, force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -951,6 +1015,18 @@ func updatePackages() {
|
|||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show optional dependencies
|
||||||
|
if !installOptional && len(optionalDepends) != 0 {
|
||||||
|
// List optional dependencies
|
||||||
|
fmt.Println("The following optional dependenices have been discovered:")
|
||||||
|
for dependant, depends := range optionalDepends {
|
||||||
|
fmt.Printf("%s: \n", dependant)
|
||||||
|
for _, depend := range depends {
|
||||||
|
fmt.Printf(" - %s\n", depend)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFileOwner() {
|
func getFileOwner() {
|
||||||
@@ -1027,6 +1103,8 @@ func getFileOwner() {
|
|||||||
// Print packages
|
// Print packages
|
||||||
if len(pkgList) == 0 {
|
if len(pkgList) == 0 {
|
||||||
fmt.Printf("%s (%s) is not owned by any packages!\n", absPath, pathType)
|
fmt.Printf("%s (%s) is not owned by any packages!\n", absPath, pathType)
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s (%s) is owned by the following packages:\n", absPath, pathType)
|
fmt.Printf("%s (%s) is owned by the following packages:\n", absPath, pathType)
|
||||||
for _, pkg := range pkgList {
|
for _, pkg := range pkgList {
|
||||||
@@ -1141,7 +1219,7 @@ func compilePackage() {
|
|||||||
} else {
|
} else {
|
||||||
// Ensure the required dependencies are installed
|
// Ensure the required dependencies are installed
|
||||||
if len(unmetDepends) != 0 {
|
if len(unmetDepends) != 0 {
|
||||||
log.Printf("Error: could not resolve dependencies: the following dependencies were not found in any databases: " + strings.Join(unmetDepends, ", "))
|
log.Printf("Error: the following dependencies were not found in any databases: %s", strings.Join(unmetDepends, ", "))
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1268,7 +1346,20 @@ func compilePackage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func listSubcommands() {
|
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 printUsage() {
|
||||||
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")
|
||||||
fmt.Println("Subcommands:")
|
fmt.Println("Subcommands:")
|
||||||
@@ -1282,6 +1373,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) {
|
||||||
|
|||||||
+112
-14
@@ -6,9 +6,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -135,6 +137,7 @@ func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks, k
|
|||||||
env = append(env, "BPM_PKG_NAME="+bpmpkg.PkgInfo.Name)
|
env = append(env, "BPM_PKG_NAME="+bpmpkg.PkgInfo.Name)
|
||||||
env = append(env, "BPM_PKG_VERSION="+bpmpkg.PkgInfo.Version)
|
env = append(env, "BPM_PKG_VERSION="+bpmpkg.PkgInfo.Version)
|
||||||
env = append(env, "BPM_PKG_REVISION="+strconv.Itoa(bpmpkg.PkgInfo.Revision))
|
env = append(env, "BPM_PKG_REVISION="+strconv.Itoa(bpmpkg.PkgInfo.Revision))
|
||||||
|
env = append(env, "BPM_PKG_URL="+bpmpkg.PkgInfo.Url)
|
||||||
env = append(env, "BPM_PKG_ARCH="+bpmpkg.PkgInfo.OutputArch)
|
env = append(env, "BPM_PKG_ARCH="+bpmpkg.PkgInfo.OutputArch)
|
||||||
env = append(env, CompilationBPMConfig.CompilationEnvironment...)
|
env = append(env, CompilationBPMConfig.CompilationEnvironment...)
|
||||||
|
|
||||||
@@ -143,8 +146,8 @@ func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks, k
|
|||||||
"set -a\n"+ // Source and export functions and variables in source.sh script
|
"set -a\n"+ // Source and export functions and variables in source.sh script
|
||||||
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
||||||
"set +a\n"+
|
"set +a\n"+
|
||||||
"[[ $(type -t prepare) == \"function\" ]] && { echo \"Running prepare() function\"; bash -e -c 'cd \"$BPM_WORKDIR\" && prepare' || exit 1; }\n"+ // Run prepare() function if it exists
|
"[[ $(type -t prepare) == \"function\" ]] && { echo \"Running prepare() function...\"; bash -e -c 'cd \"$BPM_WORKDIR\" && prepare' || exit 1; }\n"+ // Run prepare() function if it exists
|
||||||
"[[ $(type -t build) == \"function\" ]] && { echo \"Running build() function\"; bash -e -c 'cd \"$BPM_SOURCE\" && build' || exit 1; }\n"+ // Run build() function if it exists
|
"[[ $(type -t build) == \"function\" ]] && { echo \"Running build() function...\"; bash -e -c 'cd \"$BPM_SOURCE\" && build' || exit 1; }\n"+ // Run build() function if it exists
|
||||||
"exit 0")
|
"exit 0")
|
||||||
cmd.Dir = tempDirectory
|
cmd.Dir = tempDirectory
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -165,7 +168,7 @@ func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks, k
|
|||||||
"set -a\n"+ // Source and export functions and variables in source.sh script
|
"set -a\n"+ // Source and export functions and variables in source.sh script
|
||||||
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
||||||
"set +a\n"+
|
"set +a\n"+
|
||||||
"[[ $(type -t check) == \"function\" ]] && { echo \"Running check() function\"; bash -e -c 'cd \"$BPM_SOURCE\" && check' || exit 1; }\n"+ // Run check() function if it exists
|
"[[ $(type -t check) == \"function\" ]] && { echo \"Running check() function...\"; bash -e -c 'cd \"$BPM_SOURCE\" && check' || exit 1; }\n"+ // Run check() function if it exists
|
||||||
"exit 0")
|
"exit 0")
|
||||||
cmd.Dir = tempDirectory
|
cmd.Dir = tempDirectory
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -215,9 +218,8 @@ func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks, k
|
|||||||
"set -a\n"+ // Source and export functions and variables in source.sh script
|
"set -a\n"+ // Source and export functions and variables in source.sh script
|
||||||
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
||||||
"set +a\n"+
|
"set +a\n"+
|
||||||
"echo \"Running "+packageFunctionName+"() function\"\n"+
|
"echo \"Running "+packageFunctionName+"() function...\"\n"+
|
||||||
"( cd \"$BPM_SOURCE\" && fakeroot -s \"$BPM_WORKDIR\"/fakeroot_file bash -e -c '"+packageFunctionName+"' ) || exit 1\n"+ // Run package() function
|
"( cd \"$BPM_SOURCE\" && fakeroot -s \"$BPM_WORKDIR\"/fakeroot_file bash -e -c '"+packageFunctionName+"' ) || exit 1\n") // Run package() function
|
||||||
"fakeroot -i \"$BPM_WORKDIR\"/fakeroot_file find \"$BPM_OUTPUT\" -mindepth 1 -printf \"%P %#m %U %G %s\\n\" > \"$BPM_WORKDIR\"/pkg.files") // Create package file list
|
|
||||||
|
|
||||||
cmd.Dir = tempDirectory
|
cmd.Dir = tempDirectory
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -232,7 +234,92 @@ func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks, k
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strip all ELF binaries
|
||||||
|
if !slices.Contains(pkg.Options, "nostrip") {
|
||||||
|
if _, err := exec.LookPath("strip"); err != nil {
|
||||||
|
fmt.Println("Skip stripping ELF binaries. 'strip' not in path")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Stripping ELF binaries...")
|
||||||
|
|
||||||
|
err = filepath.WalkDir(path.Join(tempDirectory, "output_"+pkg.Name), func(path string, d fs.DirEntry, err error) error {
|
||||||
|
cmd = exec.Command("file", "-bi", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mimetype := strings.Split(string(output), ";")[0]
|
||||||
|
|
||||||
|
if strings.HasPrefix(mimetype, "application/x-executable") {
|
||||||
|
cmd := exec.Command("strip", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Stripped %s (%s)\n", path, mimetype)
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(mimetype, "application/x-pie-executable") || strings.HasPrefix(mimetype, "application/x-sharedlib") {
|
||||||
|
cmd = exec.Command("file", "-b", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
output, err = cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Skip files that use ELF as a container format
|
||||||
|
if strings.Contains(string(output), "no machine") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("strip", "--strip-unneeded", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Stripped %s (%s)\n", path, mimetype)
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(mimetype, "application/x-archive") {
|
||||||
|
cmd := exec.Command("strip", "--strip-debug", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Stripped %s (%s)\n", path, mimetype)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate package file list
|
||||||
|
fmt.Println("Generating package file list...")
|
||||||
|
cmd = exec.Command("bash", "-c", "fakeroot -i \"$BPM_WORKDIR\"/fakeroot_file find \"$BPM_OUTPUT\" -mindepth 1 -printf \"%P %#m %U %G %s\\n\" > \"$BPM_WORKDIR\"/pkg.files")
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Env = append(env, "BPM_OUTPUT="+path.Join(tempDirectory, "output_"+pkg.Name))
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Create gzip-compressed archive for the package files
|
// Create gzip-compressed archive for the package files
|
||||||
|
fmt.Println("Generating compressed file archive...")
|
||||||
cmd = exec.Command("bash", "-c", fmt.Sprintf("find %s -printf \"%%P\\n\" | fakeroot -i %s/fakeroot_file tar -czf files.tar.gz --no-recursion -C %s -T -", "output_"+pkg.Name, tempDirectory, "output_"+pkg.Name))
|
cmd = exec.Command("bash", "-c", fmt.Sprintf("find %s -printf \"%%P\\n\" | fakeroot -i %s/fakeroot_file tar -czf files.tar.gz --no-recursion -C %s -T -", "output_"+pkg.Name, tempDirectory, "output_"+pkg.Name))
|
||||||
cmd.Dir = tempDirectory
|
cmd.Dir = tempDirectory
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -286,6 +373,7 @@ func CompileSourcePackage(archiveFilename, outputDirectory string, skipChecks, k
|
|||||||
bpmArchiveFiles = append(bpmArchiveFiles, packageScripts...) // Package scripts
|
bpmArchiveFiles = append(bpmArchiveFiles, packageScripts...) // Package scripts
|
||||||
|
|
||||||
// Create final BPM archive
|
// Create final BPM archive
|
||||||
|
fmt.Println("Generating final BPM archive...")
|
||||||
cmd = exec.Command("bash", "-c", "tar -cf final-archive.bpm --owner=0 --group=0 -C \"$BPM_WORKDIR\" "+strings.Join(bpmArchiveFiles, " "))
|
cmd = exec.Command("bash", "-c", "tar -cf final-archive.bpm --owner=0 --group=0 -C \"$BPM_WORKDIR\" "+strings.Join(bpmArchiveFiles, " "))
|
||||||
cmd.Dir = tempDirectory
|
cmd.Dir = tempDirectory
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -347,10 +435,12 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string, verbose bo
|
|||||||
// Replace variables
|
// Replace variables
|
||||||
replaceVars := func(s string) string {
|
replaceVars := func(s string) string {
|
||||||
switch s {
|
switch s {
|
||||||
case "BPM_PKG_VERSION":
|
|
||||||
return pkgInfo.Version
|
|
||||||
case "BPM_PKG_NAME":
|
case "BPM_PKG_NAME":
|
||||||
return pkgInfo.Name
|
return pkgInfo.Name
|
||||||
|
case "BPM_PKG_VERSION":
|
||||||
|
return pkgInfo.Version
|
||||||
|
case "BPM_PKG_URL":
|
||||||
|
return pkgInfo.Url
|
||||||
case "BPM_SOURCE":
|
case "BPM_SOURCE":
|
||||||
return path.Join(tempDirectory, "source/")
|
return path.Join(tempDirectory, "source/")
|
||||||
default:
|
default:
|
||||||
@@ -362,6 +452,10 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string, verbose bo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
filepath, err := envsubst.Eval(strings.TrimSpace(download.Filepath), replaceVars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
extractTo, err := envsubst.Eval(strings.TrimSpace(download.ExtractTo), replaceVars)
|
extractTo, err := envsubst.Eval(strings.TrimSpace(download.ExtractTo), replaceVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -382,12 +476,14 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string, verbose bo
|
|||||||
|
|
||||||
switch download.Type {
|
switch download.Type {
|
||||||
case "", "file":
|
case "", "file":
|
||||||
filepath := path.Join(tempDirectory, path.Base(downloadUrl))
|
if filepath == "" {
|
||||||
if download.Filepath != "" && download.Filepath[0] != '/' {
|
filepath = path.Join(tempDirectory, path.Base(downloadUrl))
|
||||||
filepath = path.Join(tempDirectory, download.Filepath)
|
}
|
||||||
|
if filepath[0] != '/' {
|
||||||
|
filepath = path.Join(tempDirectory, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := downloadFile(downloadUrl, filepath, 0644)
|
err := downloadFile("Downloading file "+path.Base(filepath), downloadUrl, filepath, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -464,10 +560,12 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string, verbose bo
|
|||||||
gitBranch := download.GitBranch
|
gitBranch := download.GitBranch
|
||||||
gitBranch, err := envsubst.Eval(gitBranch, func(s string) string {
|
gitBranch, err := envsubst.Eval(gitBranch, func(s string) string {
|
||||||
switch s {
|
switch s {
|
||||||
case "BPM_PKG_VERSION":
|
|
||||||
return pkgInfo.Version
|
|
||||||
case "BPM_PKG_NAME":
|
case "BPM_PKG_NAME":
|
||||||
return pkgInfo.Name
|
return pkgInfo.Name
|
||||||
|
case "BPM_PKG_VERSION":
|
||||||
|
return pkgInfo.Version
|
||||||
|
case "BPM_PKG_URL":
|
||||||
|
return pkgInfo.Url
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
+62
-17
@@ -1,9 +1,12 @@
|
|||||||
package bpmlib
|
package bpmlib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"maps"
|
"maps"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -25,8 +28,8 @@ type BPMDatabase struct {
|
|||||||
type BPMDatabaseEntry struct {
|
type BPMDatabaseEntry struct {
|
||||||
Info *PackageInfo `yaml:"info"`
|
Info *PackageInfo `yaml:"info"`
|
||||||
Filepath string `yaml:"filepath"`
|
Filepath string `yaml:"filepath"`
|
||||||
DownloadSize uint64 `yaml:"download_size"`
|
DownloadSize int64 `yaml:"download_size"`
|
||||||
InstalledSize uint64 `yaml:"installed_size"`
|
InstalledSize int64 `yaml:"installed_size"`
|
||||||
Database *BPMDatabase
|
Database *BPMDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,11 +63,12 @@ func (db *configDatabase) ReadLocalDatabase() error {
|
|||||||
database.Name = db.Name
|
database.Name = db.Name
|
||||||
database.Source = db.Source
|
database.Source = db.Source
|
||||||
|
|
||||||
entriesToRemove := make([]string, 0)
|
|
||||||
for entryName, entry := range database.Entries {
|
for entryName, entry := range database.Entries {
|
||||||
entry.Database = database
|
entry.Database = database
|
||||||
|
|
||||||
if entry.Info.IsSplitPackage() {
|
if entry.Info.IsSplitPackage() {
|
||||||
|
delete(database.Entries, entryName)
|
||||||
|
|
||||||
// Handle split packages
|
// Handle split packages
|
||||||
for _, splitPkg := range entry.Info.SplitPackages {
|
for _, splitPkg := range entry.Info.SplitPackages {
|
||||||
// Turn split package into json data
|
// Turn split package into json data
|
||||||
@@ -103,9 +107,6 @@ func (db *configDatabase) ReadLocalDatabase() error {
|
|||||||
for _, p := range splitPkg.Provides {
|
for _, p := range splitPkg.Provides {
|
||||||
database.VirtualPackages[p] = append(database.VirtualPackages[p], splitPkg.Name)
|
database.VirtualPackages[p] = append(database.VirtualPackages[p], splitPkg.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add current entry to list for removal
|
|
||||||
entriesToRemove = append(entriesToRemove, entryName)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Add virtual packages to database
|
// Add virtual packages to database
|
||||||
@@ -115,11 +116,6 @@ func (db *configDatabase) ReadLocalDatabase() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove entries
|
|
||||||
for _, entryName := range entriesToRemove {
|
|
||||||
delete(database.Entries, entryName)
|
|
||||||
}
|
|
||||||
|
|
||||||
BPMDatabases[db.Name] = database
|
BPMDatabases[db.Name] = database
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -135,13 +131,29 @@ func (db *configDatabase) SyncLocalDatabaseFile() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data from URL
|
// Retrieve data from URL
|
||||||
buffer, err := retrieveUrlData(u)
|
req, err := http.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Create progress bar
|
||||||
|
bar := createProgressBar(resp.ContentLength, "Syncing "+db.Name, false)
|
||||||
|
|
||||||
|
// Copy data
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
_, err = io.Copy(io.MultiWriter(&buffer, bar), resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal data to ensure it is a valid BPM database
|
// Unmarshal data to ensure it is a valid BPM database
|
||||||
err = yaml.Unmarshal(buffer, &BPMDatabase{})
|
err = yaml.Unmarshal(buffer.Bytes(), &BPMDatabase{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not decode database: %s", err)
|
return fmt.Errorf("could not decode database: %s", err)
|
||||||
}
|
}
|
||||||
@@ -159,7 +171,7 @@ func (db *configDatabase) SyncLocalDatabaseFile() error {
|
|||||||
}
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
_, err = out.Write(buffer)
|
_, err = out.Write(buffer.Bytes())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -244,7 +256,7 @@ func (db *BPMDatabase) FetchPackage(pkg string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Download package from url
|
// Download package from url
|
||||||
err = downloadFile(u, path.Join("/var/cache/bpm/fetched/", path.Base(entry.Filepath)), 0644)
|
err = downloadFile("Downloading "+entry.Info.Name, u, path.Join("/var/cache/bpm/fetched/", path.Base(entry.Filepath)), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -281,6 +293,35 @@ func (entry *BPMDatabaseEntry) GetEntryDependants() (dependants []string) {
|
|||||||
return dependants
|
return dependants
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (entry *BPMDatabaseEntry) GetEntryOptionalDependants() (dependants []string) {
|
||||||
|
dependantsMap := make(map[string][]string)
|
||||||
|
for _, db := range BPMDatabases {
|
||||||
|
for _, e := range db.Entries {
|
||||||
|
if slices.Contains(e.Info.OptionalDepends, entry.Info.Name) {
|
||||||
|
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], e.Database.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get keys
|
||||||
|
keySlice := slices.Collect(maps.Keys(dependantsMap))
|
||||||
|
slices.Sort(keySlice)
|
||||||
|
|
||||||
|
// Add all dependant entries to slice in alphabetical order
|
||||||
|
for _, entryName := range keySlice {
|
||||||
|
dbs := dependantsMap[entryName]
|
||||||
|
if len(dbs) > 1 {
|
||||||
|
for _, db := range dbs {
|
||||||
|
dependants = append(dependants, db+"/"+entryName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dependants = append(dependants, entryName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependants
|
||||||
|
}
|
||||||
|
|
||||||
func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string {
|
func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableSize bool) string {
|
||||||
ret := make([]string, 0)
|
ret := make([]string, 0)
|
||||||
appendArray := func(label string, array []string, sort bool) {
|
appendArray := func(label string, array []string, sort bool) {
|
||||||
@@ -320,6 +361,10 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
|
|||||||
if len(dependants) > 0 {
|
if len(dependants) > 0 {
|
||||||
appendArray("Dependant packages", dependants, false)
|
appendArray("Dependant packages", dependants, false)
|
||||||
}
|
}
|
||||||
|
optionalDependants := entry.GetEntryOptionalDependants()
|
||||||
|
if len(optionalDependants) > 0 {
|
||||||
|
appendArray("Optionally dependant packages", optionalDependants, false)
|
||||||
|
}
|
||||||
appendArray("Conflicting packages", entry.Info.Conflicts, true)
|
appendArray("Conflicting packages", entry.Info.Conflicts, true)
|
||||||
appendArray("Provided packages", entry.Info.Provides, true)
|
appendArray("Provided packages", entry.Info.Provides, true)
|
||||||
appendArray("Replaces packages", entry.Info.Replaces, true)
|
appendArray("Replaces packages", entry.Info.Replaces, true)
|
||||||
@@ -348,10 +393,10 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
|
|||||||
ret = append(ret, "Installation Reason: "+installationReasonString)
|
ret = append(ret, "Installation Reason: "+installationReasonString)
|
||||||
}
|
}
|
||||||
if entry.Info.Type == "binary" {
|
if entry.Info.Type == "binary" {
|
||||||
installedSize := int64(entry.InstalledSize)
|
installedSize := entry.InstalledSize
|
||||||
var installedSizeStr string
|
var installedSizeStr string
|
||||||
if humanReadableSize {
|
if humanReadableSize {
|
||||||
installedSizeStr = bytesToHumanReadable(installedSize)
|
installedSizeStr = BytesToHumanReadable(installedSize)
|
||||||
} else {
|
} else {
|
||||||
installedSizeStr = strconv.FormatInt(installedSize, 10)
|
installedSizeStr = strconv.FormatInt(installedSize, 10)
|
||||||
}
|
}
|
||||||
|
|||||||
+51
-14
@@ -47,6 +47,12 @@ func (pkgInfo *PackageInfo) GetDependencies(includeMakeDepends, includeOptionalD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip ignored packages
|
||||||
|
allDepends = slices.DeleteFunc(allDepends, func(depend pkgInstallationReason) bool {
|
||||||
|
return slices.Contains(MainBPMConfig.IgnorePackages, depend.PkgName)
|
||||||
|
})
|
||||||
|
|
||||||
return allDepends
|
return allDepends
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,39 +177,70 @@ func resolvePackageDependenciesFromDatabase(resolved *[]pkgInstallationReason, u
|
|||||||
|
|
||||||
func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []string) {
|
func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string) (dependants []string) {
|
||||||
// Get installed package names
|
// Get installed package names
|
||||||
pkgs, err := GetInstalledPackages(rootDir)
|
pkgs, ok := localPackageInformation[rootDir]
|
||||||
if err != nil {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through all installed packages
|
// Loop through all installed packages
|
||||||
for _, installedPkgName := range pkgs {
|
for _, installedPkg := range pkgs {
|
||||||
// Get installed BPM package
|
|
||||||
installedPkg := GetPackage(installedPkgName, rootDir)
|
|
||||||
if installedPkg == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip iteration if comparing the same packages
|
// Skip iteration if comparing the same packages
|
||||||
if installedPkg.PkgInfo.Name == pkgInfo.Name {
|
if installedPkg.Name == pkgInfo.Name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add installed package to list if its dependencies include pkgName
|
// Add installed package to list if its dependencies include pkgName
|
||||||
if slices.ContainsFunc(installedPkg.PkgInfo.Depends, func(n string) bool {
|
if slices.ContainsFunc(installedPkg.Depends, func(n string) bool {
|
||||||
return n == pkgInfo.Name
|
return n == pkgInfo.Name
|
||||||
}) {
|
}) {
|
||||||
dependants = append(dependants, installedPkgName)
|
dependants = append(dependants, installedPkg.Name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each virtual package
|
// Loop through each virtual package
|
||||||
for _, vpkg := range pkgInfo.Provides {
|
for _, vpkg := range pkgInfo.Provides {
|
||||||
// Add installed package to list if its dependencies contain a provided virtual package
|
// Add installed package to list if its dependencies contain a provided virtual package
|
||||||
if slices.ContainsFunc(installedPkg.PkgInfo.Depends, func(n string) bool {
|
if slices.ContainsFunc(installedPkg.Depends, func(n string) bool {
|
||||||
return n == vpkg
|
return n == vpkg
|
||||||
}) {
|
}) {
|
||||||
dependants = append(dependants, installedPkgName)
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependants
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pkgInfo *PackageInfo) GetPackageOptionalDependants(rootDir string) (dependants []string) {
|
||||||
|
// Get installed package names
|
||||||
|
pkgs, ok := localPackageInformation[rootDir]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through all installed packages
|
||||||
|
for _, installedPkg := range pkgs {
|
||||||
|
// Skip iteration if comparing the same packages
|
||||||
|
if installedPkg.Name == pkgInfo.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its optional dependencies include pkgName
|
||||||
|
if slices.ContainsFunc(installedPkg.OptionalDepends, func(n string) bool {
|
||||||
|
return n == pkgInfo.Name
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each virtual package
|
||||||
|
for _, vpkg := range pkgInfo.Provides {
|
||||||
|
// Add installed package to list if its optional dependencies contain a provided virtual package
|
||||||
|
if slices.ContainsFunc(installedPkg.OptionalDepends, func(n string) bool {
|
||||||
|
return n == vpkg
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-9
@@ -21,7 +21,6 @@ const (
|
|||||||
|
|
||||||
// InstallPackages installs the specified packages into the given root directory by fetching them from databases or directly from local bpm archives
|
// InstallPackages installs the specified packages into the given root directory by fetching them from databases or directly from local bpm archives
|
||||||
func InstallPackages(rootDir string, forceInstallationReason InstallationReason, reinstallMethod ReinstallMethod, installOptionalDependencies, forceInstallation, verbose bool, packages ...string) (operation *BPMOperation, err error) {
|
func InstallPackages(rootDir string, forceInstallationReason InstallationReason, reinstallMethod ReinstallMethod, installOptionalDependencies, forceInstallation, verbose bool, packages ...string) (operation *BPMOperation, err error) {
|
||||||
|
|
||||||
// Setup operation struct
|
// Setup operation struct
|
||||||
operation = &BPMOperation{
|
operation = &BPMOperation{
|
||||||
Actions: make([]OperationAction, 0),
|
Actions: make([]OperationAction, 0),
|
||||||
@@ -31,6 +30,9 @@ func InstallPackages(rootDir string, forceInstallationReason InstallationReason,
|
|||||||
compiledPackages: make(map[string]string),
|
compiledPackages: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove duplicates from packages
|
||||||
|
packages = removeDuplicates(packages)
|
||||||
|
|
||||||
// Resolve packages
|
// Resolve packages
|
||||||
pkgsNotFound := make([]string, 0)
|
pkgsNotFound := make([]string, 0)
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
@@ -145,12 +147,9 @@ func InstallPackages(rootDir string, forceInstallationReason InstallationReason,
|
|||||||
operation.ReplaceObsoletePackages()
|
operation.ReplaceObsoletePackages()
|
||||||
|
|
||||||
// Check for conflicts
|
// Check for conflicts
|
||||||
conflicts, err := operation.CheckForConflicts()
|
conflicts := operation.CheckForConflicts()
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not complete package conflict check: %s", err)
|
|
||||||
}
|
|
||||||
if len(conflicts) > 0 {
|
if len(conflicts) > 0 {
|
||||||
err = nil
|
err = fmt.Errorf("conflicts detected")
|
||||||
for pkg, conflict := range conflicts {
|
for pkg, conflict := range conflicts {
|
||||||
err = errors.Join(err, PackageConflictErr{pkg, conflict})
|
err = errors.Join(err, PackageConflictErr{pkg, conflict})
|
||||||
}
|
}
|
||||||
@@ -196,6 +195,9 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ..
|
|||||||
compiledPackages: make(map[string]string),
|
compiledPackages: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove duplicates from packages
|
||||||
|
packages = removeDuplicates(packages)
|
||||||
|
|
||||||
// Search for packages
|
// Search for packages
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
bpmpkg := GetPackage(pkg, rootDir)
|
bpmpkg := GetPackage(pkg, rootDir)
|
||||||
@@ -221,6 +223,11 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ..
|
|||||||
// Get packages and their dependants
|
// Get packages and their dependants
|
||||||
packageDepndants := make(map[string][]string, 0)
|
packageDepndants := make(map[string][]string, 0)
|
||||||
for _, action := range operation.Actions {
|
for _, action := range operation.Actions {
|
||||||
|
// Skip package if ignored
|
||||||
|
if slices.Contains(MainBPMConfig.IgnorePackages, action.(*RemovePackageAction).BpmPackage.PkgInfo.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir)
|
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir)
|
||||||
packageDepndants[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = dependants
|
packageDepndants[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = dependants
|
||||||
}
|
}
|
||||||
@@ -234,6 +241,14 @@ func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ..
|
|||||||
packageDepndants[pkg] = required
|
packageDepndants[pkg] = required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove dependant packages if ignored
|
||||||
|
for pkg, required := range packageDepndants {
|
||||||
|
required = slices.DeleteFunc(required, func(pkgName string) bool {
|
||||||
|
return slices.Contains(MainBPMConfig.IgnorePackages, pkgName)
|
||||||
|
})
|
||||||
|
packageDepndants[pkg] = required
|
||||||
|
}
|
||||||
|
|
||||||
// Remove empty keys from map
|
// Remove empty keys from map
|
||||||
maps.DeleteFunc(packageDepndants, func(pkg string, required []string) bool {
|
maps.DeleteFunc(packageDepndants, func(pkg string, required []string) bool {
|
||||||
return len(required) == 0
|
return len(required) == 0
|
||||||
@@ -350,7 +365,7 @@ func CleanupCache(rootDir string, cleanupCompilationFiles, cleanupCompiledPackag
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePackages fetches the newest versions of all installed packages from
|
// UpdatePackages fetches the newest versions of all installed packages from
|
||||||
func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependencies, forceInstallation, verbose bool) (operation *BPMOperation, err error) {
|
func UpdatePackages(rootDir string, syncDatabase bool, allowDowngrades bool, installOptionalDependencies, forceInstallation, verbose bool) (operation *BPMOperation, err error) {
|
||||||
// Sync databases
|
// Sync databases
|
||||||
if syncDatabase {
|
if syncDatabase {
|
||||||
err := SyncDatabase(verbose)
|
err := SyncDatabase(verbose)
|
||||||
@@ -403,8 +418,8 @@ 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 (!allowDowngrades && comparison > 0) || (allowDowngrades && comparison != 0) {
|
||||||
operation.AppendAction(&FetchPackageAction{
|
operation.AppendAction(&FetchPackageAction{
|
||||||
InstallationReason: GetInstallationReason(pkg, rootDir),
|
InstallationReason: GetInstallationReason(pkg, rootDir),
|
||||||
DatabaseEntry: entry,
|
DatabaseEntry: entry,
|
||||||
@@ -428,6 +443,21 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
|||||||
|
|
||||||
// Replace obsolete packages
|
// Replace obsolete packages
|
||||||
operation.ReplaceObsoletePackages()
|
operation.ReplaceObsoletePackages()
|
||||||
|
|
||||||
|
// Check for conflicts
|
||||||
|
conflicts := operation.CheckForConflicts()
|
||||||
|
if len(conflicts) > 0 {
|
||||||
|
err = fmt.Errorf("conflicts detected")
|
||||||
|
for pkg, conflict := range conflicts {
|
||||||
|
err = errors.Join(err, PackageConflictErr{pkg, conflict})
|
||||||
|
}
|
||||||
|
if !forceInstallation {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
log.Printf("Warning: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return operation, nil
|
return operation, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -1,9 +1,17 @@
|
|||||||
module git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib
|
module github.com/EnumeratedDev/bpm/src/bpmlib
|
||||||
|
|
||||||
go 1.23
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/drone/envsubst v1.0.3
|
github.com/drone/envsubst v1.0.3
|
||||||
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
|
golang.org/x/sys v0.37.0 // indirect
|
||||||
|
golang.org/x/term v0.36.0 // indirect
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,9 +1,29 @@
|
|||||||
|
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
|
||||||
|
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
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 h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
|
||||||
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
||||||
|
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
|
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
|
||||||
|
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
|
||||||
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=
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var localPackageInformation map[string]map[string]*BPMPackage = make(map[string]map[string]*BPMPackage)
|
var localPackageInformation map[string]map[string]*PackageInfo = make(map[string]map[string]*PackageInfo)
|
||||||
|
|
||||||
func initializeLocalPackageInformation(rootDir string) (err error) {
|
func initializeLocalPackageInformation(rootDir string) (err error) {
|
||||||
// Return if information is already initialized
|
// Return if information is already initialized
|
||||||
@@ -17,7 +17,7 @@ func initializeLocalPackageInformation(rootDir string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
tempPackageInformation := make(map[string]*BPMPackage)
|
tempPackageInformation := make(map[string]*PackageInfo)
|
||||||
|
|
||||||
// Get path to installed package information directory
|
// Get path to installed package information directory
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
@@ -25,7 +25,7 @@ func initializeLocalPackageInformation(rootDir string) (err error) {
|
|||||||
// Get directory content
|
// Get directory content
|
||||||
items, err := os.ReadDir(installedDir)
|
items, err := os.ReadDir(installedDir)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
localPackageInformation[rootDir] = make(map[string]*BPMPackage)
|
localPackageInformation[rootDir] = make(map[string]*PackageInfo)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -49,14 +49,8 @@ func initializeLocalPackageInformation(rootDir string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read package files
|
|
||||||
files := getPackageFiles(info.Name, rootDir)
|
|
||||||
|
|
||||||
// Add package to slice
|
// Add package to slice
|
||||||
tempPackageInformation[info.Name] = &BPMPackage{
|
tempPackageInformation[info.Name] = info
|
||||||
PkgInfo: info,
|
|
||||||
PkgFiles: files,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
localPackageInformation[rootDir] = tempPackageInformation
|
localPackageInformation[rootDir] = tempPackageInformation
|
||||||
@@ -71,8 +65,8 @@ func GetInstalledPackages(rootDir string) (ret []string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each package and add it to slice
|
// Loop through each package and add it to slice
|
||||||
for _, bpmpkg := range localPackageInformation[rootDir] {
|
for _, pkgInfo := range localPackageInformation[rootDir] {
|
||||||
ret = append(ret, bpmpkg.PkgInfo.Name)
|
ret = append(ret, pkgInfo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort packages
|
// Sort packages
|
||||||
@@ -94,18 +88,6 @@ func IsPackageInstalled(pkg, rootDir string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPackageInfo(pkg string, rootDir string) *PackageInfo {
|
|
||||||
// Get BPM package
|
|
||||||
bpmpkg := GetPackage(pkg, rootDir)
|
|
||||||
|
|
||||||
// Return nil if not found
|
|
||||||
if bpmpkg == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return bpmpkg.PkgInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsVirtualPackage(pkg, rootDir string) (bool, string) {
|
func IsVirtualPackage(pkg, rootDir string) (bool, string) {
|
||||||
pkgs, err := GetInstalledPackages(rootDir)
|
pkgs, err := GetInstalledPackages(rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -146,15 +128,27 @@ func IsPackageProvided(pkg, rootDir string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPackage(pkg, rootDir string) *BPMPackage {
|
func GetPackageInfo(pkg string, rootDir string) *PackageInfo {
|
||||||
err := initializeLocalPackageInformation(rootDir)
|
err := initializeLocalPackageInformation(rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bpmpkg := localPackageInformation[rootDir][pkg]
|
return localPackageInformation[rootDir][pkg]
|
||||||
|
}
|
||||||
|
|
||||||
return bpmpkg
|
func GetPackage(pkg, rootDir string) *BPMPackage {
|
||||||
|
pkgInfo := GetPackageInfo(pkg, rootDir)
|
||||||
|
if pkgInfo == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
files := getPackageFiles(pkgInfo.Name, rootDir)
|
||||||
|
|
||||||
|
return &BPMPackage{
|
||||||
|
PkgInfo: pkgInfo,
|
||||||
|
PkgFiles: files,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllPackageFiles(rootDir string, excludePackages ...string) (map[string][]*BPMPackage, error) {
|
func GetAllPackageFiles(rootDir string, excludePackages ...string) (map[string][]*BPMPackage, error) {
|
||||||
@@ -225,7 +219,7 @@ func getPackageFiles(pkg, rootDir string) []*PackageFileEntry {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
size, err := strconv.ParseUint(stringEntry[len(stringEntry)-1], 0, 64)
|
size, err := strconv.ParseInt(stringEntry[len(stringEntry)-1], 0, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-16
@@ -9,29 +9,22 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func retrieveUrlData(u string) ([]byte, error) {
|
func downloadFile(barText, u, filepath string, perm os.FileMode) error {
|
||||||
resp, err := http.Get(u)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
// Load data into byte buffer
|
|
||||||
buffer, err := io.ReadAll(resp.Body)
|
|
||||||
|
|
||||||
return buffer, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func downloadFile(u, filepath string, perm os.FileMode) error {
|
|
||||||
if strings.HasSuffix(filepath, "/") {
|
if strings.HasSuffix(filepath, "/") {
|
||||||
return fmt.Errorf("Filepath must not end in '/'")
|
return fmt.Errorf("Filepath must not end in '/'")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := retrieveUrlData(u)
|
req, err := http.NewRequest("GET", u, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// Create parent directories
|
// Create parent directories
|
||||||
err = os.MkdirAll(path.Dir(filepath), 0755)
|
err = os.MkdirAll(path.Dir(filepath), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -45,8 +38,12 @@ func downloadFile(u, filepath string, perm os.FileMode) error {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
// Create progress bar
|
||||||
|
bar := createProgressBar(resp.ContentLength, barText, false)
|
||||||
|
defer bar.Close()
|
||||||
|
|
||||||
// Copy data
|
// Copy data
|
||||||
_, err = file.Write(data)
|
_, err = io.Copy(io.MultiWriter(file, bar), resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+135
-56
@@ -87,8 +87,8 @@ func (operation *BPMOperation) RemoveAction(pkg, actionType string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) GetTotalDownloadSize() uint64 {
|
func (operation *BPMOperation) GetTotalDownloadSize() int64 {
|
||||||
var ret uint64 = 0
|
var ret int64 = 0
|
||||||
for _, action := range operation.Actions {
|
for _, action := range operation.Actions {
|
||||||
if action.GetActionType() == "fetch" {
|
if action.GetActionType() == "fetch" {
|
||||||
ret += action.(*FetchPackageAction).DatabaseEntry.DownloadSize
|
ret += action.(*FetchPackageAction).DatabaseEntry.DownloadSize
|
||||||
@@ -97,8 +97,8 @@ func (operation *BPMOperation) GetTotalDownloadSize() uint64 {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) GetTotalInstalledSize() uint64 {
|
func (operation *BPMOperation) GetTotalInstalledSize() int64 {
|
||||||
var ret uint64 = 0
|
var ret int64 = 0
|
||||||
for _, action := range operation.Actions {
|
for _, action := range operation.Actions {
|
||||||
if action.GetActionType() == "install" {
|
if action.GetActionType() == "install" {
|
||||||
ret += action.(*InstallPackageAction).BpmPackage.GetInstalledSize()
|
ret += action.(*InstallPackageAction).BpmPackage.GetInstalledSize()
|
||||||
@@ -113,14 +113,17 @@ func (operation *BPMOperation) GetFinalActionSize(rootDir string) int64 {
|
|||||||
var ret int64 = 0
|
var ret int64 = 0
|
||||||
for _, action := range operation.Actions {
|
for _, action := range operation.Actions {
|
||||||
if action.GetActionType() == "install" {
|
if action.GetActionType() == "install" {
|
||||||
ret += int64(action.(*InstallPackageAction).BpmPackage.GetInstalledSize())
|
ret += action.(*InstallPackageAction).BpmPackage.GetInstalledSize()
|
||||||
if IsPackageInstalled(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir) {
|
if IsPackageInstalled(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir) {
|
||||||
ret -= int64(GetPackage(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir).GetInstalledSize())
|
ret -= GetPackage(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir).GetInstalledSize()
|
||||||
}
|
}
|
||||||
} else if action.GetActionType() == "fetch" {
|
} else if action.GetActionType() == "fetch" {
|
||||||
ret += int64(action.(*FetchPackageAction).DatabaseEntry.InstalledSize)
|
ret += action.(*FetchPackageAction).DatabaseEntry.InstalledSize
|
||||||
|
if IsPackageInstalled(action.(*FetchPackageAction).DatabaseEntry.Info.Name, rootDir) {
|
||||||
|
ret -= action.(*FetchPackageAction).DatabaseEntry.InstalledSize
|
||||||
|
}
|
||||||
} else if action.GetActionType() == "remove" {
|
} else if action.GetActionType() == "remove" {
|
||||||
ret -= int64(action.(*RemovePackageAction).BpmPackage.GetInstalledSize())
|
ret -= action.(*RemovePackageAction).BpmPackage.GetInstalledSize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
@@ -229,7 +232,7 @@ func (operation *BPMOperation) Cleanup(cleanupMakeDepends bool) error {
|
|||||||
keepPackages = append(keepPackages, pkg.Name)
|
keepPackages = append(keepPackages, pkg.Name)
|
||||||
resolved := pkg.GetDependenciesRecursive(!cleanupMakeDepends, operation.RootDir)
|
resolved := pkg.GetDependenciesRecursive(!cleanupMakeDepends, operation.RootDir)
|
||||||
for _, value := range resolved {
|
for _, value := range resolved {
|
||||||
if !slices.Contains(keepPackages, value) {
|
if !slices.Contains(keepPackages, value) && !slices.Contains(MainBPMConfig.IgnorePackages, value) {
|
||||||
keepPackages = append(keepPackages, value)
|
keepPackages = append(keepPackages, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,54 +280,92 @@ func (operation *BPMOperation) ReplaceObsoletePackages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) CheckForConflicts() (map[string][]string, error) {
|
func (operation *BPMOperation) CheckForConflicts() map[string][]string {
|
||||||
conflicts := make(map[string][]string)
|
conflicts := make(map[string][]string)
|
||||||
installedPackages, err := GetInstalledPackages(operation.RootDir)
|
|
||||||
if err != nil {
|
// Get installed packages
|
||||||
return nil, err
|
installedPackages := localPackageInformation[operation.RootDir]
|
||||||
}
|
|
||||||
allPackages := make([]*PackageInfo, len(installedPackages))
|
// Get packages to be removed
|
||||||
for i, value := range installedPackages {
|
removedPackages := make([]string, 0)
|
||||||
bpmpkg := GetPackage(value, operation.RootDir)
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
if bpmpkg == nil {
|
if value.GetActionType() != "remove" {
|
||||||
return nil, fmt.Errorf("could not find installed package (%s)", value)
|
continue
|
||||||
}
|
}
|
||||||
allPackages[i] = bpmpkg.PkgInfo
|
|
||||||
|
removedPackages = append(removedPackages, value.(*RemovePackageAction).BpmPackage.PkgInfo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all new packages to the allPackages slice
|
// Check for conflicts
|
||||||
for _, value := range slices.Clone(operation.Actions) {
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
if value.GetActionType() == "install" {
|
if value.GetActionType() == "install" {
|
||||||
action := value.(*InstallPackageAction)
|
pkgInfo = value.(*InstallPackageAction).BpmPackage.PkgInfo
|
||||||
pkgInfo := action.BpmPackage.PkgInfo
|
|
||||||
allPackages = append(allPackages, pkgInfo)
|
|
||||||
} else if value.GetActionType() == "fetch" {
|
} else if value.GetActionType() == "fetch" {
|
||||||
action := value.(*FetchPackageAction)
|
pkgInfo = value.(*FetchPackageAction).DatabaseEntry.Info
|
||||||
pkgInfo := action.DatabaseEntry.Info
|
} else {
|
||||||
allPackages = append(allPackages, pkgInfo)
|
continue
|
||||||
} else if value.GetActionType() == "remove" {
|
}
|
||||||
action := value.(*RemovePackageAction)
|
|
||||||
pkgInfo := action.BpmPackage.PkgInfo
|
// Check for conflicts with installed packages
|
||||||
for i := len(allPackages) - 1; i >= 0; i-- {
|
for _, installedPkg := range installedPackages {
|
||||||
info := allPackages[i]
|
// Skip if package is to be removed
|
||||||
if info.Name == pkgInfo.Name {
|
if slices.Contains(removedPackages, installedPkg.Name) {
|
||||||
allPackages = append(allPackages[:i], allPackages[i+1:]...)
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if same package
|
||||||
|
if pkgInfo.Name == installedPkg.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for new package conflicts
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, installedPkg.Name) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], installedPkg.Name)
|
||||||
|
}
|
||||||
|
for _, vpkg := range installedPkg.Provides {
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, vpkg) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], vpkg+" ("+installedPkg.Name+")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for installed package conflicts
|
||||||
|
for _, vpkg := range pkgInfo.Provides {
|
||||||
|
if slices.Contains(installedPkg.Conflicts, vpkg) {
|
||||||
|
conflicts[installedPkg.Name] = append(conflicts[installedPkg.Name], vpkg+" ("+pkgInfo.Name+")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for conflicts with other new packages
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo2 *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
pkgInfo2 = value.(*InstallPackageAction).BpmPackage.PkgInfo
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
pkgInfo2 = value.(*FetchPackageAction).DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if same package
|
||||||
|
if pkgInfo.Name == pkgInfo2.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for other package conflicts
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, pkgInfo2.Name) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], pkgInfo2.Name)
|
||||||
|
}
|
||||||
|
for _, vpkg := range pkgInfo2.Provides {
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, vpkg) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], vpkg+" ("+pkgInfo2.Name+")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range allPackages {
|
return conflicts
|
||||||
for _, conflict := range value.Conflicts {
|
|
||||||
if slices.ContainsFunc(allPackages, func(info *PackageInfo) bool {
|
|
||||||
return info.Name == conflict
|
|
||||||
}) {
|
|
||||||
conflicts[value.Name] = append(conflicts[value.Name], conflict)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return conflicts, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) ShowOperationSummary() {
|
func (operation *BPMOperation) ShowOperationSummary() {
|
||||||
@@ -370,7 +411,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 {
|
||||||
@@ -388,12 +429,12 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
|||||||
fmt.Println("Warning: Operating in " + operation.RootDir)
|
fmt.Println("Warning: Operating in " + operation.RootDir)
|
||||||
}
|
}
|
||||||
if operation.GetTotalDownloadSize() > 0 {
|
if operation.GetTotalDownloadSize() > 0 {
|
||||||
fmt.Printf("%s will be downloaded to complete this operation\n", unsignedBytesToHumanReadable(operation.GetTotalDownloadSize()))
|
fmt.Printf("%s will be downloaded to complete this operation\n", BytesToHumanReadable(operation.GetTotalDownloadSize()))
|
||||||
}
|
}
|
||||||
if operation.GetFinalActionSize(operation.RootDir) > 0 {
|
if operation.GetFinalActionSize(operation.RootDir) > 0 {
|
||||||
fmt.Printf("A total of %s will be installed after the operation finishes\n", bytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)))
|
fmt.Printf("A total of %s will be installed after the operation finishes\n", BytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)))
|
||||||
} else if operation.GetFinalActionSize(operation.RootDir) < 0 {
|
} else if operation.GetFinalActionSize(operation.RootDir) < 0 {
|
||||||
fmt.Printf("A total of %s will be freed after the operation finishes\n", strings.TrimPrefix(bytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)), "-"))
|
fmt.Printf("A total of %s will be freed after the operation finishes\n", strings.TrimPrefix(BytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)), "-"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,6 +466,40 @@ func (operation *BPMOperation) ShowSourcePackageContent() (sourcePackagesShown i
|
|||||||
return sourcePackagesShown, nil
|
return sourcePackagesShown, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) GetOptionalDependencies() (optionalDepends map[string][]string) {
|
||||||
|
optionalDepends = make(map[string][]string)
|
||||||
|
|
||||||
|
// Find all optional dependencies
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
action := value.(*InstallPackageAction)
|
||||||
|
pkgInfo = action.BpmPackage.PkgInfo
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
action := value.(*FetchPackageAction)
|
||||||
|
pkgInfo = action.DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, depend := range pkgInfo.OptionalDepends {
|
||||||
|
// Skip if dependency is already installed
|
||||||
|
if IsPackageInstalled(depend, operation.RootDir) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if not a new dependency of the package
|
||||||
|
if installedPkg := GetPackage(pkgInfo.Name, operation.RootDir); installedPkg != nil && slices.Contains(installedPkg.PkgInfo.OptionalDepends, depend) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
optionalDepends[pkgInfo.Name] = append(optionalDepends[pkgInfo.Name], depend)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) RunHooks(verbose bool) error {
|
func (operation *BPMOperation) RunHooks(verbose bool) error {
|
||||||
// Return if hooks directory does not exist
|
// Return if hooks directory does not exist
|
||||||
if stat, err := os.Stat(path.Join(operation.RootDir, "var/lib/bpm/hooks")); err != nil || !stat.IsDir() {
|
if stat, err := os.Stat(path.Join(operation.RootDir, "var/lib/bpm/hooks")); err != nil || !stat.IsDir() {
|
||||||
@@ -478,7 +553,7 @@ func (operation *BPMOperation) FetchPackages() (err error) {
|
|||||||
var bpmpkg *BPMPackage
|
var bpmpkg *BPMPackage
|
||||||
|
|
||||||
// Check if package has already been fetched from download link
|
// Check if package has already been fetched from download link
|
||||||
if _, ok := fetchedPackages[entry.Filepath]; !ok {
|
if fetchedFilepath, ok := fetchedPackages[entry.Filepath]; !ok {
|
||||||
// Fetch package from database
|
// Fetch package from database
|
||||||
fetchedPackage, err := entry.Database.FetchPackage(entry.Info.Name)
|
fetchedPackage, err := entry.Database.FetchPackage(entry.Info.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -493,16 +568,22 @@ func (operation *BPMOperation) FetchPackages() (err error) {
|
|||||||
|
|
||||||
// Add fetched package to map
|
// Add fetched package to map
|
||||||
fetchedPackages[entry.Filepath] = fetchedPackage
|
fetchedPackages[entry.Filepath] = fetchedPackage
|
||||||
|
|
||||||
fmt.Printf("Package (%s) was successfully fetched!\n", entry.Info.Name)
|
|
||||||
} else {
|
} else {
|
||||||
// Read fetched package
|
// Read fetched package
|
||||||
bpmpkg, err = ReadPackage(fetchedPackages[entry.Filepath])
|
bpmpkg, err = ReadPackage(fetchedFilepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read package (%s): %s\n", entry.Info.Name, err)
|
return fmt.Errorf("could not read package (%s): %s\n", entry.Info.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Package (%s) was successfully fetched!\n", entry.Info.Name)
|
// Get size of fetched archive
|
||||||
|
stat, err := os.Stat(fetchedFilepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bar := createProgressBar(stat.Size(), "Downloading "+entry.Info.Name, false)
|
||||||
|
bar.Set64(stat.Size())
|
||||||
|
bar.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if bpmpkg.PkgInfo.IsSplitPackage() {
|
if bpmpkg.PkgInfo.IsSplitPackage() {
|
||||||
@@ -622,8 +703,6 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err)
|
return fmt.Errorf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Package (%s) was successfully installed\n", bpmpkg.PkgInfo.Name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("Operation complete!")
|
fmt.Println("Operation complete!")
|
||||||
|
|||||||
+106
-65
@@ -17,7 +17,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
version "github.com/knqyf263/go-rpm-version"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,6 +42,7 @@ type PackageInfo struct {
|
|||||||
Conflicts []string `yaml:"conflicts,omitempty"`
|
Conflicts []string `yaml:"conflicts,omitempty"`
|
||||||
Replaces []string `yaml:"replaces,omitempty"`
|
Replaces []string `yaml:"replaces,omitempty"`
|
||||||
Provides []string `yaml:"provides,omitempty"`
|
Provides []string `yaml:"provides,omitempty"`
|
||||||
|
Options []string `yaml:"options,omitempty"`
|
||||||
Downloads []PackageDownload `yaml:"downloads,omitempty"`
|
Downloads []PackageDownload `yaml:"downloads,omitempty"`
|
||||||
SplitPackages []*PackageInfo `yaml:"split_packages,omitempty"`
|
SplitPackages []*PackageInfo `yaml:"split_packages,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ 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"`
|
||||||
Filepath string `yaml:"filepath,omitempty,omitempty"`
|
Filepath string `yaml:"filepath,omitempty"`
|
||||||
|
|
||||||
// Archive options
|
// Archive options
|
||||||
NoExtract bool `yaml:"no_extract,omitempty"`
|
NoExtract bool `yaml:"no_extract,omitempty"`
|
||||||
@@ -69,11 +69,11 @@ type PackageFileEntry struct {
|
|||||||
OctalPerms uint32
|
OctalPerms uint32
|
||||||
UserID int
|
UserID int
|
||||||
GroupID int
|
GroupID int
|
||||||
SizeInBytes uint64
|
SizeInBytes int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pkg *BPMPackage) GetInstalledSize() uint64 {
|
func (pkg *BPMPackage) GetInstalledSize() int64 {
|
||||||
var totalSize uint64 = 0
|
var totalSize int64 = 0
|
||||||
for _, entry := range pkg.PkgFiles {
|
for _, entry := range pkg.PkgFiles {
|
||||||
totalSize += entry.SizeInBytes
|
totalSize += entry.SizeInBytes
|
||||||
}
|
}
|
||||||
@@ -120,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)
|
||||||
@@ -239,7 +232,7 @@ func ReadPackage(filename string) (*BPMPackage, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
size, err := strconv.ParseUint(stringEntry[len(stringEntry)-1], 0, 64)
|
size, err := strconv.ParseInt(stringEntry[len(stringEntry)-1], 0, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -375,9 +368,44 @@ func executePackageScript(pkg, rootDir string, verbose bool, packageScript strin
|
|||||||
cmd := exec.Command("/bin/bash", "-c", content)
|
cmd := exec.Command("/bin/bash", "-c", content)
|
||||||
// Setup subprocess environment
|
// Setup subprocess environment
|
||||||
cmd.Dir = "/"
|
cmd.Dir = "/"
|
||||||
// Run hook in chroot if using the -R flag
|
// Run package script in chroot if using the -R flag
|
||||||
if rootDir != "/" {
|
if rootDir != "/" {
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{Chroot: rootDir}
|
cmd.SysProcAttr = &syscall.SysProcAttr{Chroot: rootDir}
|
||||||
|
|
||||||
|
// Bind mount /etc/resolv.conf
|
||||||
|
mounted, err := func() (bool, error) {
|
||||||
|
if _, err := os.Stat("/etc/resolv.conf"); err != nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(path.Join(rootDir, "etc/resolv.conf")); os.IsNotExist(err) {
|
||||||
|
err = os.WriteFile(path.Join(rootDir, "/etc/resolv.conf"), nil, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
mntCmd := exec.Command("mount", "-o", "ro,bind", "/etc/resolv.conf", path.Join(rootDir, "/etc/resolv.conf"))
|
||||||
|
if verbose {
|
||||||
|
mntCmd.Stdout = os.Stdout
|
||||||
|
mntCmd.Stderr = os.Stderr
|
||||||
|
}
|
||||||
|
err = mntCmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if mounted {
|
||||||
|
defer exec.Command("umount", "-f", path.Join(rootDir, "/etc/resolv.conf")).Run()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Show output if verbose
|
// Show output if verbose
|
||||||
if verbose {
|
if verbose {
|
||||||
@@ -434,6 +462,7 @@ func ReadPackageInfo(contents string) (*PackageInfo, error) {
|
|||||||
Conflicts: make([]string, 0),
|
Conflicts: make([]string, 0),
|
||||||
Replaces: make([]string, 0),
|
Replaces: make([]string, 0),
|
||||||
Provides: make([]string, 0),
|
Provides: make([]string, 0),
|
||||||
|
Options: make([]string, 0),
|
||||||
Downloads: make([]PackageDownload, 0),
|
Downloads: make([]PackageDownload, 0),
|
||||||
SplitPackages: make([]*PackageInfo, 0),
|
SplitPackages: make([]*PackageInfo, 0),
|
||||||
}
|
}
|
||||||
@@ -507,56 +536,57 @@ func ReadPackageInfo(contents string) (*PackageInfo, error) {
|
|||||||
return pkgInfo, nil
|
return pkgInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bpmpkg *BPMPackage) CreateReadableInfo(rootDir string, humanReadableSize bool) string {
|
func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
|
||||||
ret := make([]string, 0)
|
ret := make([]string, 0)
|
||||||
appendArray := func(label string, array []string) {
|
appendArray := func(label string, array []string) {
|
||||||
if len(array) == 0 {
|
if len(array) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort array
|
|
||||||
slices.Sort(array)
|
|
||||||
|
|
||||||
ret = append(ret, fmt.Sprintf("%s: %s", label, strings.Join(array, ", ")))
|
ret = append(ret, fmt.Sprintf("%s: %s", label, strings.Join(array, ", ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = append(ret, "Name: "+bpmpkg.PkgInfo.Name)
|
ret = append(ret, "Name: "+pkgInfo.Name)
|
||||||
ret = append(ret, "Description: "+bpmpkg.PkgInfo.Description)
|
ret = append(ret, "Description: "+pkgInfo.Description)
|
||||||
ret = append(ret, "Version: "+bpmpkg.PkgInfo.GetFullVersion())
|
ret = append(ret, "Version: "+pkgInfo.GetFullVersion())
|
||||||
if bpmpkg.PkgInfo.Url != "" {
|
if pkgInfo.Url != "" {
|
||||||
ret = append(ret, "URL: "+bpmpkg.PkgInfo.Url)
|
ret = append(ret, "URL: "+pkgInfo.Url)
|
||||||
}
|
}
|
||||||
if bpmpkg.PkgInfo.License != "" {
|
if pkgInfo.License != "" {
|
||||||
ret = append(ret, "License: "+bpmpkg.PkgInfo.License)
|
ret = append(ret, "License: "+pkgInfo.License)
|
||||||
}
|
}
|
||||||
ret = append(ret, "Architecture: "+bpmpkg.PkgInfo.Arch)
|
ret = append(ret, "Architecture: "+pkgInfo.Arch)
|
||||||
if bpmpkg.PkgInfo.Type == "source" && bpmpkg.PkgInfo.OutputArch != "" && bpmpkg.PkgInfo.OutputArch != GetArch() {
|
if pkgInfo.Type == "source" && pkgInfo.OutputArch != "" && pkgInfo.OutputArch != GetArch() {
|
||||||
ret = append(ret, "Output architecture: "+bpmpkg.PkgInfo.Arch)
|
ret = append(ret, "Output architecture: "+pkgInfo.Arch)
|
||||||
}
|
}
|
||||||
ret = append(ret, "Type: "+bpmpkg.PkgInfo.Type)
|
ret = append(ret, "Type: "+pkgInfo.Type)
|
||||||
appendArray("Dependencies", bpmpkg.PkgInfo.Depends)
|
appendArray("Dependencies", pkgInfo.Depends)
|
||||||
if bpmpkg.PkgInfo.Type == "source" {
|
if pkgInfo.Type == "source" {
|
||||||
appendArray("Make Dependencies", bpmpkg.PkgInfo.MakeDepends)
|
appendArray("Make Dependencies", pkgInfo.MakeDepends)
|
||||||
}
|
}
|
||||||
appendArray("Optional dependencies", bpmpkg.PkgInfo.OptionalDepends)
|
appendArray("Optional dependencies", pkgInfo.OptionalDepends)
|
||||||
dependants := bpmpkg.PkgInfo.GetPackageDependants(rootDir)
|
dependants := pkgInfo.GetPackageDependants(rootDir)
|
||||||
if len(dependants) > 0 {
|
if len(dependants) > 0 {
|
||||||
appendArray("Dependant packages", dependants)
|
appendArray("Dependant packages", dependants)
|
||||||
}
|
}
|
||||||
appendArray("Conflicting packages", bpmpkg.PkgInfo.Conflicts)
|
optionalDependants := pkgInfo.GetPackageOptionalDependants(rootDir)
|
||||||
appendArray("Provided packages", bpmpkg.PkgInfo.Provides)
|
if len(optionalDependants) > 0 {
|
||||||
appendArray("Replaces packages", bpmpkg.PkgInfo.Replaces)
|
appendArray("Optionally dependant packages", optionalDependants)
|
||||||
|
}
|
||||||
|
appendArray("Conflicting packages", pkgInfo.Conflicts)
|
||||||
|
appendArray("Provided packages", pkgInfo.Provides)
|
||||||
|
appendArray("Replaces packages", pkgInfo.Replaces)
|
||||||
|
|
||||||
if bpmpkg.PkgInfo.Type == "source" && len(bpmpkg.PkgInfo.SplitPackages) != 0 {
|
if pkgInfo.Type == "source" && len(pkgInfo.SplitPackages) != 0 {
|
||||||
splitPkgs := make([]string, len(bpmpkg.PkgInfo.SplitPackages))
|
splitPkgs := make([]string, len(pkgInfo.SplitPackages))
|
||||||
for i, splitPkgInfo := range bpmpkg.PkgInfo.SplitPackages {
|
for i, splitPkgInfo := range pkgInfo.SplitPackages {
|
||||||
splitPkgs[i] = splitPkgInfo.Name
|
splitPkgs[i] = splitPkgInfo.Name
|
||||||
}
|
}
|
||||||
appendArray("Split Packages", splitPkgs)
|
appendArray("Split Packages", splitPkgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rootDir != "" && IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
if rootDir != "" && IsPackageInstalled(pkgInfo.Name, rootDir) {
|
||||||
installationReason := GetInstallationReason(bpmpkg.PkgInfo.Name, rootDir)
|
installationReason := GetInstallationReason(pkgInfo.Name, rootDir)
|
||||||
var installationReasonString string
|
var installationReasonString string
|
||||||
switch installationReason {
|
switch installationReason {
|
||||||
case InstallationReasonManual:
|
case InstallationReasonManual:
|
||||||
@@ -570,37 +600,21 @@ func (bpmpkg *BPMPackage) CreateReadableInfo(rootDir string, humanReadableSize b
|
|||||||
}
|
}
|
||||||
ret = append(ret, "Installation Reason: "+installationReasonString)
|
ret = append(ret, "Installation Reason: "+installationReasonString)
|
||||||
}
|
}
|
||||||
if bpmpkg.PkgInfo.Type == "binary" {
|
|
||||||
installedSize := int64(bpmpkg.GetInstalledSize())
|
|
||||||
var installedSizeStr string
|
|
||||||
if humanReadableSize {
|
|
||||||
installedSizeStr = bytesToHumanReadable(installedSize)
|
|
||||||
} else {
|
|
||||||
installedSizeStr = strconv.FormatInt(installedSize, 10)
|
|
||||||
}
|
|
||||||
ret = append(ret, "Installed size: "+installedSizeStr)
|
|
||||||
}
|
|
||||||
return strings.Join(ret, "\n")
|
return strings.Join(ret, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize progress bar
|
||||||
|
bar := createProgressBar(bpmpkg.GetInstalledSize(), "Installing "+bpmpkg.PkgInfo.Name, verbose)
|
||||||
|
defer bar.Close()
|
||||||
|
|
||||||
tarballFile, err := readTarballFile(filename, "files.tar.gz")
|
tarballFile, err := readTarballFile(filename, "files.tar.gz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -612,6 +626,7 @@ func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
packageFilesReader := tar.NewReader(archive)
|
packageFilesReader := tar.NewReader(archive)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
header, err := packageFilesReader.Next()
|
header, err := packageFilesReader.Next()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
@@ -648,6 +663,7 @@ func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string)
|
|||||||
if verbose {
|
if verbose {
|
||||||
fmt.Printf("Created directory %s (%o)\n", extractFilename, header.Mode)
|
fmt.Printf("Created directory %s (%o)\n", extractFilename, header.Mode)
|
||||||
}
|
}
|
||||||
|
bar.Add64(header.Size)
|
||||||
case tar.TypeReg:
|
case tar.TypeReg:
|
||||||
skip := false
|
skip := false
|
||||||
if _, err := os.Stat(extractFilename); err == nil {
|
if _, err := os.Stat(extractFilename); err == nil {
|
||||||
@@ -704,6 +720,7 @@ func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string)
|
|||||||
if verbose {
|
if verbose {
|
||||||
fmt.Printf("Created File: %s (%o)\n", extractFilename, header.Mode)
|
fmt.Printf("Created File: %s (%o)\n", extractFilename, header.Mode)
|
||||||
}
|
}
|
||||||
|
bar.Add64(header.Size)
|
||||||
case tar.TypeSymlink:
|
case tar.TypeSymlink:
|
||||||
err := os.Remove(extractFilename)
|
err := os.Remove(extractFilename)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
@@ -718,6 +735,7 @@ func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string)
|
|||||||
if verbose {
|
if verbose {
|
||||||
fmt.Println("Created Symlink: " + extractFilename + " -> " + header.Linkname)
|
fmt.Println("Created Symlink: " + extractFilename + " -> " + header.Linkname)
|
||||||
}
|
}
|
||||||
|
bar.Add64(header.Size)
|
||||||
case tar.TypeLink:
|
case tar.TypeLink:
|
||||||
if verbose {
|
if verbose {
|
||||||
fmt.Println("Detected Hard Link: " + extractFilename + " -> " + path.Join(rootDir, strings.TrimPrefix(header.Linkname, "files/")))
|
fmt.Println("Detected Hard Link: " + extractFilename + " -> " + path.Join(rootDir, strings.TrimPrefix(header.Linkname, "files/")))
|
||||||
@@ -727,6 +745,7 @@ func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string)
|
|||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
bar.Add64(header.Size)
|
||||||
default:
|
default:
|
||||||
return errors.New("unknown type (" + strconv.Itoa(int(header.Typeflag)) + ") in " + extractFilename)
|
return errors.New("unknown type (" + strconv.Itoa(int(header.Typeflag)) + ") in " + extractFilename)
|
||||||
}
|
}
|
||||||
@@ -761,6 +780,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
|
||||||
@@ -942,6 +975,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 {
|
||||||
@@ -961,7 +995,7 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add or update package information for rootDir
|
// Add or update package information for rootDir
|
||||||
localPackageInformation[rootDir][bpmpkg.PkgInfo.Name] = bpmpkg
|
localPackageInformation[rootDir][bpmpkg.PkgInfo.Name] = bpmpkg.PkgInfo
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -979,8 +1013,11 @@ func removePackage(pkg string, verbose bool, rootDir string) error {
|
|||||||
log.Printf("Warning: %s\n", err)
|
log.Printf("Warning: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get BPM package
|
||||||
|
bpmpkg := GetPackage(pkg, rootDir)
|
||||||
|
|
||||||
// Fetching and reversing package file entry list
|
// Fetching and reversing package file entry list
|
||||||
fileEntries := GetPackage(pkg, rootDir).PkgFiles
|
fileEntries := bpmpkg.PkgFiles
|
||||||
sort.Slice(fileEntries, func(i, j int) bool {
|
sort.Slice(fileEntries, func(i, j int) bool {
|
||||||
return fileEntries[i].Path < fileEntries[j].Path
|
return fileEntries[i].Path < fileEntries[j].Path
|
||||||
})
|
})
|
||||||
@@ -990,8 +1027,12 @@ func removePackage(pkg string, verbose bool, rootDir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bar := createProgressBar(bpmpkg.GetInstalledSize(), "Removing "+bpmpkg.PkgInfo.Name, verbose)
|
||||||
|
defer bar.Close()
|
||||||
|
|
||||||
// Removing package files
|
// Removing package files
|
||||||
for _, entry := range fileEntries {
|
for _, entry := range fileEntries {
|
||||||
|
bar.Add64(entry.SizeInBytes)
|
||||||
file := path.Join(rootDir, entry.Path)
|
file := path.Join(rootDir, entry.Path)
|
||||||
lstat, err := os.Lstat(file)
|
lstat, err := os.Lstat(file)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
|||||||
+69
-22
@@ -2,10 +2,15 @@ package bpmlib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
version "github.com/knqyf263/go-rpm-version"
|
||||||
|
"github.com/schollz/progressbar/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BPMLock struct {
|
type BPMLock struct {
|
||||||
@@ -13,20 +18,6 @@ type BPMLock struct {
|
|||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lock *BPMLock) Unlock() error {
|
|
||||||
err := lock.file.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Remove(lock.path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func LockBPM(rootDir string) (*BPMLock, error) {
|
func LockBPM(rootDir string) (*BPMLock, error) {
|
||||||
// Create parent directories if they don't already exist
|
// Create parent directories if they don't already exist
|
||||||
err := os.MkdirAll(path.Join(rootDir, "/var/lib/bpm"), 0755)
|
err := os.MkdirAll(path.Join(rootDir, "/var/lib/bpm"), 0755)
|
||||||
@@ -49,6 +40,20 @@ func LockBPM(rootDir string) (*BPMLock, error) {
|
|||||||
return &BPMLock{f, path.Join(rootDir, "var/lib/bpm/bpm.lock")}, nil
|
return &BPMLock{f, path.Join(rootDir, "var/lib/bpm/bpm.lock")}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (lock *BPMLock) Unlock() error {
|
||||||
|
err := lock.file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Remove(lock.path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetArch() string {
|
func GetArch() string {
|
||||||
uname := syscall.Utsname{}
|
uname := syscall.Utsname{}
|
||||||
err := syscall.Uname(&uname)
|
err := syscall.Uname(&uname)
|
||||||
@@ -64,6 +69,47 @@ func GetArch() string {
|
|||||||
return string(byteString[:indexLength])
|
return string(byteString[:indexLength])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CompareVersions(version1, version2 string) int {
|
||||||
|
v1 := version.NewVersion(version1)
|
||||||
|
v2 := version.NewVersion(version2)
|
||||||
|
|
||||||
|
return v1.Compare(v2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createProgressBar(max int64, description string, hideBar bool) *progressbar.ProgressBar {
|
||||||
|
var output io.Writer
|
||||||
|
if hideBar {
|
||||||
|
output = io.Discard
|
||||||
|
} else {
|
||||||
|
output = os.Stderr
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(description) < 40 {
|
||||||
|
for i := len(description); i < 40; i++ {
|
||||||
|
description += " "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(description) > 40 {
|
||||||
|
overflow := len(description) - 37
|
||||||
|
description = description[:len(description)-overflow] + "..."
|
||||||
|
}
|
||||||
|
|
||||||
|
return progressbar.NewOptions64(max,
|
||||||
|
progressbar.OptionSetDescription(description),
|
||||||
|
progressbar.OptionSetWriter(output),
|
||||||
|
progressbar.OptionShowBytes(true),
|
||||||
|
progressbar.OptionShowTotalBytes(true),
|
||||||
|
progressbar.OptionSetWidth(20),
|
||||||
|
progressbar.OptionThrottle(65*time.Millisecond),
|
||||||
|
progressbar.OptionShowCount(),
|
||||||
|
progressbar.OptionOnCompletion(func() {
|
||||||
|
fmt.Fprint(output, "\n")
|
||||||
|
}),
|
||||||
|
progressbar.OptionSpinnerType(14),
|
||||||
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
|
progressbar.OptionSetTheme(progressbar.ThemeASCII))
|
||||||
|
}
|
||||||
|
|
||||||
func stringSliceRemove(s []string, r string) []string {
|
func stringSliceRemove(s []string, r string) []string {
|
||||||
for i, v := range s {
|
for i, v := range s {
|
||||||
if v == r {
|
if v == r {
|
||||||
@@ -73,7 +119,7 @@ func stringSliceRemove(s []string, r string) []string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func unsignedBytesToHumanReadable(b uint64) string {
|
func BytesToHumanReadable(b int64) string {
|
||||||
bf := float64(b)
|
bf := float64(b)
|
||||||
for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} {
|
for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} {
|
||||||
if math.Abs(bf) < 1024.0 {
|
if math.Abs(bf) < 1024.0 {
|
||||||
@@ -84,13 +130,14 @@ func unsignedBytesToHumanReadable(b uint64) string {
|
|||||||
return fmt.Sprintf("%.1fYiB", bf)
|
return fmt.Sprintf("%.1fYiB", bf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bytesToHumanReadable(b int64) string {
|
func removeDuplicates[T comparable](sliceList []T) []T {
|
||||||
bf := float64(b)
|
allKeys := make(map[T]bool)
|
||||||
for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} {
|
list := []T{}
|
||||||
if math.Abs(bf) < 1024.0 {
|
for _, item := range sliceList {
|
||||||
return fmt.Sprintf("%3.1f%sB", bf, unit)
|
if _, value := allKeys[item]; !value {
|
||||||
|
allKeys[item] = true
|
||||||
|
list = append(list, item)
|
||||||
}
|
}
|
||||||
bf /= 1024.0
|
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%.1fYiB", bf)
|
return list
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user