Compare commits
No commits in common. "2f8d6a7ea9e2230cfbd5e73e7719eb827b484c4a" and "e60381beb1d923177489f952fc619adf179cc163" have entirely different histories.
2f8d6a7ea9
...
e60381beb1
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
"git.enumerated.dev/bubble-package-manager/bpm/src/bpmlib"
|
||||||
@ -27,6 +26,9 @@ var subcommandArgs []string
|
|||||||
var rootDir = "/"
|
var rootDir = "/"
|
||||||
var verbose = false
|
var verbose = false
|
||||||
var yesAll = false
|
var yesAll = false
|
||||||
|
var buildSource = false
|
||||||
|
var skipCheck = false
|
||||||
|
var keepTempDir = false
|
||||||
var force = false
|
var force = false
|
||||||
var pkgListNumbers = false
|
var pkgListNumbers = false
|
||||||
var pkgListNames = false
|
var pkgListNames = false
|
||||||
@ -40,10 +42,7 @@ var doCleanup = false
|
|||||||
var showRepoInfo = false
|
var showRepoInfo = false
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := bpmlib.ReadConfig()
|
bpmlib.ReadConfig()
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error: could not read BPM config: %s", err)
|
|
||||||
}
|
|
||||||
resolveFlags()
|
resolveFlags()
|
||||||
resolveCommand()
|
resolveCommand()
|
||||||
}
|
}
|
||||||
@ -236,19 +235,8 @@ func resolveCommand() {
|
|||||||
reinstallMethod = bpmlib.ReinstallMethodNone
|
reinstallMethod = bpmlib.ReinstallMethodNone
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create installation operation
|
// Create Installation Operation
|
||||||
operation, err := bpmlib.InstallPackages(rootDir, ir, reinstallMethod, !noOptional, force, verbose, subcommandArgs...)
|
operation, err := bpmlib.InstallPackages(rootDir, ir, reinstallMethod, !noOptional, force, verbose, subcommandArgs...)
|
||||||
if errors.As(err, &bpmlib.PackageNotFoundErr{}) || errors.As(err, &bpmlib.DependencyNotFoundErr{}) || errors.As(err, &bpmlib.PackageConflictErr{}) {
|
|
||||||
log.Fatalf("Error: %s", err)
|
|
||||||
} else if err != nil {
|
|
||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit if operation contains no actions
|
|
||||||
if len(operation.Actions) == 0 {
|
|
||||||
fmt.Println("No action needs to be taken")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
operation.ShowOperationSummary()
|
operation.ShowOperationSummary()
|
||||||
@ -287,18 +275,10 @@ func resolveCommand() {
|
|||||||
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create update operation
|
// Create Update Operation
|
||||||
operation, err := bpmlib.UpdatePackages(rootDir, !nosync, !noOptional, force, verbose)
|
operation, err := bpmlib.UpdatePackages(rootDir, !nosync, !noOptional, force, verbose)
|
||||||
if errors.As(err, &bpmlib.PackageNotFoundErr{}) || errors.As(err, &bpmlib.DependencyNotFoundErr{}) || errors.As(err, &bpmlib.PackageConflictErr{}) {
|
if err != nil {
|
||||||
log.Fatalf("Error: %s", err)
|
log.Fatalf("Error: could not update packages: %s\n", err)
|
||||||
} else if err != nil {
|
|
||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit if operation contains no actions
|
|
||||||
if len(operation.Actions) == 0 {
|
|
||||||
fmt.Println("No action needs to be taken")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
@ -344,7 +324,6 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync databases
|
|
||||||
err := bpmlib.SyncDatabase(verbose)
|
err := bpmlib.SyncDatabase(verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error: could not sync local database: %s\n", err)
|
log.Fatalf("Error: could not sync local database: %s\n", err)
|
||||||
@ -362,18 +341,10 @@ func resolveCommand() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create remove operation
|
// Remove packages
|
||||||
operation, err := bpmlib.RemovePackages(rootDir, removeUnused, doCleanup, verbose, subcommandArgs...)
|
operation, err := bpmlib.RemovePackages(rootDir, removeUnused, doCleanup, verbose, subcommandArgs...)
|
||||||
if errors.As(err, &bpmlib.PackageNotFoundErr{}) || errors.As(err, &bpmlib.DependencyNotFoundErr{}) || errors.As(err, &bpmlib.PackageConflictErr{}) {
|
if err != nil {
|
||||||
log.Fatalf("Error: %s", err)
|
log.Fatalf("Error: could not remove packages: %s\n", err)
|
||||||
} else if err != nil {
|
|
||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit if operation contains no actions
|
|
||||||
if len(operation.Actions) == 0 {
|
|
||||||
fmt.Println("No action needs to be taken")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
@ -408,18 +379,10 @@ func resolveCommand() {
|
|||||||
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create cleanup operation
|
// Do cleanup
|
||||||
operation, err := bpmlib.CleanupPackages(rootDir, verbose)
|
operation, err := bpmlib.CleanupPackages(rootDir, verbose)
|
||||||
if errors.As(err, &bpmlib.PackageNotFoundErr{}) || errors.As(err, &bpmlib.DependencyNotFoundErr{}) || errors.As(err, &bpmlib.PackageConflictErr{}) {
|
if err != nil {
|
||||||
log.Fatalf("Error: %s", err)
|
log.Fatalf("Error: could not cleanup packages: %s\n", err)
|
||||||
} else if err != nil {
|
|
||||||
log.Fatalf("Error: could not setup operation: %s\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit if operation contains no actions
|
|
||||||
if len(operation.Actions) == 0 {
|
|
||||||
fmt.Println("No action needs to be taken")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show operation summary
|
// Show operation summary
|
||||||
@ -521,6 +484,9 @@ func printHelp() {
|
|||||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
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, conflict 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(" -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(" -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(" --reinstall Reinstalls packages even if they do not have a newer version available")
|
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(" --reinstall-all Same as --reinstall but also reinstalls dependencies")
|
||||||
@ -541,8 +507,8 @@ func printHelp() {
|
|||||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
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(" --unused removes only packages that aren't required as dependencies by other packages")
|
fmt.Println(" -unused removes only packages that aren't required as dependencies by other packages")
|
||||||
fmt.Println(" --cleanup performs a dependency cleanup")
|
fmt.Println(" -cleanup performs a dependency cleanup")
|
||||||
fmt.Println("-> bpm cleanup [-R, -v, -y] | remove all unused dependency packages")
|
fmt.Println("-> bpm cleanup [-R, -v, -y] | remove all unused dependency packages")
|
||||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
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")
|
||||||
@ -569,6 +535,11 @@ func resolveFlags() {
|
|||||||
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(&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(&bpmlib.BPMConfig.BinaryOutputDir, "o", bpmlib.BPMConfig.BinaryOutputDir, "Set the binary output directory")
|
||||||
|
installFlagSet.StringVar(&bpmlib.BPMConfig.CompilationDir, "c", bpmlib.BPMConfig.CompilationDir, "Set the compilation directory")
|
||||||
|
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
|
||||||
|
installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation")
|
||||||
|
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
|
||||||
installFlagSet.BoolVar(&force, "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(&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(&reinstallAll, "reinstall-all", false, "Same as --reinstall but also reinstalls dependencies")
|
||||||
|
@ -2,46 +2,50 @@ package bpmlib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BPMConfigStruct struct {
|
type BPMConfigStruct struct {
|
||||||
IgnorePackages []string `yaml:"ignore_packages"`
|
CompilationEnv []string `yaml:"compilation_env"`
|
||||||
Repositories []*Repository `yaml:"repositories"`
|
SilentCompilation bool `yaml:"silent_compilation"`
|
||||||
|
BinaryOutputDir string `yaml:"binary_output_dir"`
|
||||||
|
CompilationDir string `yaml:"compilation_dir"`
|
||||||
|
IgnorePackages []string `yaml:"ignore_packages"`
|
||||||
|
Repositories []*Repository `yaml:"repositories"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var BPMConfig BPMConfigStruct
|
var BPMConfig BPMConfigStruct
|
||||||
|
|
||||||
func ReadConfig() (err error) {
|
func ReadConfig() {
|
||||||
if _, err = os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
||||||
return err
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := os.ReadFile("/etc/bpm.conf")
|
bytes, err := os.ReadFile("/etc/bpm.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
BPMConfig = BPMConfigStruct{
|
||||||
|
CompilationEnv: make([]string, 0),
|
||||||
|
SilentCompilation: false,
|
||||||
|
BinaryOutputDir: "/var/lib/bpm/compiled/",
|
||||||
|
CompilationDir: "/var/tmp/",
|
||||||
}
|
}
|
||||||
|
|
||||||
BPMConfig = BPMConfigStruct{}
|
|
||||||
err = yaml.Unmarshal(bytes, &BPMConfig)
|
err = yaml.Unmarshal(bytes, &BPMConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := len(BPMConfig.Repositories) - 1; i >= 0; i-- {
|
for i := len(BPMConfig.Repositories) - 1; i >= 0; i-- {
|
||||||
if BPMConfig.Repositories[i].Disabled != nil && *BPMConfig.Repositories[i].Disabled {
|
if BPMConfig.Repositories[i].Disabled != nil && *BPMConfig.Repositories[i].Disabled {
|
||||||
BPMConfig.Repositories = append(BPMConfig.Repositories[:i], BPMConfig.Repositories[i+1:]...)
|
BPMConfig.Repositories = append(BPMConfig.Repositories[:i], BPMConfig.Repositories[i+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, repo := range BPMConfig.Repositories {
|
for _, repo := range BPMConfig.Repositories {
|
||||||
repo.Entries = make(map[string]*RepositoryEntry)
|
repo.Entries = make(map[string]*RepositoryEntry)
|
||||||
repo.VirtualPackages = make(map[string][]string)
|
repo.VirtualPackages = make(map[string][]string)
|
||||||
err := repo.ReadLocalDatabase()
|
err := repo.ReadLocalDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package bpmlib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PackageNotFoundErr struct {
|
|
||||||
packages []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e PackageNotFoundErr) Error() string {
|
|
||||||
return "The following packages were not found in any repositories: " + strings.Join(e.packages, ", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
type DependencyNotFoundErr struct {
|
|
||||||
dependencies []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e DependencyNotFoundErr) Error() string {
|
|
||||||
return "The following dependencies were not found in any repositories: " + strings.Join(e.dependencies, ", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
type PackageConflictErr struct {
|
|
||||||
pkg string
|
|
||||||
conflicts []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e PackageConflictErr) Error() string {
|
|
||||||
return fmt.Sprintf("Package (%s) is in conflict with the following packages: %s", e.pkg, strings.Join(e.conflicts, ", "))
|
|
||||||
}
|
|
@ -1,11 +1,11 @@
|
|||||||
package bpmlib
|
package bpmlib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReinstallMethod uint8
|
type ReinstallMethod uint8
|
||||||
@ -28,7 +28,6 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resolve packages
|
// Resolve packages
|
||||||
pkgsNotFound := make([]string, 0)
|
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
|
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
|
||||||
bpmpkg, err := ReadPackage(pkg)
|
bpmpkg, err := ReadPackage(pkg)
|
||||||
@ -51,14 +50,12 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
} else if isVirtual, p := IsVirtualPackage(pkg, rootDir); isVirtual {
|
} else if isVirtual, p := IsVirtualPackage(pkg, rootDir); isVirtual {
|
||||||
entry, _, err = GetRepositoryEntry(p)
|
entry, _, err = GetRepositoryEntry(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pkgsNotFound = append(pkgsNotFound, pkg)
|
return nil, fmt.Errorf("could not find package (%s) in any repositor", p)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
} else if e := ResolveVirtualPackage(pkg); e != nil {
|
} else if e := ResolveVirtualPackage(pkg); e != nil {
|
||||||
entry = e
|
entry = e
|
||||||
} else {
|
} else {
|
||||||
pkgsNotFound = append(pkgsNotFound, pkg)
|
return nil, fmt.Errorf("could not find package (%s) in any repository", pkg)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if reinstallMethod == ReinstallMethodNone && IsPackageInstalled(entry.Info.Name, rootDir) && GetPackageInfo(entry.Info.Name, rootDir).GetFullVersion() == entry.Info.GetFullVersion() {
|
if reinstallMethod == ReinstallMethodNone && IsPackageInstalled(entry.Info.Name, rootDir) && GetPackageInfo(entry.Info.Name, rootDir).GetFullVersion() == entry.Info.GetFullVersion() {
|
||||||
continue
|
continue
|
||||||
@ -70,11 +67,6 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return error if not all packages are found
|
|
||||||
if len(pkgsNotFound) != 0 {
|
|
||||||
return nil, PackageNotFoundErr{pkgsNotFound}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve dependencies
|
// Resolve dependencies
|
||||||
err = operation.ResolveDependencies(reinstallMethod == ReinstallMethodAll, installOptionalDependencies, verbose)
|
err = operation.ResolveDependencies(reinstallMethod == ReinstallMethodAll, installOptionalDependencies, verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -82,9 +74,9 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
}
|
}
|
||||||
if len(operation.UnresolvedDepends) != 0 {
|
if len(operation.UnresolvedDepends) != 0 {
|
||||||
if !forceInstallation {
|
if !forceInstallation {
|
||||||
return nil, DependencyNotFoundErr{operation.UnresolvedDepends}
|
return nil, fmt.Errorf("dependencies (%s) could not be found in any repositories", strings.Join(operation.UnresolvedDepends, ", "))
|
||||||
} else if verbose {
|
} else if verbose {
|
||||||
log.Printf("Warning: %s", DependencyNotFoundErr{operation.UnresolvedDepends})
|
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(operation.UnresolvedDepends, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,14 +89,15 @@ func InstallPackages(rootDir string, installationReason InstallationReason, rein
|
|||||||
return nil, fmt.Errorf("could not complete package conflict check: %s", err)
|
return nil, fmt.Errorf("could not complete package conflict check: %s", err)
|
||||||
}
|
}
|
||||||
if len(conflicts) > 0 {
|
if len(conflicts) > 0 {
|
||||||
err = nil
|
if verbose {
|
||||||
for pkg, conflict := range conflicts {
|
for pkg, conflict := range conflicts {
|
||||||
err = errors.Join(err, PackageConflictErr{pkg, conflict})
|
fmt.Printf("%s is in conflict with packages (%s)\n", pkg, strings.Join(conflict, ", "))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !forceInstallation {
|
if !forceInstallation {
|
||||||
return nil, err
|
return nil, fmt.Errorf("conflicting packages found")
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Warning: %s", err)
|
log.Println("Warning: conflicting packages found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,10 +172,7 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reload config and local databases
|
// Reload config and local databases
|
||||||
err = ReadConfig()
|
ReadConfig()
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not read BPM config: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get installed packages and check for updates
|
// Get installed packages and check for updates
|
||||||
pkgs, err := GetInstalledPackages(rootDir)
|
pkgs, err := GetInstalledPackages(rootDir)
|
||||||
@ -232,9 +222,9 @@ func UpdatePackages(rootDir string, syncDatabase bool, installOptionalDependenci
|
|||||||
}
|
}
|
||||||
if len(operation.UnresolvedDepends) != 0 {
|
if len(operation.UnresolvedDepends) != 0 {
|
||||||
if !forceInstallation {
|
if !forceInstallation {
|
||||||
return nil, DependencyNotFoundErr{operation.UnresolvedDepends}
|
return nil, fmt.Errorf("dependencies (%s) could not be found in any repositories", strings.Join(operation.UnresolvedDepends, ", "))
|
||||||
} else if verbose {
|
} else if verbose {
|
||||||
log.Printf("Warning: %s", DependencyNotFoundErr{operation.UnresolvedDepends})
|
log.Printf("Warning: dependencies (%s) could not be found in any repositories\n", strings.Join(operation.UnresolvedDepends, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ func (operation *BPMOperation) Cleanup(verbose bool) error {
|
|||||||
// Get all installed packages
|
// Get all installed packages
|
||||||
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not get installed packages: %s", err)
|
log.Fatalf("Error: could not get installed packages: %s\n", err)
|
||||||
}
|
}
|
||||||
installedPackages := make([]*PackageInfo, len(installedPackageNames))
|
installedPackages := make([]*PackageInfo, len(installedPackageNames))
|
||||||
for i, value := range installedPackageNames {
|
for i, value := range installedPackageNames {
|
||||||
@ -329,8 +329,8 @@ func (operation *BPMOperation) CheckForConflicts() (map[string][]string, error)
|
|||||||
|
|
||||||
func (operation *BPMOperation) ShowOperationSummary() {
|
func (operation *BPMOperation) ShowOperationSummary() {
|
||||||
if len(operation.Actions) == 0 {
|
if len(operation.Actions) == 0 {
|
||||||
fmt.Println("No action needs to be taken")
|
fmt.Println("All packages are up to date!")
|
||||||
return
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range operation.Actions {
|
for _, value := range operation.Actions {
|
||||||
@ -348,6 +348,9 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
|||||||
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
||||||
sourceInfo := ""
|
sourceInfo := ""
|
||||||
if pkgInfo.Type == "source" {
|
if pkgInfo.Type == "source" {
|
||||||
|
if operation.RootDir != "/" {
|
||||||
|
log.Fatalf("cannot compile and install source packages to a different root directory")
|
||||||
|
}
|
||||||
sourceInfo = "(From Source)"
|
sourceInfo = "(From Source)"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,9 +468,9 @@ func (operation *BPMOperation) Execute(verbose, force bool) error {
|
|||||||
isReinstall := IsPackageInstalled(bpmpkg.PkgInfo.Name, operation.RootDir)
|
isReinstall := IsPackageInstalled(bpmpkg.PkgInfo.Name, operation.RootDir)
|
||||||
var err error
|
var err error
|
||||||
if value.IsDependency {
|
if value.IsDependency {
|
||||||
err = installPackage(value.File, operation.RootDir, verbose, true)
|
err = installPackage(value.File, operation.RootDir, verbose, true, false, false, false)
|
||||||
} else {
|
} else {
|
||||||
err = installPackage(value.File, operation.RootDir, verbose, force)
|
err = installPackage(value.File, operation.RootDir, verbose, force, false, false, false)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err))
|
return errors.New(fmt.Sprintf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err))
|
||||||
|
@ -8,13 +8,16 @@ import (
|
|||||||
version "github.com/knqyf263/go-rpm-version"
|
version "github.com/knqyf263/go-rpm-version"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BPMPackage struct {
|
type BPMPackage struct {
|
||||||
@ -306,6 +309,11 @@ func executePackageScripts(filename, rootDir string, operation packageOperation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("/bin/bash", temp.Name())
|
cmd := exec.Command("/bin/bash", temp.Name())
|
||||||
|
if !BPMConfig.SilentCompilation {
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
}
|
||||||
cmd.Dir = rootDir
|
cmd.Dir = rootDir
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", rootDir))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", rootDir))
|
||||||
@ -425,6 +433,14 @@ func ReadPackageInfo(contents string) (*PackageInfo, error) {
|
|||||||
return &pkgInfo, nil
|
return &pkgInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateInfoFile(pkgInfo *PackageInfo) string {
|
||||||
|
b, err := yaml.Marshal(&pkgInfo)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, pkgInfo *PackageInfo, rootDir string) string {
|
func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, pkgInfo *PackageInfo, rootDir string) string {
|
||||||
ret := make([]string, 0)
|
ret := make([]string, 0)
|
||||||
appendArray := func(label string, array []string) {
|
appendArray := func(label string, array []string) {
|
||||||
@ -595,7 +611,447 @@ func extractPackage(bpmpkg *BPMPackage, verbose bool, filename, rootDir string)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func installPackage(filename, rootDir string, verbose, force bool) error {
|
func isSplitPackage(filename string) bool {
|
||||||
|
pkgInfo, err := ReadPackage(filename)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if pkgInfo.PkgInfo.Type != "source" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("test $(tar -tf %s | grep '^pkg.info' | wc -l) -eq 1", filename))
|
||||||
|
if err := cmd.Run(); err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func compilePackage(bpmpkg *BPMPackage, filename, rootDir string, verbose, binaryPkgFromSrc, skipCheck, keepTempDir bool) (error, []string) {
|
||||||
|
var files []string
|
||||||
|
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
||||||
|
err := executePackageScripts(filename, rootDir, packageOperationInstall, false)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err := executePackageScripts(filename, rootDir, packageOperationUpdate, false)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//seenHardlinks := make(map[string]string)
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tr := tar.NewReader(file)
|
||||||
|
|
||||||
|
temp := path.Join(BPMConfig.CompilationDir, "bpm_source-"+bpmpkg.PkgInfo.Name)
|
||||||
|
err = os.RemoveAll(temp)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Creating temp directory at: " + temp)
|
||||||
|
}
|
||||||
|
err = os.Mkdir(temp, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(temp, 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
header, err := tr.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(header.Name, "source-files/") && header.Name != "source-files/" {
|
||||||
|
extractFilename := path.Join(temp, strings.TrimPrefix(header.Name, "source-files/"))
|
||||||
|
switch header.Typeflag {
|
||||||
|
case tar.TypeDir:
|
||||||
|
if err := os.Mkdir(extractFilename, 0755); err != nil {
|
||||||
|
if !os.IsExist(err) {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
|
}
|
||||||
|
err = os.Chown(extractFilename, 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case tar.TypeReg:
|
||||||
|
err := os.Remove(extractFilename)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
outFile, err := os.Create(extractFilename)
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Creating File: " + extractFilename)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(extractFilename, 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(outFile, tr); err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
if err := os.Chmod(extractFilename, header.FileInfo().Mode()); err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = outFile.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
case tar.TypeSymlink:
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Skipping symlink (Bundling symlinks in source packages is not supported)")
|
||||||
|
}
|
||||||
|
case tar.TypeLink:
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Skipping hard link (Bundling hard links in source packages is not supported)")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return errors.New("unknown type (" + strconv.Itoa(int(header.Typeflag)) + ") in " + extractFilename), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if header.Name == "source.sh" {
|
||||||
|
bs, err := io.ReadAll(tr)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.WriteFile(path.Join(temp, "source.sh"), bs, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(path.Join(temp, "source.sh"), 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(path.Join(temp, "source.sh")); os.IsNotExist(err) {
|
||||||
|
return errors.New("source.sh file could not be found in the temporary build directory"), nil
|
||||||
|
}
|
||||||
|
fmt.Println("Running source.sh file...")
|
||||||
|
if !IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
||||||
|
err = executePackageScripts(filename, rootDir, packageOperationInstall, false)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = executePackageScripts(filename, rootDir, packageOperationUpdate, false)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bs, err := os.ReadFile(path.Join(temp, "source.sh"))
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(string(bs), "package()") {
|
||||||
|
fmt.Print("This package does not seem to have the required 'package' function\nThe source.sh file may have been created for an older BPM version\nPlease update the source.sh file")
|
||||||
|
return errors.New("invalid source.sh format"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
runScript := `
|
||||||
|
cd "$BPM_WORKDIR"
|
||||||
|
|
||||||
|
set -a
|
||||||
|
source "source.sh"
|
||||||
|
set +a
|
||||||
|
|
||||||
|
if [[ $(type -t prepare) == function ]]; then
|
||||||
|
echo "Running prepare() function..."
|
||||||
|
bash -e -c prepare
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to run prepare() function in source.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$BPM_SOURCE"
|
||||||
|
if [[ $(type -t build) == function ]]; then
|
||||||
|
echo "Running build() function..."
|
||||||
|
bash -e -c build
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to run build() function in source.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$BPM_SOURCE"
|
||||||
|
if [[ $(type -t check) == function ]] && [ -z "$SKIPCHECK" ]; then
|
||||||
|
echo "Running check() function..."
|
||||||
|
bash -e -c check
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to run check() function in source.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
cd "$BPM_SOURCE"
|
||||||
|
if ! [[ $(type -t package) == function ]]; then
|
||||||
|
echo "Failed to locate package() function in source.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Running package() function..."
|
||||||
|
touch "$BPM_WORKDIR"/fakeroot_file
|
||||||
|
fakeroot -s "$BPM_WORKDIR"/fakeroot_file bash -e -c package
|
||||||
|
bash -e -c package
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to run package() function in source.sh"
|
||||||
|
fi
|
||||||
|
`
|
||||||
|
err = os.WriteFile(path.Join(temp, "run.sh"), []byte(runScript), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(path.Join(temp, "run.sh"), 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("/bin/bash", "-e", "run.sh")
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: 65534, Gid: 65534}
|
||||||
|
cmd.Dir = temp
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Env = append(cmd.Env, "USER=nobody")
|
||||||
|
cmd.Env = append(cmd.Env, "HOME="+temp)
|
||||||
|
|
||||||
|
err = os.Mkdir(path.Join(temp, "source"), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(path.Join(temp, "source"), 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Mkdir(path.Join(temp, "output"), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(path.Join(temp, "output"), 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
cmd.Env = append(cmd.Env, "BPM_WORKDIR="+temp)
|
||||||
|
cmd.Env = append(cmd.Env, "BPM_SOURCE="+path.Join(temp, "source"))
|
||||||
|
cmd.Env = append(cmd.Env, "BPM_OUTPUT="+path.Join(temp, "output"))
|
||||||
|
cmd.Env = append(cmd.Env, "SKIPCHECK="+strconv.FormatBool(skipCheck))
|
||||||
|
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", rootDir))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", bpmpkg.PkgInfo.Name))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", bpmpkg.PkgInfo.Description))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", bpmpkg.PkgInfo.Version))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_REVISION=%d", bpmpkg.PkgInfo.Revision))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", bpmpkg.PkgInfo.Url))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", bpmpkg.PkgInfo.Arch))
|
||||||
|
depends := make([]string, len(bpmpkg.PkgInfo.Depends))
|
||||||
|
copy(depends, bpmpkg.PkgInfo.Depends)
|
||||||
|
for i := 0; i < len(depends); i++ {
|
||||||
|
depends[i] = fmt.Sprintf("\"%s\"", depends[i])
|
||||||
|
}
|
||||||
|
makeDepends := make([]string, len(bpmpkg.PkgInfo.MakeDepends))
|
||||||
|
copy(makeDepends, bpmpkg.PkgInfo.MakeDepends)
|
||||||
|
for i := 0; i < len(makeDepends); i++ {
|
||||||
|
makeDepends[i] = fmt.Sprintf("\"%s\"", makeDepends[i])
|
||||||
|
}
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DEPENDS=(%s)", strings.Join(depends, " ")))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_MAKE_DEPENDS=(%s)", strings.Join(makeDepends, " ")))
|
||||||
|
for _, value := range BPMConfig.CompilationEnv {
|
||||||
|
cmd.Env = append(cmd.Env, value)
|
||||||
|
}
|
||||||
|
cmd.Env = append(cmd.Env, "BPM_PKG_TYPE=source")
|
||||||
|
|
||||||
|
if !BPMConfig.SilentCompilation {
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(path.Join(temp, "output/")); err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return errors.New("output directory not be found at " + path.Join(temp, "output/")), nil
|
||||||
|
}
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
if dir, _ := os.ReadDir(path.Join(temp, "output/")); len(dir) == 0 {
|
||||||
|
return errors.New("output directory is empty"), nil
|
||||||
|
}
|
||||||
|
fmt.Println("Copying all files...")
|
||||||
|
err = filepath.WalkDir(path.Join(temp, "/output/"), func(fullpath string, d fs.DirEntry, err error) error {
|
||||||
|
relFilename, err := filepath.Rel(path.Join(temp, "/output/"), fullpath)
|
||||||
|
if relFilename == "." {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
extractFilename := path.Join(rootDir, relFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if d.Type() == os.ModeDir {
|
||||||
|
files = append(files, relFilename+"/")
|
||||||
|
if err := os.Mkdir(extractFilename, 0755); err != nil {
|
||||||
|
if !os.IsExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Creating Directory: " + extractFilename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if d.Type().IsRegular() {
|
||||||
|
if _, err := os.Stat(extractFilename); err == nil {
|
||||||
|
if slices.Contains(bpmpkg.PkgInfo.Keep, relFilename) {
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Skipping File: " + extractFilename + "(File is configured to be kept during installs/updates)")
|
||||||
|
}
|
||||||
|
files = append(files, relFilename)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := os.Remove(extractFilename)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
outFile, err := os.Create(extractFilename)
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Creating File: " + extractFilename)
|
||||||
|
}
|
||||||
|
files = append(files, relFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f, err := os.Open(fullpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(outFile, f); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := os.Stat(fullpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.Chmod(extractFilename, info.Mode()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = outFile.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if d.Type() == os.ModeSymlink {
|
||||||
|
link, err := os.Readlink(fullpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Remove(extractFilename)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
||||||
|
}
|
||||||
|
files = append(files, relFilename)
|
||||||
|
err = os.Symlink(link, extractFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
if binaryPkgFromSrc {
|
||||||
|
compiledDir := path.Join(BPMConfig.BinaryOutputDir)
|
||||||
|
err = os.MkdirAll(compiledDir, 0755)
|
||||||
|
compiledInfo := PackageInfo{}
|
||||||
|
compiledInfo = *bpmpkg.PkgInfo
|
||||||
|
compiledInfo.Type = "binary"
|
||||||
|
compiledInfo.Arch = GetArch()
|
||||||
|
err = os.WriteFile(path.Join(temp, "pkg.info"), []byte(CreateInfoFile(&compiledInfo)), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(path.Join(temp, "pkg.info"), 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
scripts, err := ReadPackageScripts(filename)
|
||||||
|
for key, val := range scripts {
|
||||||
|
err = os.WriteFile(path.Join(temp, key), []byte(val), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(path.Join(temp, key), 65534, 65534)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sed := fmt.Sprintf("s/output/files/")
|
||||||
|
fileName := compiledInfo.Name + "-" + compiledInfo.GetFullVersion() + "-" + compiledInfo.Arch + ".bpm"
|
||||||
|
cmd := exec.Command("/usr/bin/fakeroot", "-i fakeroot_file", "tar", "-czvpf", fileName, "pkg.info", "output/", "--transform", sed)
|
||||||
|
if !BPMConfig.SilentCompilation {
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
}
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: 65534, Gid: 65534}
|
||||||
|
cmd.Dir = temp
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
fmt.Printf("running command: %s\n", strings.Join(cmd.Args, " "))
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = copyFileContents(path.Join(temp, fileName), path.Join(compiledDir, fileName))
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
err = os.Chown(path.Join(compiledDir, fileName), 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !keepTempDir {
|
||||||
|
err := os.RemoveAll(temp)
|
||||||
|
if err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(files) == 0 {
|
||||||
|
return errors.New("no output files for source package. Cancelling package installation"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
return nil, files
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
@ -714,7 +1170,13 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if bpmpkg.PkgInfo.Type == "source" {
|
} else if bpmpkg.PkgInfo.Type == "source" {
|
||||||
return errors.New("direct source package compilation in BPM has been temporarily removed and is being reworked on")
|
if isSplitPackage(filename) {
|
||||||
|
return errors.New("BPM is unable to install split source packages")
|
||||||
|
}
|
||||||
|
err, _ := compilePackage(bpmpkg, filename, rootDir, verbose, binaryPkgFromSrc, skipCheck, keepTempDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return errors.New("unknown package type: " + bpmpkg.PkgInfo.Type)
|
return errors.New("unknown package type: " + bpmpkg.PkgInfo.Type)
|
||||||
}
|
}
|
||||||
@ -846,21 +1308,8 @@ func (pkgInfo *PackageInfo) GetDependants(rootDir string) ([]string, error) {
|
|||||||
if bpmpkg == nil {
|
if bpmpkg == nil {
|
||||||
return nil, errors.New("package not found: " + pkg)
|
return nil, errors.New("package not found: " + pkg)
|
||||||
}
|
}
|
||||||
if bpmpkg.PkgInfo.Name == pkgInfo.Name {
|
if bpmpkg.PkgInfo.Name != pkgInfo.Name && slices.Contains(bpmpkg.PkgInfo.GetAllDependencies(false, true), pkgInfo.Name) {
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies := bpmpkg.PkgInfo.GetAllDependencies(false, true)
|
|
||||||
|
|
||||||
if slices.Contains(dependencies, pkgInfo.Name) {
|
|
||||||
ret = append(ret, pkg)
|
ret = append(ret, pkg)
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, vpkg := range pkgInfo.Provides {
|
|
||||||
if slices.Contains(dependencies, vpkg) {
|
|
||||||
ret = append(ret, pkg)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1187,6 +1636,11 @@ func removePackage(pkg string, verbose bool, rootDir string) error {
|
|||||||
// Executing post_remove script
|
// Executing post_remove script
|
||||||
if _, err := os.Stat(path.Join(pkgDir, "post_remove.sh")); err == nil {
|
if _, err := os.Stat(path.Join(pkgDir, "post_remove.sh")); err == nil {
|
||||||
cmd := exec.Command("/bin/bash", path.Join(pkgDir, "post_remove.sh"))
|
cmd := exec.Command("/bin/bash", path.Join(pkgDir, "post_remove.sh"))
|
||||||
|
if !BPMConfig.SilentCompilation {
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
}
|
||||||
cmd.Dir = rootDir
|
cmd.Dir = rootDir
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", rootDir))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_ROOT=%s", rootDir))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user