mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-26 23:46:12 +00:00
Compare commits
2
Commits
a7c03c272e
...
5909370407
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5909370407
|
||
|
|
5a78fd3002
|
@@ -1,4 +1,5 @@
|
|||||||
ignore_packages: []
|
ignore_packages: []
|
||||||
|
show_source_package_contents: always
|
||||||
cleanup_make_dependencies: true
|
cleanup_make_dependencies: true
|
||||||
databases:
|
databases:
|
||||||
- name: example-database
|
- name: example-database
|
||||||
|
|||||||
@@ -446,6 +446,37 @@ func installPackages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch packages
|
||||||
|
err = operation.FetchPackages()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error: could not fetch packages for operation: %s\n", err)
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if bpmlib.MainBPMConfig.ShowSourcePackageContents == "always" || bpmlib.MainBPMConfig.ShowSourcePackageContents == "install-only" {
|
||||||
|
// Show source package contents
|
||||||
|
sourcePackagesShown, err := operation.ShowSourcePackageContent()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error: could not show source package content: %s\n", err)
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirmation Prompt
|
||||||
|
if sourcePackagesShown > 0 && !yesAll {
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
fmt.Printf("Are you sure you wish to continue? [y\\N] ")
|
||||||
|
|
||||||
|
text, _ := reader.ReadString('\n')
|
||||||
|
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||||
|
fmt.Println("Cancelling package installation...")
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute operation
|
// Execute operation
|
||||||
err = operation.Execute(verbose, force)
|
err = operation.Execute(verbose, force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -771,6 +802,37 @@ func updatePackages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch packages
|
||||||
|
err = operation.FetchPackages()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error: could not fetch packages for operation: %s\n", err)
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if bpmlib.MainBPMConfig.ShowSourcePackageContents == "always" {
|
||||||
|
// Show source package contents
|
||||||
|
sourcePackagesShown, err := operation.ShowSourcePackageContent()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error: could not show source package content: %s\n", err)
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirmation Prompt
|
||||||
|
if sourcePackagesShown > 0 && !yesAll {
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
fmt.Printf("Are you sure you wish to continue? [y\\N] ")
|
||||||
|
|
||||||
|
text, _ := reader.ReadString('\n')
|
||||||
|
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||||
|
fmt.Println("Cancelling package installation...")
|
||||||
|
exitCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute operation
|
// Execute operation
|
||||||
err = operation.Execute(verbose, force)
|
err = operation.Execute(verbose, force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -515,3 +515,75 @@ func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showPackageFiles(archiveFilename string) error {
|
||||||
|
// Read BPM archive
|
||||||
|
bpmpkg, err := ReadPackage(archiveFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure package type is 'source'
|
||||||
|
if bpmpkg.PkgInfo.Type != "source" {
|
||||||
|
return fmt.Errorf("cannot compile a non-source package")
|
||||||
|
}
|
||||||
|
|
||||||
|
printTarballContent := func(filename string) error {
|
||||||
|
// Get tarball reader for file
|
||||||
|
reader, err := readTarballFile(archiveFilename, filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read file content
|
||||||
|
data, err := io.ReadAll(reader.tarReader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print file name and content
|
||||||
|
fmt.Println("==============================")
|
||||||
|
fmt.Printf("%s: %s\n", bpmpkg.PkgInfo.Name, filename)
|
||||||
|
fmt.Println("==============================")
|
||||||
|
fmt.Printf("%s\n", data)
|
||||||
|
|
||||||
|
// Close reader
|
||||||
|
err = reader.file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print pkg.info content
|
||||||
|
err = printTarballContent("pkg.info")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print source files contents
|
||||||
|
files, err := listTarballContent(archiveFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
if !strings.HasPrefix(file, "source-files/") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print source file content
|
||||||
|
err = printTarballContent(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print source.sh content
|
||||||
|
err = printTarballContent("source.sh")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
type MainBPMConfigStruct struct {
|
type MainBPMConfigStruct struct {
|
||||||
IgnorePackages []string `yaml:"ignore_packages"`
|
IgnorePackages []string `yaml:"ignore_packages"`
|
||||||
|
ShowSourcePackageContents string `yaml:"show_source_package_contents"`
|
||||||
CleanupMakeDependencies bool `yaml:"cleanup_make_dependencies"`
|
CleanupMakeDependencies bool `yaml:"cleanup_make_dependencies"`
|
||||||
Databases []configDatabase `yaml:"databases"`
|
Databases []configDatabase `yaml:"databases"`
|
||||||
}
|
}
|
||||||
@@ -31,6 +32,7 @@ func ReadConfig() (err error) {
|
|||||||
|
|
||||||
// Set default config options
|
// Set default config options
|
||||||
MainBPMConfig = MainBPMConfigStruct{
|
MainBPMConfig = MainBPMConfigStruct{
|
||||||
|
ShowSourcePackageContents: "always",
|
||||||
CleanupMakeDependencies: true,
|
CleanupMakeDependencies: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+62
-16
@@ -8,6 +8,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BPMOperation struct {
|
type BPMOperation struct {
|
||||||
@@ -15,7 +16,9 @@ type BPMOperation struct {
|
|||||||
UnresolvedDepends []string
|
UnresolvedDepends []string
|
||||||
Changes map[string]string
|
Changes map[string]string
|
||||||
RootDir string
|
RootDir string
|
||||||
|
|
||||||
compiledPackages map[string]string
|
compiledPackages map[string]string
|
||||||
|
hasFetchedPackages bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) ActionsContainPackage(pkg string) bool {
|
func (operation *BPMOperation) ActionsContainPackage(pkg string) bool {
|
||||||
@@ -333,6 +336,9 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer := tabwriter.NewWriter(os.Stdout, 6, 4, 6, ' ', 0)
|
||||||
|
fmt.Fprintln(writer, "Name\tVersion\tAction\tInstallation Reason\tFrom Source")
|
||||||
|
|
||||||
for _, value := range operation.Actions {
|
for _, value := range operation.Actions {
|
||||||
var pkgInfo *PackageInfo
|
var pkgInfo *PackageInfo
|
||||||
var installationReason = InstallationReasonUnknown
|
var installationReason = InstallationReasonUnknown
|
||||||
@@ -347,41 +353,40 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
|||||||
pkgInfo = value.(*FetchPackageAction).DatabaseEntry.Info
|
pkgInfo = value.(*FetchPackageAction).DatabaseEntry.Info
|
||||||
} else {
|
} else {
|
||||||
pkgInfo = value.(*RemovePackageAction).BpmPackage.PkgInfo
|
pkgInfo = value.(*RemovePackageAction).BpmPackage.PkgInfo
|
||||||
fmt.Printf("%s: %s (Remove)\n", pkgInfo.Name, pkgInfo.GetFullVersion())
|
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Remove", "-", "-")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
installationReasonStr := ""
|
||||||
additionalInfo := ""
|
|
||||||
switch installationReason {
|
switch installationReason {
|
||||||
case InstallationReasonManual:
|
case InstallationReasonManual:
|
||||||
additionalInfo = "(Manual)"
|
installationReasonStr = "Manual"
|
||||||
case InstallationReasonDependency:
|
case InstallationReasonDependency:
|
||||||
additionalInfo = "(Dependency)"
|
installationReasonStr = "Dependency"
|
||||||
case InstallationReasonMakeDependency:
|
case InstallationReasonMakeDependency:
|
||||||
additionalInfo = "(Make dependency)"
|
installationReasonStr = "Make dependency"
|
||||||
default:
|
default:
|
||||||
additionalInfo = "(Unknown)"
|
installationReasonStr = "Unknown"
|
||||||
}
|
|
||||||
|
|
||||||
if pkgInfo.Type == "source" {
|
|
||||||
additionalInfo += " (From Source)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
||||||
if installedInfo == nil {
|
if installedInfo == nil {
|
||||||
fmt.Printf("%s: %s (Install) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), additionalInfo)
|
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%t\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Install", installationReasonStr, pkgInfo.Type == "source")
|
||||||
} else {
|
} else {
|
||||||
comparison := ComparePackageVersions(*pkgInfo, *installedInfo)
|
comparison := ComparePackageVersions(*pkgInfo, *installedInfo)
|
||||||
if comparison < 0 {
|
if comparison < 0 {
|
||||||
fmt.Printf("%s: %s -> %s (Downgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), additionalInfo)
|
fmt.Fprintf(writer, "%s\t%s -> %s\t%s\t%s\t%t\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), "Downgrade", installationReasonStr, pkgInfo.Type == "source")
|
||||||
} else if comparison > 0 {
|
} else if comparison > 0 {
|
||||||
fmt.Printf("%s: %s -> %s (Upgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), additionalInfo)
|
fmt.Fprintf(writer, "%s\t%s -> %s\t%s\t%s\t%t\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), "Upgrade", installationReasonStr, pkgInfo.Type == "source")
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s: %s (Reinstall) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), additionalInfo)
|
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%t\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Reinstall", installationReasonStr, pkgInfo.Type == "source")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
if operation.RootDir != "/" {
|
if operation.RootDir != "/" {
|
||||||
fmt.Println("Warning: Operating in " + operation.RootDir)
|
fmt.Println("Warning: Operating in " + operation.RootDir)
|
||||||
}
|
}
|
||||||
@@ -395,6 +400,34 @@ func (operation *BPMOperation) ShowOperationSummary() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) ShowSourcePackageContent() (sourcePackagesShown int, err error) {
|
||||||
|
// Fetch packages
|
||||||
|
if !operation.hasFetchedPackages {
|
||||||
|
err = operation.FetchPackages()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
if action.GetActionType() != "install" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if action.(*InstallPackageAction).BpmPackage.PkgInfo.Type != "source" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = showPackageFiles(action.(*InstallPackageAction).File)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcePackagesShown++
|
||||||
|
}
|
||||||
|
|
||||||
|
return sourcePackagesShown, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) RunHooks(verbose bool) error {
|
func (operation *BPMOperation) RunHooks(verbose bool) error {
|
||||||
// Return if hooks directory does not exist
|
// Return if hooks directory does not exist
|
||||||
if stat, err := os.Stat(path.Join(operation.RootDir, "var/lib/bpm/hooks")); err != nil || !stat.IsDir() {
|
if stat, err := os.Stat(path.Join(operation.RootDir, "var/lib/bpm/hooks")); err != nil || !stat.IsDir() {
|
||||||
@@ -426,7 +459,7 @@ func (operation *BPMOperation) RunHooks(verbose bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
func (operation *BPMOperation) FetchPackages() (err error) {
|
||||||
// Fetch packages from databases
|
// Fetch packages from databases
|
||||||
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
||||||
return action.GetActionType() == "fetch"
|
return action.GetActionType() == "fetch"
|
||||||
@@ -492,6 +525,19 @@ func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operation.hasFetchedPackages = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||||
|
// Fetch packages
|
||||||
|
if !operation.hasFetchedPackages {
|
||||||
|
err = operation.FetchPackages()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Determine words to be used for the following message
|
// Determine words to be used for the following message
|
||||||
words := make([]string, 0)
|
words := make([]string, 0)
|
||||||
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user