mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
368b098888 | ||
|
|
5e2fc138e9 | ||
|
|
bc489ebd23 | ||
|
|
6247c6eff7 | ||
|
|
c24b7c85e3 | ||
|
|
2fd01a3fc2 | ||
|
|
747c770499 | ||
|
|
26500d670d | ||
|
|
59df2324e6 | ||
|
|
12d5e7580e | ||
|
|
123697e1dc | ||
|
|
743918702a | ||
|
|
7d2caa542c | ||
|
|
ab75193022 | ||
|
|
7d577a8dc2 | ||
|
|
c85c9b5d1c |
@@ -1,34 +0,0 @@
|
|||||||
package bpm_utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BPMConfigStruct struct {
|
|
||||||
CompilationEnv []string `yaml:"compilation_env"`
|
|
||||||
SilentCompilation bool `yaml:"silent_compilation"`
|
|
||||||
BinaryOutputDir string `yaml:"binary_output_dir"`
|
|
||||||
CompilationDir string `yaml:"compilation_dir"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var BPMConfig BPMConfigStruct = BPMConfigStruct{
|
|
||||||
CompilationEnv: make([]string, 0),
|
|
||||||
SilentCompilation: false,
|
|
||||||
BinaryOutputDir: "/var/lib/bpm/compiled/",
|
|
||||||
CompilationDir: "/var/tmp/",
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadConfig() {
|
|
||||||
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
bytes, err := os.ReadFile("/etc/bpm.conf")
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = yaml.Unmarshal(bytes, &BPMConfig)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,3 +2,7 @@ compilation_env: []
|
|||||||
silent_compilation: false
|
silent_compilation: false
|
||||||
compilation_dir: "/var/tmp/"
|
compilation_dir: "/var/tmp/"
|
||||||
binary_output_dir: "/var/lib/bpm/compiled/"
|
binary_output_dir: "/var/lib/bpm/compiled/"
|
||||||
|
repositories:
|
||||||
|
- name: example-repository
|
||||||
|
source: https://my-repo.xyz/
|
||||||
|
disabled: true
|
||||||
@@ -2,4 +2,7 @@ module gitlab.com/bubble-package-manager/bpm
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
require gopkg.in/yaml.v3 v3.0.1 // indirect
|
require (
|
||||||
|
github.com/elliotchance/orderedmap/v2 v2.4.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
github.com/elliotchance/orderedmap/v2 v2.4.0 h1:6tUmMwD9F998FNpwFxA5E6NQvSpk2PVw7RKsVq3+2Cw=
|
||||||
|
github.com/elliotchance/orderedmap/v2 v2.4.0/go.mod h1:85lZyVbpGaGvHvnKa7Qhx7zncAdBIBq6u56Hb1PRU5Q=
|
||||||
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=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitlab.com/bubble-package-manager/bpm/bpm_utils"
|
"github.com/elliotchance/orderedmap/v2"
|
||||||
|
"gitlab.com/bubble-package-manager/bpm/utils"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -17,23 +18,28 @@ import (
|
|||||||
/* A simple-to-use package manager */
|
/* A simple-to-use package manager */
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
var bpmVer = "0.3.2"
|
var bpmVer = "0.4"
|
||||||
|
|
||||||
var subcommand = "help"
|
var subcommand = "help"
|
||||||
var subcommandArgs []string
|
var subcommandArgs []string
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
var rootDir = "/"
|
var rootDir = "/"
|
||||||
|
var verbose = false
|
||||||
var yesAll = false
|
var yesAll = false
|
||||||
var buildSource = false
|
var buildSource = false
|
||||||
var skipCheck = false
|
var skipCheck = false
|
||||||
var keepTempDir = false
|
var keepTempDir = false
|
||||||
var forceInstall = false
|
var force = false
|
||||||
var pkgListNumbers = false
|
var pkgListNumbers = false
|
||||||
var pkgListNames = false
|
var pkgListNames = false
|
||||||
|
var reinstall = false
|
||||||
|
var reinstallAll = false
|
||||||
|
var noOptional = false
|
||||||
|
var nosync = true
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bpm_utils.ReadConfig()
|
utils.ReadConfig()
|
||||||
resolveFlags()
|
resolveFlags()
|
||||||
resolveCommand()
|
resolveCommand()
|
||||||
}
|
}
|
||||||
@@ -45,7 +51,10 @@ const (
|
|||||||
version
|
version
|
||||||
info
|
info
|
||||||
list
|
list
|
||||||
|
search
|
||||||
install
|
install
|
||||||
|
update
|
||||||
|
sync
|
||||||
remove
|
remove
|
||||||
file
|
file
|
||||||
)
|
)
|
||||||
@@ -58,8 +67,14 @@ func getCommandType() commandType {
|
|||||||
return info
|
return info
|
||||||
case "list":
|
case "list":
|
||||||
return list
|
return list
|
||||||
|
case "search":
|
||||||
|
return search
|
||||||
case "install":
|
case "install":
|
||||||
return install
|
return install
|
||||||
|
case "update":
|
||||||
|
return update
|
||||||
|
case "sync":
|
||||||
|
return sync
|
||||||
case "remove":
|
case "remove":
|
||||||
return remove
|
return remove
|
||||||
case "file":
|
case "file":
|
||||||
@@ -81,18 +96,19 @@ func resolveCommand() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for n, pkg := range packages {
|
for n, pkg := range packages {
|
||||||
info := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
var info *utils.PackageInfo
|
||||||
|
info = utils.GetPackageInfo(pkg, rootDir, false)
|
||||||
if info == nil {
|
if info == nil {
|
||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
log.Fatalf("Package (%s) is not installed\n", pkg)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info, true))
|
fmt.Println("----------------")
|
||||||
|
fmt.Println(utils.CreateReadableInfo(true, true, true, info, rootDir))
|
||||||
if n == len(packages)-1 {
|
if n == len(packages)-1 {
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case list:
|
case list:
|
||||||
packages, err := bpm_utils.GetInstalledPackages(rootDir)
|
packages, err := utils.GetInstalledPackages(rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not get installed packages\nError: %s", err.Error())
|
log.Fatalf("Could not get installed packages\nError: %s", err.Error())
|
||||||
return
|
return
|
||||||
@@ -109,58 +125,186 @@ func resolveCommand() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for n, pkg := range packages {
|
for n, pkg := range packages {
|
||||||
info := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
info := utils.GetPackageInfo(pkg, rootDir, false)
|
||||||
if info == nil {
|
if info == nil {
|
||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info, true))
|
fmt.Println("----------------\n" + utils.CreateReadableInfo(true, true, true, info, rootDir))
|
||||||
if n == len(packages)-1 {
|
if n == len(packages)-1 {
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case search:
|
||||||
|
searchTerms := subcommandArgs
|
||||||
|
if len(searchTerms) == 0 {
|
||||||
|
fmt.Println("No search terms given")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, term := range searchTerms {
|
||||||
|
nameResults := make([]*utils.PackageInfo, 0)
|
||||||
|
descResults := make([]*utils.PackageInfo, 0)
|
||||||
|
for _, repo := range utils.BPMConfig.Repositories {
|
||||||
|
for _, entry := range repo.Entries {
|
||||||
|
if strings.Contains(entry.Info.Name, term) {
|
||||||
|
nameResults = append(nameResults, entry.Info)
|
||||||
|
} else if strings.Contains(entry.Info.Description, term) {
|
||||||
|
descResults = append(descResults, entry.Info)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results := append(nameResults, descResults...)
|
||||||
|
if len(results) == 0 {
|
||||||
|
log.Fatalf("No results for term (%s) were found\n", term)
|
||||||
|
}
|
||||||
|
fmt.Printf("Results for term (%s)\n", term)
|
||||||
|
for i, result := range results {
|
||||||
|
fmt.Println("----------------")
|
||||||
|
fmt.Printf("%d) %s: %s (%s)\n", i+1, result.Name, result.Description, result.Version)
|
||||||
|
}
|
||||||
|
}
|
||||||
case install:
|
case install:
|
||||||
if os.Getuid() != 0 {
|
if os.Getuid() != 0 {
|
||||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
files := subcommandArgs
|
pkgs := subcommandArgs
|
||||||
if len(files) == 0 {
|
if len(pkgs) == 0 {
|
||||||
fmt.Println("No files were given to install")
|
fmt.Println("No packages or files were given to install")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
|
||||||
pkgInfo, err := bpm_utils.ReadPackage(file)
|
pkgsToInstall := orderedmap.NewOrderedMap[string, *struct {
|
||||||
|
isDependency bool
|
||||||
|
pkgInfo *utils.PackageInfo
|
||||||
|
}]()
|
||||||
|
pkgsToFetch := orderedmap.NewOrderedMap[string, *struct {
|
||||||
|
isDependency bool
|
||||||
|
pkgInfo *utils.PackageInfo
|
||||||
|
}]()
|
||||||
|
unresolvedDepends := make([]string, 0)
|
||||||
|
|
||||||
|
// Search for packages
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
|
||||||
|
pkgInfo, err := utils.ReadPackage(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not read package\nError: %s\n", err)
|
log.Fatalf("Could not read package. Error: %s\n", err)
|
||||||
}
|
}
|
||||||
if !yesAll {
|
if !reinstall && utils.IsPackageInstalled(pkgInfo.Name, rootDir) && utils.GetPackageInfo(pkgInfo.Name, rootDir, true).Version == pkgInfo.Version {
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo, true))
|
|
||||||
fmt.Println("----------------")
|
|
||||||
}
|
|
||||||
verb := "install"
|
|
||||||
if pkgInfo.Type == "source" {
|
|
||||||
if _, err := os.Stat("/bin/fakeroot"); os.IsNotExist(err) {
|
|
||||||
fmt.Printf("Skipping... cannot %s package (%s) due to fakeroot not being installed")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
verb = "build"
|
pkgsToInstall.Set(pkg, &struct {
|
||||||
|
isDependency bool
|
||||||
|
pkgInfo *utils.PackageInfo
|
||||||
|
}{isDependency: false, pkgInfo: pkgInfo})
|
||||||
|
} else {
|
||||||
|
entry, _, err := utils.GetRepositoryEntry(pkg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
||||||
}
|
}
|
||||||
if !forceInstall {
|
if !reinstall && utils.IsPackageInstalled(entry.Info.Name, rootDir) && utils.GetPackageInfo(entry.Info.Name, rootDir, true).Version == entry.Info.Version {
|
||||||
if pkgInfo.Arch != "any" && pkgInfo.Arch != bpm_utils.GetArch() {
|
|
||||||
fmt.Printf("skipping... cannot %s a package with a different architecture\n", verb)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if unresolved := bpm_utils.CheckDependencies(pkgInfo, rootDir); len(unresolved) != 0 {
|
pkgsToFetch.Set(entry.Info.Name, &struct {
|
||||||
fmt.Printf("skipping... cannot %s package (%s) due to missing dependencies: %s\n", verb, pkgInfo.Name, strings.Join(unresolved, ", "))
|
isDependency bool
|
||||||
|
pkgInfo *utils.PackageInfo
|
||||||
|
}{isDependency: false, pkgInfo: entry.Info})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for dependencies and conflicts
|
||||||
|
clone := pkgsToFetch.Copy()
|
||||||
|
pkgsToFetch = orderedmap.NewOrderedMap[string, *struct {
|
||||||
|
isDependency bool
|
||||||
|
pkgInfo *utils.PackageInfo
|
||||||
|
}]()
|
||||||
|
for _, pkg := range clone.Keys() {
|
||||||
|
value := clone.GetElement(pkg).Value
|
||||||
|
resolved, unresolved := value.pkgInfo.ResolveAll(&[]string{}, &[]string{}, false, !noOptional, !reinstall, rootDir)
|
||||||
|
unresolvedDepends = append(unresolvedDepends, unresolved...)
|
||||||
|
for _, depend := range resolved {
|
||||||
|
if _, ok := pkgsToFetch.Get(depend); !ok && depend != value.pkgInfo.Name {
|
||||||
|
if !reinstallAll && utils.IsPackageInstalled(depend, rootDir) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if pkgInfo.Type == "source" {
|
entry, _, err := utils.GetRepositoryEntry(depend)
|
||||||
if unresolved := bpm_utils.CheckMakeDependencies(pkgInfo, "/"); len(unresolved) != 0 {
|
if err != nil {
|
||||||
fmt.Printf("skipping... cannot %s package (%s) due to missing make dependencies: %s\n", verb, pkgInfo.Name, strings.Join(unresolved, ", "))
|
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
||||||
|
}
|
||||||
|
pkgsToFetch.Set(depend, &struct {
|
||||||
|
isDependency bool
|
||||||
|
pkgInfo *utils.PackageInfo
|
||||||
|
}{isDependency: true, pkgInfo: entry.Info})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pkgsToFetch.Set(pkg, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pkg := range pkgsToInstall.Keys() {
|
||||||
|
value, _ := pkgsToInstall.Get(pkg)
|
||||||
|
resolved, unresolved := value.pkgInfo.ResolveAll(&[]string{}, &[]string{}, false, !noOptional, !reinstall, rootDir)
|
||||||
|
unresolvedDepends = append(unresolvedDepends, unresolved...)
|
||||||
|
for _, depend := range resolved {
|
||||||
|
if _, ok := clone.Get(depend); !ok && depend != value.pkgInfo.Name {
|
||||||
|
if !reinstallAll && utils.IsPackageInstalled(depend, rootDir) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
entry, _, err := utils.GetRepositoryEntry(depend)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
||||||
|
}
|
||||||
|
pkgsToFetch.Set(depend, &struct {
|
||||||
|
isDependency bool
|
||||||
|
pkgInfo *utils.PackageInfo
|
||||||
|
}{isDependency: true, pkgInfo: entry.Info})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show summary
|
||||||
|
if len(unresolvedDepends) != 0 {
|
||||||
|
if force {
|
||||||
|
log.Fatalf("The following dependencies could not be found in any repositories: %s\n", strings.Join(unresolvedDepends, ", "))
|
||||||
|
} else {
|
||||||
|
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(unresolvedDepends, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pkgsToInstall.Len()+pkgsToFetch.Len() == 0 {
|
||||||
|
fmt.Println("All packages are up to date!")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
for _, pkg := range pkgsToInstall.Keys() {
|
||||||
|
pkgInfo, err := utils.ReadPackage(pkg)
|
||||||
|
if err != nil {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not read package. Error: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
installedInfo := utils.GetPackageInfo(pkgInfo.Name, rootDir, false)
|
||||||
|
if installedInfo == nil {
|
||||||
|
fmt.Printf("%s: %s (Install)\n", pkgInfo.Name, pkgInfo.Version)
|
||||||
|
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) < 0 {
|
||||||
|
fmt.Printf("%s: %s -> %s (Downgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version)
|
||||||
|
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 {
|
||||||
|
fmt.Printf("%s: %s -> %s (Upgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s: %s (Reinstall)\n", pkgInfo.Name, pkgInfo.Version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, pkg := range pkgsToFetch.Keys() {
|
||||||
|
pkgInfo := pkgsToFetch.GetElement(pkg).Value.pkgInfo
|
||||||
|
installedInfo := utils.GetPackageInfo(pkgInfo.Name, rootDir, false)
|
||||||
|
if installedInfo == nil {
|
||||||
|
fmt.Printf("%s: %s (Install)\n", pkgInfo.Name, pkgInfo.Version)
|
||||||
|
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) < 0 {
|
||||||
|
fmt.Printf("%s: %s -> %s (Downgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version)
|
||||||
|
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 {
|
||||||
|
fmt.Printf("%s: %s -> %s (Upgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s: %s (Reinstall)\n", pkgInfo.Name, pkgInfo.Version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rootDir != "/" {
|
if rootDir != "/" {
|
||||||
@@ -168,61 +312,235 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
if pkgInfo.Type == "source" {
|
fmt.Printf("Do you wish to install these %d packages? [y\\N] ", pkgsToInstall.Len()+pkgsToFetch.Len())
|
||||||
fmt.Print("Would you like to view the source.sh file of this package? [Y\\n] ")
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "n" && strings.TrimSpace(strings.ToLower(text)) != "no" {
|
|
||||||
script, err := bpm_utils.GetSourceScript(file)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not read source script\nError: %s\n", err)
|
|
||||||
}
|
|
||||||
fmt.Println(script)
|
|
||||||
fmt.Println("-------EOF-------")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if bpm_utils.IsPackageInstalled(pkgInfo.Name, rootDir) {
|
|
||||||
if !yesAll {
|
|
||||||
installedInfo := bpm_utils.GetPackageInfo(pkgInfo.Name, rootDir, false)
|
|
||||||
if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 {
|
|
||||||
fmt.Println("This file contains a newer version of this package (" + installedInfo.Version + " -> " + pkgInfo.Version + ")")
|
|
||||||
fmt.Print("Do you wish to update this package? [y\\N] ")
|
|
||||||
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) < 0 {
|
|
||||||
fmt.Println("This file contains an older version of this package (" + installedInfo.Version + " -> " + pkgInfo.Version + ")")
|
|
||||||
fmt.Print("Do you wish to downgrade this package? (Not recommended) [y\\N] ")
|
|
||||||
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) == 0 {
|
|
||||||
fmt.Println("This package is already installed on the system and is up to date")
|
|
||||||
fmt.Printf("Do you wish to re%s this package? [y\\N] ", verb)
|
|
||||||
}
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
text, _ := reader.ReadString('\n')
|
text, _ := reader.ReadString('\n')
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||||
fmt.Printf("Skipping package (%s)...\n", pkgInfo.Name)
|
fmt.Println("Cancelling...")
|
||||||
continue
|
os.Exit(1)
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if !yesAll {
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
fmt.Printf("Do you wish to %s this package? [y\\N] ", verb)
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Printf("Skipping package (%s)...\n", pkgInfo.Name)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bpm_utils.InstallPackage(file, rootDir, forceInstall, buildSource, skipCheck, keepTempDir)
|
// Fetch packages from repositories
|
||||||
|
fmt.Println("Fetching packages from available repositories...")
|
||||||
|
for _, pkg := range pkgsToFetch.Keys() {
|
||||||
|
isDependency, _ := pkgsToFetch.Get(pkg)
|
||||||
|
entry, repo, err := utils.GetRepositoryEntry(pkg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
||||||
|
}
|
||||||
|
fetchedPackage, err := repo.FetchPackage(entry.Info.Name)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not fetch package (%s). Error: %s\n", pkg, err)
|
||||||
|
}
|
||||||
|
pkgsToInstall.Set(fetchedPackage, isDependency)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install fetched packages
|
||||||
|
for _, pkg := range pkgsToInstall.Keys() {
|
||||||
|
value, _ := pkgsToInstall.Get(pkg)
|
||||||
|
pkgInfo := value.pkgInfo
|
||||||
|
var err error
|
||||||
|
if value.isDependency {
|
||||||
|
err = utils.InstallPackage(pkg, rootDir, verbose, true, buildSource, skipCheck, keepTempDir)
|
||||||
|
} else {
|
||||||
|
err = utils.InstallPackage(pkg, rootDir, verbose, force, buildSource, skipCheck, keepTempDir)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pkgInfo.Type == "source" && keepTempDir {
|
if pkgInfo.Type == "source" && keepTempDir {
|
||||||
fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name)
|
fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name)
|
||||||
}
|
}
|
||||||
log.Fatalf("Could not install package\nError: %s\n", err)
|
log.Fatalf("Could not install package (%s). Error: %s\n", pkg, err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name)
|
fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name)
|
||||||
|
if value.isDependency {
|
||||||
|
err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not set installation reason for package\nError: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if pkgInfo.Type == "source" && keepTempDir {
|
if pkgInfo.Type == "source" && keepTempDir {
|
||||||
fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **")
|
fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case update:
|
||||||
|
if os.Getuid() != 0 {
|
||||||
|
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync repositories
|
||||||
|
if !nosync {
|
||||||
|
for _, repo := range utils.BPMConfig.Repositories {
|
||||||
|
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
||||||
|
err := repo.SyncLocalDatabase()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("All package databases synced successfully!")
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.ReadConfig()
|
||||||
|
|
||||||
|
// Get installed packages and check for updates
|
||||||
|
pkgs, err := utils.GetInstalledPackages(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not get installed packages! Error: %s\n", err)
|
||||||
|
}
|
||||||
|
toUpdate := orderedmap.NewOrderedMap[string, *struct {
|
||||||
|
isDependency bool
|
||||||
|
entry *utils.RepositoryEntry
|
||||||
|
}]()
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
entry, _, err := utils.GetRepositoryEntry(pkg)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
installedInfo := utils.GetPackageInfo(pkg, rootDir, true)
|
||||||
|
if installedInfo == nil {
|
||||||
|
log.Fatalf(pkg)
|
||||||
|
}
|
||||||
|
if strings.Compare(entry.Info.Version, installedInfo.Version) > 0 {
|
||||||
|
toUpdate.Set(entry.Info.Name, &struct {
|
||||||
|
isDependency bool
|
||||||
|
entry *utils.RepositoryEntry
|
||||||
|
}{isDependency: false, entry: entry})
|
||||||
|
} else if reinstall {
|
||||||
|
toUpdate.Set(entry.Info.Name, &struct {
|
||||||
|
isDependency bool
|
||||||
|
entry *utils.RepositoryEntry
|
||||||
|
}{isDependency: false, entry: entry})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if toUpdate.Len() == 0 {
|
||||||
|
fmt.Println("All packages are up to date!")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for new dependencies in updated packages
|
||||||
|
unresolved := make([]string, 0)
|
||||||
|
clone := toUpdate.Copy()
|
||||||
|
for _, key := range clone.Keys() {
|
||||||
|
pkg, _ := clone.Get(key)
|
||||||
|
r, u := pkg.entry.Info.ResolveAll(&[]string{}, &[]string{}, false, !noOptional, true, rootDir)
|
||||||
|
unresolved = append(unresolved, u...)
|
||||||
|
for _, depend := range r {
|
||||||
|
if _, ok := toUpdate.Get(depend); !ok {
|
||||||
|
entry, _, err := utils.GetRepositoryEntry(depend)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not find package (%s) in any repository\n", depend)
|
||||||
|
}
|
||||||
|
toUpdate.Set(depend, &struct {
|
||||||
|
isDependency bool
|
||||||
|
entry *utils.RepositoryEntry
|
||||||
|
}{isDependency: true, entry: entry})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(unresolved) != 0 {
|
||||||
|
if force {
|
||||||
|
log.Fatalf("The following dependencies could not be found in any repositories: %s\n", strings.Join(unresolved, ", "))
|
||||||
|
} else {
|
||||||
|
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(unresolved, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, key := range toUpdate.Keys() {
|
||||||
|
value, _ := toUpdate.Get(key)
|
||||||
|
installedInfo := utils.GetPackageInfo(value.entry.Info.Name, rootDir, true)
|
||||||
|
if installedInfo == nil {
|
||||||
|
fmt.Printf("%s: %s (Install)\n", value.entry.Info.Name, value.entry.Info.Version)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.Compare(value.entry.Info.Version, installedInfo.Version) > 0 {
|
||||||
|
fmt.Printf("%s: %s -> %s (Upgrade)\n", value.entry.Info.Name, installedInfo.Version, value.entry.Info.Version)
|
||||||
|
} else if reinstall {
|
||||||
|
fmt.Printf("%s: %s -> %s (Reinstall)\n", value.entry.Info.Name, installedInfo.Version, value.entry.Info.Version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update confirmation prompt
|
||||||
|
if !yesAll {
|
||||||
|
fmt.Printf("Are you sure you wish to update all %d packages? [y\\N] ", toUpdate.Len())
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
text, _ := reader.ReadString('\n')
|
||||||
|
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||||
|
fmt.Println("Cancelling update...")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch packages
|
||||||
|
pkgsToInstall := orderedmap.NewOrderedMap[string, *struct {
|
||||||
|
isDependency bool
|
||||||
|
entry *utils.RepositoryEntry
|
||||||
|
}]()
|
||||||
|
fmt.Println("Fetching packages from available repositories...")
|
||||||
|
for _, pkg := range toUpdate.Keys() {
|
||||||
|
isDependency, _ := toUpdate.Get(pkg)
|
||||||
|
entry, repo, err := utils.GetRepositoryEntry(pkg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
||||||
|
}
|
||||||
|
fetchedPackage, err := repo.FetchPackage(entry.Info.Name)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not fetch package (%s). Error: %s\n", pkg, err)
|
||||||
|
}
|
||||||
|
pkgsToInstall.Set(fetchedPackage, isDependency)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install fetched packages
|
||||||
|
for _, pkg := range pkgsToInstall.Keys() {
|
||||||
|
value, _ := pkgsToInstall.Get(pkg)
|
||||||
|
pkgInfo := value.entry.Info
|
||||||
|
var err error
|
||||||
|
if value.isDependency {
|
||||||
|
err = utils.InstallPackage(pkg, rootDir, verbose, true, buildSource, skipCheck, keepTempDir)
|
||||||
|
} else {
|
||||||
|
err = utils.InstallPackage(pkg, rootDir, verbose, force, buildSource, skipCheck, keepTempDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if pkgInfo.Type == "source" && keepTempDir {
|
||||||
|
fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name)
|
||||||
|
}
|
||||||
|
log.Fatalf("Could not install package (%s). Error: %s\n", pkg, err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name)
|
||||||
|
if value.isDependency {
|
||||||
|
err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not set installation reason for package\nError: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pkgInfo.Type == "source" && keepTempDir {
|
||||||
|
fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case sync:
|
||||||
|
if os.Getuid() != 0 {
|
||||||
|
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
if !yesAll {
|
||||||
|
fmt.Printf("Are you sure you wish to sync all databases? [y\\N] ")
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
text, _ := reader.ReadString('\n')
|
||||||
|
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||||
|
fmt.Println("Cancelling sync...")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, repo := range utils.BPMConfig.Repositories {
|
||||||
|
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
||||||
|
err := repo.SyncLocalDatabase()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("All package databases synced successfully!")
|
||||||
case remove:
|
case remove:
|
||||||
if os.Getuid() != 0 {
|
if os.Getuid() != 0 {
|
||||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||||
@@ -234,12 +552,12 @@ func resolveCommand() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
pkgInfo := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
pkgInfo := utils.GetPackageInfo(pkg, rootDir, false)
|
||||||
if pkgInfo == nil {
|
if pkgInfo == nil {
|
||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo, true))
|
fmt.Println("----------------\n" + utils.CreateReadableInfo(false, false, false, pkgInfo, rootDir))
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
if rootDir != "/" {
|
if rootDir != "/" {
|
||||||
fmt.Println("Warning: Operating in " + rootDir)
|
fmt.Println("Warning: Operating in " + rootDir)
|
||||||
@@ -253,7 +571,7 @@ func resolveCommand() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := bpm_utils.RemovePackage(pkg, rootDir)
|
err := utils.RemovePackage(pkg, verbose, rootDir)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not remove package\nError: %s\n", err)
|
log.Fatalf("Could not remove package\nError: %s\n", err)
|
||||||
@@ -275,7 +593,7 @@ func resolveCommand() {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log.Fatalf(absFile + " does not exist!")
|
log.Fatalf(absFile + " does not exist!")
|
||||||
}
|
}
|
||||||
pkgs, err := bpm_utils.GetInstalledPackages(rootDir)
|
pkgs, err := utils.GetInstalledPackages(rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not get installed packages. Error %s", err.Error())
|
log.Fatalf("Could not get installed packages. Error %s", err.Error())
|
||||||
}
|
}
|
||||||
@@ -294,7 +612,7 @@ func resolveCommand() {
|
|||||||
|
|
||||||
var pkgList []string
|
var pkgList []string
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
if slices.Contains(bpm_utils.GetPackageFiles(pkg, rootDir), absFile) {
|
if slices.Contains(utils.GetPackageFiles(pkg, rootDir), absFile) {
|
||||||
pkgList = append(pkgList, pkg)
|
pkgList = append(pkgList, pkg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,21 +636,38 @@ func printHelp() {
|
|||||||
fmt.Println("-> flags will be read if passed right after the subcommand otherwise they will be read as subcommand arguments")
|
fmt.Println("-> flags will be read if passed right after the subcommand otherwise they will be read as subcommand arguments")
|
||||||
fmt.Println("\033[1m---- Command List ----\033[0m")
|
fmt.Println("\033[1m---- Command List ----\033[0m")
|
||||||
fmt.Println("-> bpm version | shows information on the installed version of bpm")
|
fmt.Println("-> bpm version | shows information on the installed version of bpm")
|
||||||
fmt.Println("-> bpm info [-R] | shows information on an installed package")
|
fmt.Println("-> bpm info [-R] <packages...> | shows information on an installed package")
|
||||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||||
fmt.Println("-> bpm list [-R, -c, -n] | lists all installed packages")
|
fmt.Println("-> bpm list [-R, -c, -n] | lists all installed packages")
|
||||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||||
fmt.Println(" -c lists the amount of installed packages")
|
fmt.Println(" -c lists the amount of installed packages")
|
||||||
fmt.Println(" -n lists only the names of installed packages")
|
fmt.Println(" -n lists only the names of installed packages")
|
||||||
fmt.Println("-> bpm install [-R, -y, -f, -o, -c, -b, -k] <files...> | installs the following files")
|
fmt.Println("-> bpm search <search terms...> | Searches for packages through declared repositories")
|
||||||
|
fmt.Println("-> bpm install [-R, -v, -y, -f, -o, -c, -b, -k, --reinstall, --reinstall-all, --no-optional] <packages...> | installs the following files")
|
||||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||||
|
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||||
fmt.Println(" -y skips the confirmation prompt")
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
fmt.Println(" -f skips dependency and architecture checking")
|
fmt.Println(" -f skips dependency, conflict and architecture checking")
|
||||||
fmt.Println(" -o=<path> set the binary package output directory (defaults to /var/lib/bpm/compiled)")
|
fmt.Println(" -o=<path> set the binary package output directory (defaults to /var/lib/bpm/compiled)")
|
||||||
fmt.Println(" -c=<path> set the compilation directory (defaults to /var/tmp)")
|
fmt.Println(" -c=<path> set the compilation directory (defaults to /var/tmp)")
|
||||||
fmt.Println(" -b creates a binary package from a source package after compilation and saves it in the binary package output directory")
|
fmt.Println(" -b creates a binary package from a source package after compilation and saves it in the binary package output directory")
|
||||||
fmt.Println(" -k keeps the compilation directory created by BPM after source package installation")
|
fmt.Println(" -k keeps the compilation directory created by BPM after source package installation")
|
||||||
fmt.Println("-> bpm remove [-R, -y] <packages...> | removes the following packages")
|
fmt.Println(" --reinstall Reinstalls packages even if they do not have a newer version available")
|
||||||
|
fmt.Println(" --reinstall-all Same as --reinstall but also reinstalls dependencies")
|
||||||
|
fmt.Println(" --no-optional Prevents installation of optional dependencies")
|
||||||
|
fmt.Println("-> bpm update [-R, -v, -y, -f, --reinstall, --no-sync] | updates all packages that are available in the repositories")
|
||||||
|
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||||
|
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||||
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
|
fmt.Println(" -f skips dependency, conflict and architecture checking")
|
||||||
|
fmt.Println(" --reinstall Fetches and reinstalls all packages even if they do not have a newer version available")
|
||||||
|
fmt.Println(" --no-sync Skips package database syncing")
|
||||||
|
fmt.Println("-> bpm sync [-R, -v, -y] | Syncs package databases without updating packages")
|
||||||
|
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||||
|
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||||
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
|
fmt.Println("-> bpm remove [-R, -v, -y] <packages...> | removes the following packages")
|
||||||
|
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||||
fmt.Println(" -y skips the confirmation prompt")
|
fmt.Println(" -y skips the confirmation prompt")
|
||||||
fmt.Println("-> bpm file [-R] <files...> | shows what packages the following packages are managed by")
|
fmt.Println("-> bpm file [-R] <files...> | shows what packages the following packages are managed by")
|
||||||
@@ -354,17 +689,37 @@ func resolveFlags() {
|
|||||||
// Install flags
|
// Install flags
|
||||||
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
|
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
|
||||||
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
|
installFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||||
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
installFlagSet.StringVar(&bpm_utils.BPMConfig.BinaryOutputDir, "o", bpm_utils.BPMConfig.BinaryOutputDir, "Set the binary output directory")
|
installFlagSet.StringVar(&utils.BPMConfig.BinaryOutputDir, "o", utils.BPMConfig.BinaryOutputDir, "Set the binary output directory")
|
||||||
installFlagSet.StringVar(&bpm_utils.BPMConfig.CompilationDir, "c", bpm_utils.BPMConfig.CompilationDir, "Set the compilation directory")
|
installFlagSet.StringVar(&utils.BPMConfig.CompilationDir, "c", utils.BPMConfig.CompilationDir, "Set the compilation directory")
|
||||||
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
|
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
|
||||||
installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation")
|
installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation")
|
||||||
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
|
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
|
||||||
installFlagSet.BoolVar(&forceInstall, "f", false, "Force installation by skipping architecture and dependency resolution")
|
installFlagSet.BoolVar(&force, "f", false, "Force installation by skipping architecture and dependency resolution")
|
||||||
|
installFlagSet.BoolVar(&reinstall, "reinstall", false, "Reinstalls packages even if they do not have a newer version available")
|
||||||
|
installFlagSet.BoolVar(&reinstallAll, "reinstall-all", false, "Same as --reinstall but also reinstalls dependencies")
|
||||||
|
installFlagSet.BoolVar(&noOptional, "no-optional", false, "Prevents installation of optional dependencies")
|
||||||
installFlagSet.Usage = printHelp
|
installFlagSet.Usage = printHelp
|
||||||
|
// Update flags
|
||||||
|
updateFlagSet := flag.NewFlagSet("Update flags", flag.ExitOnError)
|
||||||
|
updateFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
|
updateFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||||
|
updateFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
|
updateFlagSet.BoolVar(&force, "f", false, "Force update by skipping architecture and dependency resolution")
|
||||||
|
updateFlagSet.BoolVar(&reinstall, "reinstall", false, "Fetches and reinstalls all packages even if they do not have a newer version available")
|
||||||
|
updateFlagSet.BoolVar(&nosync, "no-sync", false, "Skips package database syncing")
|
||||||
|
updateFlagSet.Usage = printHelp
|
||||||
|
// Sync flags
|
||||||
|
syncFlagSet := flag.NewFlagSet("Sync flags", flag.ExitOnError)
|
||||||
|
syncFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
|
syncFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||||
|
syncFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
|
syncFlagSet.Usage = printHelp
|
||||||
// Remove flags
|
// Remove flags
|
||||||
removeFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
removeFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
||||||
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||||
|
removeFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||||
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||||
removeFlagSet.Usage = printHelp
|
removeFlagSet.Usage = printHelp
|
||||||
// File flags
|
// File flags
|
||||||
@@ -394,6 +749,18 @@ func resolveFlags() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
subcommandArgs = installFlagSet.Args()
|
subcommandArgs = installFlagSet.Args()
|
||||||
|
} else if getCommandType() == update {
|
||||||
|
err := updateFlagSet.Parse(subcommandArgs)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
subcommandArgs = updateFlagSet.Args()
|
||||||
|
} else if getCommandType() == sync {
|
||||||
|
err := syncFlagSet.Parse(subcommandArgs)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
subcommandArgs = syncFlagSet.Args()
|
||||||
} else if getCommandType() == remove {
|
} else if getCommandType() == remove {
|
||||||
err := removeFlagSet.Parse(subcommandArgs)
|
err := removeFlagSet.Parse(subcommandArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -407,5 +774,8 @@ func resolveFlags() {
|
|||||||
}
|
}
|
||||||
subcommandArgs = fileFlagSet.Args()
|
subcommandArgs = fileFlagSet.Args()
|
||||||
}
|
}
|
||||||
|
if reinstallAll {
|
||||||
|
reinstall = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BPMConfigStruct struct {
|
||||||
|
CompilationEnv []string `yaml:"compilation_env"`
|
||||||
|
SilentCompilation bool `yaml:"silent_compilation"`
|
||||||
|
BinaryOutputDir string `yaml:"binary_output_dir"`
|
||||||
|
CompilationDir string `yaml:"compilation_dir"`
|
||||||
|
Repositories []*Repository `yaml:"repositories"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var BPMConfig BPMConfigStruct
|
||||||
|
|
||||||
|
func ReadConfig() {
|
||||||
|
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
bytes, err := os.ReadFile("/etc/bpm.conf")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
BPMConfig = BPMConfigStruct{
|
||||||
|
CompilationEnv: make([]string, 0),
|
||||||
|
SilentCompilation: false,
|
||||||
|
BinaryOutputDir: "/var/lib/bpm/compiled/",
|
||||||
|
CompilationDir: "/var/tmp/",
|
||||||
|
}
|
||||||
|
err = yaml.Unmarshal(bytes, &BPMConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
for i := len(BPMConfig.Repositories) - 1; i >= 0; i-- {
|
||||||
|
if BPMConfig.Repositories[i].Disabled != nil && *BPMConfig.Repositories[i].Disabled {
|
||||||
|
BPMConfig.Repositories = append(BPMConfig.Repositories[:i], BPMConfig.Repositories[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, repo := range BPMConfig.Repositories {
|
||||||
|
repo.Entries = make(map[string]*RepositoryEntry)
|
||||||
|
err := repo.ReadLocalDatabase()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package bpm_utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package bpm_utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
@@ -19,17 +20,56 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PackageInfo struct {
|
type PackageInfo struct {
|
||||||
Name string
|
Name string `yaml:"name,omitempty"`
|
||||||
Description string
|
Description string `yaml:"description,omitempty"`
|
||||||
Version string
|
Version string `yaml:"version,omitempty"`
|
||||||
Url string
|
Url string `yaml:"url,omitempty"`
|
||||||
License string
|
License string `yaml:"license,omitempty"`
|
||||||
Arch string
|
Arch string `yaml:"architecture,omitempty"`
|
||||||
Type string
|
Type string `yaml:"type,omitempty"`
|
||||||
Keep []string
|
Keep []string `yaml:"keep,omitempty"`
|
||||||
Depends []string
|
Depends []string `yaml:"depends,omitempty"`
|
||||||
MakeDepends []string
|
MakeDepends []string `yaml:"make_depends,omitempty"`
|
||||||
Provides []string
|
OptionalDepends []string `yaml:"optional_depends,omitempty"`
|
||||||
|
Conflicts []string `yaml:"conflicts,omitempty"`
|
||||||
|
Provides []string `yaml:"provides,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type InstallationReason string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Manual InstallationReason = "manual"
|
||||||
|
Dependency InstallationReason = "dependency"
|
||||||
|
Unknown InstallationReason = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetInstallationReason(pkg, rootDir string) InstallationReason {
|
||||||
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
|
if stat, err := os.Stat(path.Join(pkgDir, "installation_reason")); err != nil || stat.IsDir() {
|
||||||
|
return Manual
|
||||||
|
}
|
||||||
|
bytes, err := os.ReadFile(path.Join(pkgDir, "installation_reason"))
|
||||||
|
if err != nil {
|
||||||
|
return Unknown
|
||||||
|
}
|
||||||
|
reason := string(bytes)
|
||||||
|
if reason == "manual" {
|
||||||
|
return Manual
|
||||||
|
} else if reason == "dependency" {
|
||||||
|
return Dependency
|
||||||
|
}
|
||||||
|
return Unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetInstallationReason(pkg string, reason InstallationReason, rootDir string) error {
|
||||||
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
|
err := os.WriteFile(path.Join(pkgDir, "installation_reason"), []byte(reason), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPackageInfoRaw(filename string) (string, error) {
|
func GetPackageInfoRaw(filename string) (string, error) {
|
||||||
@@ -275,59 +315,16 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error)
|
|||||||
License: "",
|
License: "",
|
||||||
Arch: "",
|
Arch: "",
|
||||||
Type: "",
|
Type: "",
|
||||||
Keep: nil,
|
Keep: make([]string, 0),
|
||||||
Depends: nil,
|
Depends: make([]string, 0),
|
||||||
MakeDepends: nil,
|
MakeDepends: make([]string, 0),
|
||||||
Provides: nil,
|
OptionalDepends: make([]string, 0),
|
||||||
}
|
Conflicts: make([]string, 0),
|
||||||
lines := strings.Split(contents, "\n")
|
Provides: make([]string, 0),
|
||||||
for num, line := range lines {
|
|
||||||
if len(strings.TrimSpace(line)) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if line[0] == '#' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
split := strings.SplitN(line, ":", 2)
|
|
||||||
if len(split) != 2 {
|
|
||||||
return nil, errors.New("invalid pkg.info format at line " + strconv.Itoa(num))
|
|
||||||
}
|
|
||||||
split[0] = strings.Trim(split[0], " ")
|
|
||||||
split[1] = strings.Trim(split[1], " ")
|
|
||||||
switch split[0] {
|
|
||||||
case "name":
|
|
||||||
if strings.Contains(split[1], " ") {
|
|
||||||
return nil, errors.New("the " + split[0] + " field cannot contain spaces")
|
|
||||||
}
|
|
||||||
pkgInfo.Name = split[1]
|
|
||||||
case "description":
|
|
||||||
pkgInfo.Description = split[1]
|
|
||||||
case "version":
|
|
||||||
if strings.Contains(split[1], " ") {
|
|
||||||
return nil, errors.New("the " + split[0] + " field cannot contain spaces")
|
|
||||||
}
|
|
||||||
pkgInfo.Version = split[1]
|
|
||||||
case "url":
|
|
||||||
pkgInfo.Url = split[1]
|
|
||||||
case "license":
|
|
||||||
pkgInfo.License = split[1]
|
|
||||||
case "architecture":
|
|
||||||
pkgInfo.Arch = split[1]
|
|
||||||
case "type":
|
|
||||||
pkgInfo.Type = split[1]
|
|
||||||
case "keep":
|
|
||||||
pkgInfo.Keep = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
|
||||||
pkgInfo.Keep = stringSliceRemoveEmpty(pkgInfo.Keep)
|
|
||||||
case "depends":
|
|
||||||
pkgInfo.Depends = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
|
||||||
pkgInfo.Depends = stringSliceRemoveEmpty(pkgInfo.Depends)
|
|
||||||
case "make_depends":
|
|
||||||
pkgInfo.MakeDepends = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
|
||||||
pkgInfo.MakeDepends = stringSliceRemoveEmpty(pkgInfo.MakeDepends)
|
|
||||||
case "provides":
|
|
||||||
pkgInfo.Provides = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
|
||||||
pkgInfo.Provides = stringSliceRemoveEmpty(pkgInfo.Provides)
|
|
||||||
}
|
}
|
||||||
|
err := yaml.Unmarshal([]byte(contents), &pkgInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
if !defaultValues {
|
if !defaultValues {
|
||||||
if pkgInfo.Name == "" {
|
if pkgInfo.Name == "" {
|
||||||
@@ -342,38 +339,52 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error)
|
|||||||
return nil, errors.New("this package contains no type")
|
return nil, errors.New("this package contains no type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for i := 0; i < len(pkgInfo.Keep); i++ {
|
||||||
|
pkgInfo.Keep[i] = strings.TrimPrefix(pkgInfo.Keep[i], "/")
|
||||||
|
}
|
||||||
return &pkgInfo, nil
|
return &pkgInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateInfoFile(pkgInfo PackageInfo, keepSourceFields bool) string {
|
func CreateInfoFile(pkgInfo *PackageInfo) string {
|
||||||
ret := ""
|
bytes, err := yaml.Marshal(&pkgInfo)
|
||||||
ret = ret + "name: " + pkgInfo.Name + "\n"
|
if err != nil {
|
||||||
ret = ret + "description: " + pkgInfo.Description + "\n"
|
return ""
|
||||||
ret = ret + "version: " + pkgInfo.Version + "\n"
|
|
||||||
if pkgInfo.Url != "" {
|
|
||||||
ret = ret + "url: " + pkgInfo.Url + "\n"
|
|
||||||
}
|
}
|
||||||
if pkgInfo.License != "" {
|
return string(bytes)
|
||||||
ret = ret + "license: " + pkgInfo.License + "\n"
|
|
||||||
}
|
|
||||||
ret = ret + "architecture: " + pkgInfo.Arch + "\n"
|
|
||||||
ret = ret + "type: " + pkgInfo.Type + "\n"
|
|
||||||
if len(pkgInfo.Keep) > 0 {
|
|
||||||
ret = ret + "keep (" + strconv.Itoa(len(pkgInfo.Keep)) + "): " + strings.Join(pkgInfo.Keep, ",") + "\n"
|
|
||||||
}
|
|
||||||
if len(pkgInfo.Depends) > 0 {
|
|
||||||
ret = ret + "depends (" + strconv.Itoa(len(pkgInfo.Depends)) + "): " + strings.Join(pkgInfo.Depends, ",") + "\n"
|
|
||||||
}
|
|
||||||
if len(pkgInfo.MakeDepends) > 0 && keepSourceFields {
|
|
||||||
ret = ret + "make_depends (" + strconv.Itoa(len(pkgInfo.MakeDepends)) + "): " + strings.Join(pkgInfo.MakeDepends, ",") + "\n"
|
|
||||||
}
|
|
||||||
if len(pkgInfo.Provides) > 0 {
|
|
||||||
ret = ret + "provides (" + strconv.Itoa(len(pkgInfo.Provides)) + "): " + strings.Join(pkgInfo.Provides, ",") + "\n"
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractPackage(pkgInfo *PackageInfo, filename, rootDir string) (error, []string) {
|
func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, pkgInfo *PackageInfo, rootDir string) string {
|
||||||
|
ret := make([]string, 0)
|
||||||
|
appendArray := func(label string, array []string) {
|
||||||
|
if len(array) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ret = append(ret, fmt.Sprintf("%s: %s", label, strings.Join(array, ", ")))
|
||||||
|
}
|
||||||
|
ret = append(ret, "Name: "+pkgInfo.Name)
|
||||||
|
ret = append(ret, "Description: "+pkgInfo.Description)
|
||||||
|
ret = append(ret, "Version: "+pkgInfo.Version)
|
||||||
|
ret = append(ret, "URL: "+pkgInfo.Url)
|
||||||
|
ret = append(ret, "License: "+pkgInfo.License)
|
||||||
|
if showArchitecture {
|
||||||
|
ret = append(ret, "Architecture: "+pkgInfo.Arch)
|
||||||
|
}
|
||||||
|
if showType {
|
||||||
|
ret = append(ret, "Type: "+pkgInfo.Type)
|
||||||
|
}
|
||||||
|
if showPackageRelations {
|
||||||
|
appendArray("Dependencies", pkgInfo.Depends)
|
||||||
|
appendArray("Make Dependencies", pkgInfo.MakeDepends)
|
||||||
|
appendArray("Optional dependencies", pkgInfo.OptionalDepends)
|
||||||
|
appendArray("Conflicting packages", pkgInfo.Conflicts)
|
||||||
|
appendArray("Provided packages", pkgInfo.Provides)
|
||||||
|
|
||||||
|
}
|
||||||
|
ret = append(ret, "Installation Reason: "+string(GetInstallationReason(pkgInfo.Name, rootDir)))
|
||||||
|
return strings.Join(ret, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractPackage(pkgInfo *PackageInfo, verbose bool, filename, rootDir string) (error, []string) {
|
||||||
var files []string
|
var files []string
|
||||||
if !IsPackageInstalled(pkgInfo.Name, rootDir) {
|
if !IsPackageInstalled(pkgInfo.Name, rootDir) {
|
||||||
err := ExecutePackageScripts(filename, rootDir, Install, false)
|
err := ExecutePackageScripts(filename, rootDir, Install, false)
|
||||||
@@ -415,22 +426,46 @@ func extractPackage(pkgInfo *PackageInfo, filename, rootDir string) (error, []st
|
|||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating Directory: " + extractFilename)
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case tar.TypeReg:
|
case tar.TypeReg:
|
||||||
|
skip := false
|
||||||
if _, err := os.Stat(extractFilename); err == nil {
|
if _, err := os.Stat(extractFilename); err == nil {
|
||||||
if slices.Contains(pkgInfo.Keep, trimmedName) {
|
for _, k := range pkgInfo.Keep {
|
||||||
fmt.Println("Skipping File: " + extractFilename + "(File is configured to be kept during installs/updates)")
|
if strings.HasSuffix(k, "/") {
|
||||||
files = append(files, trimmedName)
|
if strings.HasPrefix(trimmedName, k) {
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Skipping File: " + extractFilename + " (Containing directory is set to be kept during installs/updates)")
|
||||||
|
}
|
||||||
|
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
||||||
|
skip = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if trimmedName == k {
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Skipping File: " + extractFilename + " (File is configured to be kept during installs/updates)")
|
||||||
|
}
|
||||||
|
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
||||||
|
skip = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if skip {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
err := os.Remove(extractFilename)
|
err := os.Remove(extractFilename)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
outFile, err := os.Create(extractFilename)
|
outFile, err := os.Create(extractFilename)
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
fmt.Println("Creating File: " + extractFilename)
|
||||||
|
}
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
@@ -446,7 +481,9 @@ func extractPackage(pkgInfo *PackageInfo, filename, rootDir string) (error, []st
|
|||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
case tar.TypeSymlink:
|
case tar.TypeSymlink:
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating Symlink: " + extractFilename + " -> " + header.Linkname)
|
fmt.Println("Creating Symlink: " + extractFilename + " -> " + header.Linkname)
|
||||||
|
}
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
||||||
err := os.Remove(extractFilename)
|
err := os.Remove(extractFilename)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
@@ -457,7 +494,9 @@ func extractPackage(pkgInfo *PackageInfo, filename, rootDir string) (error, []st
|
|||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
case tar.TypeLink:
|
case tar.TypeLink:
|
||||||
|
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/")))
|
||||||
|
}
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
||||||
seenHardlinks[extractFilename] = path.Join(strings.TrimPrefix(header.Linkname, "files/"))
|
seenHardlinks[extractFilename] = path.Join(strings.TrimPrefix(header.Linkname, "files/"))
|
||||||
err := os.Remove(extractFilename)
|
err := os.Remove(extractFilename)
|
||||||
@@ -470,7 +509,9 @@ func extractPackage(pkgInfo *PackageInfo, filename, rootDir string) (error, []st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for extractFilename, destination := range seenHardlinks {
|
for extractFilename, destination := range seenHardlinks {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating Hard Link: " + extractFilename + " -> " + path.Join(rootDir, destination))
|
fmt.Println("Creating Hard Link: " + extractFilename + " -> " + path.Join(rootDir, destination))
|
||||||
|
}
|
||||||
err := os.Link(path.Join(rootDir, destination), extractFilename)
|
err := os.Link(path.Join(rootDir, destination), extractFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
@@ -496,7 +537,7 @@ func isSplitPackage(filename string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFromSrc, skipCheck, keepTempDir bool) (error, []string) {
|
func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, verbose, binaryPkgFromSrc, skipCheck, keepTempDir bool) (error, []string) {
|
||||||
var files []string
|
var files []string
|
||||||
if !IsPackageInstalled(pkgInfo.Name, rootDir) {
|
if !IsPackageInstalled(pkgInfo.Name, rootDir) {
|
||||||
err := ExecutePackageScripts(filename, rootDir, Install, false)
|
err := ExecutePackageScripts(filename, rootDir, Install, false)
|
||||||
@@ -525,7 +566,9 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating temp directory at: " + temp)
|
fmt.Println("Creating temp directory at: " + temp)
|
||||||
|
}
|
||||||
err = os.Mkdir(temp, 0755)
|
err = os.Mkdir(temp, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
@@ -552,7 +595,9 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFro
|
|||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating Directory: " + extractFilename)
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
|
}
|
||||||
err = os.Chown(extractFilename, 65534, 65534)
|
err = os.Chown(extractFilename, 65534, 65534)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
@@ -564,7 +609,9 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFro
|
|||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
outFile, err := os.Create(extractFilename)
|
outFile, err := os.Create(extractFilename)
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
fmt.Println("Creating File: " + extractFilename)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
@@ -583,9 +630,13 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, binaryPkgFro
|
|||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
case tar.TypeSymlink:
|
case tar.TypeSymlink:
|
||||||
|
if verbose {
|
||||||
fmt.Println("Skipping symlink (Bundling symlinks in source packages is not supported)")
|
fmt.Println("Skipping symlink (Bundling symlinks in source packages is not supported)")
|
||||||
|
}
|
||||||
case tar.TypeLink:
|
case tar.TypeLink:
|
||||||
|
if verbose {
|
||||||
fmt.Println("Skipping hard link (Bundling hard links in source packages is not supported)")
|
fmt.Println("Skipping hard link (Bundling hard links in source packages is not supported)")
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename), nil
|
return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename), nil
|
||||||
}
|
}
|
||||||
@@ -779,12 +830,16 @@ fi
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating Directory: " + extractFilename)
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if d.Type().IsRegular() {
|
} else if d.Type().IsRegular() {
|
||||||
if _, err := os.Stat(extractFilename); err == nil {
|
if _, err := os.Stat(extractFilename); err == nil {
|
||||||
if slices.Contains(pkgInfo.Keep, relFilename) {
|
if slices.Contains(pkgInfo.Keep, relFilename) {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Skipping File: " + extractFilename + "(File is configured to be kept during installs/updates)")
|
fmt.Println("Skipping File: " + extractFilename + "(File is configured to be kept during installs/updates)")
|
||||||
|
}
|
||||||
files = append(files, relFilename)
|
files = append(files, relFilename)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -794,7 +849,9 @@ fi
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
outFile, err := os.Create(extractFilename)
|
outFile, err := os.Create(extractFilename)
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
fmt.Println("Creating File: " + extractFilename)
|
||||||
|
}
|
||||||
files = append(files, relFilename)
|
files = append(files, relFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -830,7 +887,9 @@ fi
|
|||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if verbose {
|
||||||
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
||||||
|
}
|
||||||
files = append(files, relFilename)
|
files = append(files, relFilename)
|
||||||
err = os.Symlink(link, extractFilename)
|
err = os.Symlink(link, extractFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -849,7 +908,7 @@ fi
|
|||||||
compiledInfo = *pkgInfo
|
compiledInfo = *pkgInfo
|
||||||
compiledInfo.Type = "binary"
|
compiledInfo.Type = "binary"
|
||||||
compiledInfo.Arch = GetArch()
|
compiledInfo.Arch = GetArch()
|
||||||
err = os.WriteFile(path.Join(temp, "pkg.info"), []byte(CreateInfoFile(compiledInfo, false)), 0644)
|
err = os.WriteFile(path.Join(temp, "pkg.info"), []byte(CreateInfoFile(&compiledInfo)), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
@@ -909,7 +968,7 @@ fi
|
|||||||
return nil, files
|
return nil, files
|
||||||
}
|
}
|
||||||
|
|
||||||
func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck, keepTempDir bool) error {
|
func InstallPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc, skipCheck, keepTempDir bool) error {
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -927,12 +986,12 @@ func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck
|
|||||||
if pkgInfo.Arch != "any" && pkgInfo.Arch != GetArch() {
|
if pkgInfo.Arch != "any" && pkgInfo.Arch != GetArch() {
|
||||||
return errors.New("cannot install a package with a different architecture")
|
return errors.New("cannot install a package with a different architecture")
|
||||||
}
|
}
|
||||||
if unresolved := CheckDependencies(pkgInfo, rootDir); len(unresolved) != 0 {
|
if unresolved := pkgInfo.CheckDependencies(pkgInfo.Type == "source", true, rootDir); len(unresolved) != 0 {
|
||||||
return errors.New("Could not resolve all dependencies. Missing " + strings.Join(unresolved, ", "))
|
return errors.New("Could not resolve all dependencies. Missing " + strings.Join(unresolved, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pkgInfo.Type == "binary" {
|
if pkgInfo.Type == "binary" {
|
||||||
err, i := extractPackage(pkgInfo, filename, rootDir)
|
err, i := extractPackage(pkgInfo, verbose, filename, rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -941,7 +1000,7 @@ func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck
|
|||||||
if isSplitPackage(filename) {
|
if isSplitPackage(filename) {
|
||||||
return errors.New("BPM is unable to install split source packages")
|
return errors.New("BPM is unable to install split source packages")
|
||||||
}
|
}
|
||||||
err, i := compilePackage(pkgInfo, filename, rootDir, binaryPkgFromSrc, skipCheck, keepTempDir)
|
err, i := compilePackage(pkgInfo, filename, rootDir, verbose, binaryPkgFromSrc, skipCheck, keepTempDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1023,7 +1082,7 @@ func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(filesDiff) != 0 {
|
if len(filesDiff) != 0 {
|
||||||
fmt.Println("Removing obsolete files")
|
fmt.Println("Removing obsolete files...")
|
||||||
var symlinks []string
|
var symlinks []string
|
||||||
for _, f := range filesDiff {
|
for _, f := range filesDiff {
|
||||||
f = path.Join(rootDir, f)
|
f = path.Join(rootDir, f)
|
||||||
@@ -1049,14 +1108,18 @@ func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dir) == 0 {
|
if len(dir) == 0 {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Removing: " + f)
|
fmt.Println("Removing: " + f)
|
||||||
|
}
|
||||||
err := os.Remove(f)
|
err := os.Remove(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Removing: " + f)
|
fmt.Println("Removing: " + f)
|
||||||
|
}
|
||||||
err := os.Remove(f)
|
err := os.Remove(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1082,7 +1145,9 @@ func InstallPackage(filename, rootDir string, force, binaryPkgFromSrc, skipCheck
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
removals++
|
removals++
|
||||||
|
if verbose {
|
||||||
fmt.Println("Removing: " + f)
|
fmt.Println("Removing: " + f)
|
||||||
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1144,24 +1209,73 @@ func GetSourceScript(filename string) (string, error) {
|
|||||||
return "", errors.New("package does not contain a source.sh file")
|
return "", errors.New("package does not contain a source.sh file")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckDependencies(pkgInfo *PackageInfo, rootDir string) []string {
|
func (pkgInfo *PackageInfo) GetAllDependencies(checkMake, checkOptional bool) []string {
|
||||||
var unresolved []string
|
allDepends := make([]string, 0)
|
||||||
for _, dependency := range pkgInfo.Depends {
|
allDepends = append(allDepends, pkgInfo.Depends...)
|
||||||
if !IsPackageInstalled(dependency, rootDir) {
|
if checkMake {
|
||||||
unresolved = append(unresolved, dependency)
|
allDepends = append(allDepends, pkgInfo.MakeDepends...)
|
||||||
}
|
}
|
||||||
|
if checkOptional {
|
||||||
|
allDepends = append(allDepends, pkgInfo.OptionalDepends...)
|
||||||
}
|
}
|
||||||
return unresolved
|
return allDepends
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckMakeDependencies(pkgInfo *PackageInfo, rootDir string) []string {
|
func (pkgInfo *PackageInfo) CheckDependencies(checkMake, checkOptional bool, rootDir string) []string {
|
||||||
var unresolved []string
|
var ret []string
|
||||||
|
for _, dependency := range pkgInfo.Depends {
|
||||||
|
if !IsPackageProvided(dependency, rootDir) {
|
||||||
|
ret = append(ret, dependency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if checkMake {
|
||||||
for _, dependency := range pkgInfo.MakeDepends {
|
for _, dependency := range pkgInfo.MakeDepends {
|
||||||
if !IsPackageInstalled(dependency, "/") {
|
if !IsPackageProvided(dependency, rootDir) {
|
||||||
unresolved = append(unresolved, dependency)
|
ret = append(ret, dependency)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return unresolved
|
}
|
||||||
|
if checkOptional {
|
||||||
|
for _, dependency := range pkgInfo.OptionalDepends {
|
||||||
|
if !IsPackageProvided(dependency, rootDir) {
|
||||||
|
ret = append(ret, dependency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pkgInfo *PackageInfo) CheckConflicts(rootDir string) []string {
|
||||||
|
var ret []string
|
||||||
|
for _, conflict := range pkgInfo.Conflicts {
|
||||||
|
if IsPackageInstalled(conflict, rootDir) {
|
||||||
|
ret = append(ret, conflict)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pkgInfo *PackageInfo) ResolveAll(resolved, unresolved *[]string, checkMake, checkOptional, ignoreInstalled bool, rootDir string) ([]string, []string) {
|
||||||
|
*unresolved = append(*unresolved, pkgInfo.Name)
|
||||||
|
for _, depend := range pkgInfo.GetAllDependencies(checkMake, checkOptional) {
|
||||||
|
if !slices.Contains(*resolved, depend) {
|
||||||
|
if slices.Contains(*unresolved, depend) || (ignoreInstalled && IsPackageInstalled(depend, rootDir)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
entry, _, err := GetRepositoryEntry(depend)
|
||||||
|
if err != nil {
|
||||||
|
if !slices.Contains(*unresolved, depend) {
|
||||||
|
*unresolved = append(*unresolved, depend)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
entry.Info.ResolveAll(resolved, unresolved, checkMake, checkOptional, ignoreInstalled, rootDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*resolved = append(*resolved, pkgInfo.Name)
|
||||||
|
*unresolved = stringSliceRemove(*unresolved, pkgInfo.Name)
|
||||||
|
return *resolved, *unresolved
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPackageInstalled(pkg, rootDir string) bool {
|
func IsPackageInstalled(pkg, rootDir string) bool {
|
||||||
@@ -1173,6 +1287,26 @@ func IsPackageInstalled(pkg, rootDir string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsPackageProvided(pkg, rootDir string) bool {
|
||||||
|
pkgs, err := GetInstalledPackages(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, p := range pkgs {
|
||||||
|
if p == pkg {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
i := GetPackageInfo(p, rootDir, true)
|
||||||
|
if i == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if slices.Contains(i.Provides, pkg) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func GetInstalledPackages(rootDir string) ([]string, error) {
|
func GetInstalledPackages(rootDir string) ([]string, error) {
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
items, err := os.ReadDir(installedDir)
|
items, err := os.ReadDir(installedDir)
|
||||||
@@ -1236,7 +1370,7 @@ func GetPackageInfo(pkg, rootDir string, defaultValues bool) *PackageInfo {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemovePackage(pkg, rootDir string) error {
|
func RemovePackage(pkg string, verbose bool, rootDir string) error {
|
||||||
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)
|
||||||
pkgInfo := GetPackageInfo(pkg, rootDir, false)
|
pkgInfo := GetPackageInfo(pkg, rootDir, false)
|
||||||
@@ -1271,14 +1405,18 @@ func RemovePackage(pkg, rootDir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dir) == 0 {
|
if len(dir) == 0 {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Removing: " + file)
|
fmt.Println("Removing: " + file)
|
||||||
|
}
|
||||||
err := os.Remove(file)
|
err := os.Remove(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if verbose {
|
||||||
fmt.Println("Removing: " + file)
|
fmt.Println("Removing: " + file)
|
||||||
|
}
|
||||||
err := os.Remove(file)
|
err := os.Remove(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1304,7 +1442,9 @@ func RemovePackage(pkg, rootDir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
removals++
|
removals++
|
||||||
|
if verbose {
|
||||||
fmt.Println("Removing: " + file)
|
fmt.Println("Removing: " + file)
|
||||||
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1347,6 +1487,8 @@ func RemovePackage(pkg, rootDir string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if verbose {
|
||||||
fmt.Println("Removing: " + pkgDir)
|
fmt.Println("Removing: " + pkgDir)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Source string `yaml:"source"`
|
||||||
|
Disabled *bool `yaml:"disabled"`
|
||||||
|
Entries map[string]*RepositoryEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepositoryEntry struct {
|
||||||
|
Info *PackageInfo `yaml:"info"`
|
||||||
|
Download string `yaml:"download"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) ContainsPackage(pkg string) bool {
|
||||||
|
_, ok := repo.Entries[pkg]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) ReadLocalDatabase() error {
|
||||||
|
repoFile := "/var/lib/bpm/repositories/" + repo.Name + ".bpmdb"
|
||||||
|
if _, err := os.Stat(repoFile); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes, err := os.ReadFile(repoFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
data := string(bytes)
|
||||||
|
for _, b := range strings.Split(data, "---") {
|
||||||
|
entry := RepositoryEntry{
|
||||||
|
Info: &PackageInfo{
|
||||||
|
Name: "",
|
||||||
|
Description: "",
|
||||||
|
Version: "",
|
||||||
|
Url: "",
|
||||||
|
License: "",
|
||||||
|
Arch: "",
|
||||||
|
Type: "",
|
||||||
|
Keep: make([]string, 0),
|
||||||
|
Depends: make([]string, 0),
|
||||||
|
MakeDepends: make([]string, 0),
|
||||||
|
OptionalDepends: make([]string, 0),
|
||||||
|
Conflicts: make([]string, 0),
|
||||||
|
Provides: make([]string, 0),
|
||||||
|
},
|
||||||
|
Download: "",
|
||||||
|
}
|
||||||
|
err := yaml.Unmarshal([]byte(b), &entry)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
repo.Entries[entry.Info.Name] = &entry
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) SyncLocalDatabase() error {
|
||||||
|
repoFile := "/var/lib/bpm/repositories/" + repo.Name + ".bpmdb"
|
||||||
|
err := os.MkdirAll(path.Dir(repoFile), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.JoinPath(repo.Source, "database.bpmdb")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.Get(u)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
out, err := os.Create(repoFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRepository(name string) *Repository {
|
||||||
|
for _, repo := range BPMConfig.Repositories {
|
||||||
|
if repo.Name == name {
|
||||||
|
return repo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRepositoryEntry(str string) (*RepositoryEntry, *Repository, error) {
|
||||||
|
split := strings.Split(str, "/")
|
||||||
|
if len(split) == 1 {
|
||||||
|
pkgName := strings.TrimSpace(split[0])
|
||||||
|
if pkgName == "" {
|
||||||
|
return nil, nil, errors.New("could not find repository entry for this package")
|
||||||
|
}
|
||||||
|
for _, repo := range BPMConfig.Repositories {
|
||||||
|
if repo.ContainsPackage(pkgName) {
|
||||||
|
return repo.Entries[pkgName], repo, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil, errors.New("could not find repository entry for this package")
|
||||||
|
} else if len(split) == 2 {
|
||||||
|
repoName := strings.TrimSpace(split[0])
|
||||||
|
pkgName := strings.TrimSpace(split[1])
|
||||||
|
if repoName == "" || pkgName == "" {
|
||||||
|
return nil, nil, errors.New("could not find repository entry for this package")
|
||||||
|
}
|
||||||
|
repo := GetRepository(repoName)
|
||||||
|
if repo == nil || !repo.ContainsPackage(pkgName) {
|
||||||
|
return nil, nil, errors.New("could not find repository entry for this package")
|
||||||
|
}
|
||||||
|
return repo.Entries[pkgName], repo, nil
|
||||||
|
} else {
|
||||||
|
return nil, nil, errors.New("could not find repository entry for this package")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) FetchPackage(pkg string) (string, error) {
|
||||||
|
if !repo.ContainsPackage(pkg) {
|
||||||
|
return "", errors.New("Could not fetch package '" + pkg + "'")
|
||||||
|
}
|
||||||
|
entry := repo.Entries[pkg]
|
||||||
|
URL, err := url.JoinPath(repo.Source, entry.Download)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
resp, err := http.Get(URL)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
err = os.MkdirAll("/var/cache/bpm/packages/", 0755)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
out, err := os.Create("/var/cache/bpm/packages/" + path.Base(entry.Download))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
return "/var/cache/bpm/packages/" + path.Base(entry.Download), nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user