Finalize remote repositories functionality #6
133
main.go
133
main.go
@ -18,7 +18,7 @@ import (
|
|||||||
/* A simple-to-use package manager */
|
/* A simple-to-use package manager */
|
||||||
/* ---------------------------------- */
|
/* ---------------------------------- */
|
||||||
|
|
||||||
var bpmVer = "0.4"
|
var bpmVer = "0.4.1"
|
||||||
|
|
||||||
var subcommand = "help"
|
var subcommand = "help"
|
||||||
var subcommandArgs []string
|
var subcommandArgs []string
|
||||||
@ -99,7 +99,7 @@ func resolveCommand() {
|
|||||||
var info *utils.PackageInfo
|
var info *utils.PackageInfo
|
||||||
info = utils.GetPackageInfo(pkg, rootDir, false)
|
info = utils.GetPackageInfo(pkg, rootDir, false)
|
||||||
if info == nil {
|
if info == nil {
|
||||||
log.Fatalf("Package (%s) is not installed\n", pkg)
|
log.Fatalf("Error: package (%s) is not installed\n", pkg)
|
||||||
}
|
}
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
fmt.Println(utils.CreateReadableInfo(true, true, true, info, rootDir))
|
fmt.Println(utils.CreateReadableInfo(true, true, true, info, rootDir))
|
||||||
@ -110,7 +110,7 @@ func resolveCommand() {
|
|||||||
case list:
|
case list:
|
||||||
packages, err := 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("Error: could not get installed packages: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if pkgListNumbers {
|
if pkgListNumbers {
|
||||||
@ -139,8 +139,7 @@ func resolveCommand() {
|
|||||||
case search:
|
case search:
|
||||||
searchTerms := subcommandArgs
|
searchTerms := subcommandArgs
|
||||||
if len(searchTerms) == 0 {
|
if len(searchTerms) == 0 {
|
||||||
fmt.Println("No search terms given")
|
log.Fatalf("Error: no search terms given")
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, term := range searchTerms {
|
for _, term := range searchTerms {
|
||||||
@ -157,18 +156,17 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
results := append(nameResults, descResults...)
|
results := append(nameResults, descResults...)
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
log.Fatalf("No results for term (%s) were found\n", term)
|
log.Fatalf("Error: no results for term (%s) were found\n", term)
|
||||||
}
|
}
|
||||||
fmt.Printf("Results for term (%s)\n", term)
|
fmt.Printf("Results for term (%s)\n", term)
|
||||||
for i, result := range results {
|
for i, result := range results {
|
||||||
fmt.Println("----------------")
|
fmt.Println("----------------")
|
||||||
fmt.Printf("%d) %s: %s (%s)\n", i+1, result.Name, result.Description, result.Version)
|
fmt.Printf("%d) %s: %s (%s)\n", i+1, result.Name, result.Description, result.GetFullVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case install:
|
case install:
|
||||||
if os.Getuid() != 0 {
|
if os.Getuid() != 0 {
|
||||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
pkgs := subcommandArgs
|
pkgs := subcommandArgs
|
||||||
if len(pkgs) == 0 {
|
if len(pkgs) == 0 {
|
||||||
@ -189,9 +187,9 @@ func resolveCommand() {
|
|||||||
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
|
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
|
||||||
pkgInfo, err := utils.ReadPackage(pkg)
|
pkgInfo, err := utils.ReadPackage(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not read package. Error: %s\n", err)
|
log.Fatalf("Error: could not read package: %s\n", err)
|
||||||
}
|
}
|
||||||
if !reinstall && utils.IsPackageInstalled(pkgInfo.Name, rootDir) && utils.GetPackageInfo(pkgInfo.Name, rootDir, true).Version == pkgInfo.Version {
|
if !reinstall && utils.IsPackageInstalled(pkgInfo.Name, rootDir) && utils.GetPackageInfo(pkgInfo.Name, rootDir, true).GetFullVersion() == pkgInfo.GetFullVersion() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pkgsToInstall.Set(pkgInfo.Name, &struct {
|
pkgsToInstall.Set(pkgInfo.Name, &struct {
|
||||||
@ -203,9 +201,9 @@ func resolveCommand() {
|
|||||||
} else {
|
} else {
|
||||||
entry, _, err := utils.GetRepositoryEntry(pkg)
|
entry, _, err := utils.GetRepositoryEntry(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
log.Fatalf("Error: could not find package (%s) in any repository\n", pkg)
|
||||||
}
|
}
|
||||||
if !reinstall && utils.IsPackageInstalled(entry.Info.Name, rootDir) && utils.GetPackageInfo(entry.Info.Name, rootDir, true).Version == entry.Info.Version {
|
if !reinstall && utils.IsPackageInstalled(entry.Info.Name, rootDir) && utils.GetPackageInfo(entry.Info.Name, rootDir, true).GetFullVersion() == entry.Info.GetFullVersion() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pkgsToInstall.Set(entry.Info.Name, &struct {
|
pkgsToInstall.Set(entry.Info.Name, &struct {
|
||||||
@ -226,7 +224,7 @@ func resolveCommand() {
|
|||||||
}]()
|
}]()
|
||||||
for _, pkg := range clone.Keys() {
|
for _, pkg := range clone.Keys() {
|
||||||
value, _ := clone.Get(pkg)
|
value, _ := clone.Get(pkg)
|
||||||
resolved, unresolved := value.pkgInfo.ResolveAll(&[]string{}, &[]string{}, false, !noOptional, !reinstall, rootDir)
|
resolved, unresolved := value.pkgInfo.ResolveAll(&[]string{}, &[]string{}, value.pkgInfo.Type == "source", !noOptional, !reinstall, rootDir)
|
||||||
unresolvedDepends = append(unresolvedDepends, unresolved...)
|
unresolvedDepends = append(unresolvedDepends, unresolved...)
|
||||||
for _, depend := range resolved {
|
for _, depend := range resolved {
|
||||||
if _, ok := pkgsToInstall.Get(depend); !ok && depend != value.pkgInfo.Name {
|
if _, ok := pkgsToInstall.Get(depend); !ok && depend != value.pkgInfo.Name {
|
||||||
@ -235,7 +233,7 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
entry, _, err := utils.GetRepositoryEntry(depend)
|
entry, _, err := utils.GetRepositoryEntry(depend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
log.Fatalf("Error: could not find package (%s) in any repository\n", pkg)
|
||||||
}
|
}
|
||||||
pkgsToInstall.Set(depend, &struct {
|
pkgsToInstall.Set(depend, &struct {
|
||||||
bpmFile string
|
bpmFile string
|
||||||
@ -251,7 +249,7 @@ func resolveCommand() {
|
|||||||
// Show summary
|
// Show summary
|
||||||
if len(unresolvedDepends) != 0 {
|
if len(unresolvedDepends) != 0 {
|
||||||
if !force {
|
if !force {
|
||||||
log.Fatalf("The following dependencies could not be found in any repositories: %s\n", strings.Join(unresolvedDepends, ", "))
|
log.Fatalf("Error: the following dependencies could not be found in any repositories: %s\n", strings.Join(unresolvedDepends, ", "))
|
||||||
} else {
|
} else {
|
||||||
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(unresolvedDepends, ", "))
|
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(unresolvedDepends, ", "))
|
||||||
}
|
}
|
||||||
@ -265,14 +263,21 @@ func resolveCommand() {
|
|||||||
value, _ := pkgsToInstall.Get(pkg)
|
value, _ := pkgsToInstall.Get(pkg)
|
||||||
pkgInfo := value.pkgInfo
|
pkgInfo := value.pkgInfo
|
||||||
installedInfo := utils.GetPackageInfo(pkgInfo.Name, rootDir, false)
|
installedInfo := utils.GetPackageInfo(pkgInfo.Name, rootDir, false)
|
||||||
|
sourceInfo := ""
|
||||||
|
if pkgInfo.Type == "source" {
|
||||||
|
if rootDir != "/" && !force {
|
||||||
|
log.Fatalf("Error: cannot compile and install source packages to a different root directory")
|
||||||
|
}
|
||||||
|
sourceInfo = "(From Source)"
|
||||||
|
}
|
||||||
if installedInfo == nil {
|
if installedInfo == nil {
|
||||||
fmt.Printf("%s: %s (Install)\n", pkgInfo.Name, pkgInfo.Version)
|
fmt.Printf("%s: %s (Install) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo)
|
||||||
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) < 0 {
|
} else if strings.Compare(pkgInfo.GetFullVersion(), installedInfo.GetFullVersion()) < 0 {
|
||||||
fmt.Printf("%s: %s -> %s (Downgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version)
|
fmt.Printf("%s: %s -> %s (Downgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo)
|
||||||
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 {
|
} else if strings.Compare(pkgInfo.GetFullVersion(), installedInfo.GetFullVersion()) > 0 {
|
||||||
fmt.Printf("%s: %s -> %s (Upgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version)
|
fmt.Printf("%s: %s -> %s (Upgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s: %s (Reinstall)\n", pkgInfo.Name, pkgInfo.Version)
|
fmt.Printf("%s: %s (Reinstall) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rootDir != "/" {
|
if rootDir != "/" {
|
||||||
@ -280,7 +285,12 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
if pkgsToInstall.Len() == 1 {
|
||||||
|
fmt.Printf("Do you wish to install this package? [y\\N] ")
|
||||||
|
} else {
|
||||||
fmt.Printf("Do you wish to install these %d packages? [y\\N] ", pkgsToInstall.Len())
|
fmt.Printf("Do you wish to install these %d packages? [y\\N] ", pkgsToInstall.Len())
|
||||||
|
}
|
||||||
|
|
||||||
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.Println("Cancelling...")
|
fmt.Println("Cancelling...")
|
||||||
@ -297,12 +307,13 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
entry, repo, err := utils.GetRepositoryEntry(pkg)
|
entry, repo, err := utils.GetRepositoryEntry(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
log.Fatalf("Error: could not find package (%s) in any repository\n", pkg)
|
||||||
}
|
}
|
||||||
fetchedPackage, err := repo.FetchPackage(entry.Info.Name)
|
fetchedPackage, err := repo.FetchPackage(entry.Info.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not fetch package (%s). Error: %s\n", pkg, err)
|
log.Fatalf("Error: could not fetch package (%s): %s\n", pkg, err)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Package (%s) was successfully fetched!\n", value.pkgInfo.Name)
|
||||||
value.bpmFile = fetchedPackage
|
value.bpmFile = fetchedPackage
|
||||||
pkgsToInstall.Set(pkg, value)
|
pkgsToInstall.Set(pkg, value)
|
||||||
}
|
}
|
||||||
@ -322,13 +333,13 @@ func resolveCommand() {
|
|||||||
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 (%s). Error: %s\n", pkg, err)
|
log.Fatalf("Error: could not install package (%s): %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 {
|
if value.isDependency {
|
||||||
err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir)
|
err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not set installation reason for package\nError: %s\n", err)
|
log.Fatalf("Error: could not set installation reason for package: %s\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pkgInfo.Type == "source" && keepTempDir {
|
if pkgInfo.Type == "source" && keepTempDir {
|
||||||
@ -337,8 +348,7 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
case update:
|
case update:
|
||||||
if os.Getuid() != 0 {
|
if os.Getuid() != 0 {
|
||||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync repositories
|
// Sync repositories
|
||||||
@ -347,7 +357,7 @@ func resolveCommand() {
|
|||||||
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
||||||
err := repo.SyncLocalDatabase()
|
err := repo.SyncLocalDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Error: could not sync local database for repository (%s): %s\n", repo.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("All package databases synced successfully!")
|
fmt.Println("All package databases synced successfully!")
|
||||||
@ -358,7 +368,7 @@ func resolveCommand() {
|
|||||||
// Get installed packages and check for updates
|
// Get installed packages and check for updates
|
||||||
pkgs, err := utils.GetInstalledPackages(rootDir)
|
pkgs, err := utils.GetInstalledPackages(rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not get installed packages! Error: %s\n", err)
|
log.Fatalf("Error: could not get installed packages: %s\n", err)
|
||||||
}
|
}
|
||||||
toUpdate := orderedmap.NewOrderedMap[string, *struct {
|
toUpdate := orderedmap.NewOrderedMap[string, *struct {
|
||||||
isDependency bool
|
isDependency bool
|
||||||
@ -371,9 +381,9 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
installedInfo := utils.GetPackageInfo(pkg, rootDir, true)
|
installedInfo := utils.GetPackageInfo(pkg, rootDir, true)
|
||||||
if installedInfo == nil {
|
if installedInfo == nil {
|
||||||
log.Fatalf(pkg)
|
log.Fatalf("Error: could not get package info for (%s)\n", pkg)
|
||||||
}
|
}
|
||||||
if strings.Compare(entry.Info.Version, installedInfo.Version) > 0 {
|
if strings.Compare(entry.Info.GetFullVersion(), installedInfo.GetFullVersion()) > 0 {
|
||||||
toUpdate.Set(entry.Info.Name, &struct {
|
toUpdate.Set(entry.Info.Name, &struct {
|
||||||
isDependency bool
|
isDependency bool
|
||||||
entry *utils.RepositoryEntry
|
entry *utils.RepositoryEntry
|
||||||
@ -395,13 +405,13 @@ func resolveCommand() {
|
|||||||
clone := toUpdate.Copy()
|
clone := toUpdate.Copy()
|
||||||
for _, key := range clone.Keys() {
|
for _, key := range clone.Keys() {
|
||||||
pkg, _ := clone.Get(key)
|
pkg, _ := clone.Get(key)
|
||||||
r, u := pkg.entry.Info.ResolveAll(&[]string{}, &[]string{}, false, !noOptional, true, rootDir)
|
r, u := pkg.entry.Info.ResolveAll(&[]string{}, &[]string{}, pkg.entry.Info.Type == "source", !noOptional, true, rootDir)
|
||||||
unresolved = append(unresolved, u...)
|
unresolved = append(unresolved, u...)
|
||||||
for _, depend := range r {
|
for _, depend := range r {
|
||||||
if _, ok := toUpdate.Get(depend); !ok {
|
if _, ok := toUpdate.Get(depend); !ok {
|
||||||
entry, _, err := utils.GetRepositoryEntry(depend)
|
entry, _, err := utils.GetRepositoryEntry(depend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not find package (%s) in any repository\n", depend)
|
log.Fatalf("Error: could not find package (%s) in any repository\n", depend)
|
||||||
}
|
}
|
||||||
toUpdate.Set(depend, &struct {
|
toUpdate.Set(depend, &struct {
|
||||||
isDependency bool
|
isDependency bool
|
||||||
@ -413,23 +423,27 @@ func resolveCommand() {
|
|||||||
|
|
||||||
if len(unresolved) != 0 {
|
if len(unresolved) != 0 {
|
||||||
if !force {
|
if !force {
|
||||||
log.Fatalf("The following dependencies could not be found in any repositories: %s\n", strings.Join(unresolved, ", "))
|
log.Fatalf("Error: the following dependencies could not be found in any repositories: %s\n", strings.Join(unresolved, ", "))
|
||||||
} else {
|
} else {
|
||||||
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(unresolved, ", "))
|
log.Printf("Warning: the following dependencies could not be found in any repositories: %s\n", strings.Join(unresolved, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range toUpdate.Keys() {
|
for _, key := range toUpdate.Keys() {
|
||||||
value, _ := toUpdate.Get(key)
|
value, _ := toUpdate.Get(key)
|
||||||
installedInfo := utils.GetPackageInfo(value.entry.Info.Name, rootDir, true)
|
installedInfo := utils.GetPackageInfo(value.entry.Info.Name, rootDir, true)
|
||||||
|
sourceInfo := ""
|
||||||
|
if value.entry.Info.Type == "source" {
|
||||||
|
sourceInfo = "(From Source)"
|
||||||
|
}
|
||||||
if installedInfo == nil {
|
if installedInfo == nil {
|
||||||
fmt.Printf("%s: %s (Install)\n", value.entry.Info.Name, value.entry.Info.Version)
|
fmt.Printf("%s: %s (Install) %s\n", value.entry.Info.Name, value.entry.Info.GetFullVersion(), sourceInfo)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.Compare(value.entry.Info.Version, installedInfo.Version) > 0 {
|
if strings.Compare(value.entry.Info.GetFullVersion(), installedInfo.GetFullVersion()) > 0 {
|
||||||
fmt.Printf("%s: %s -> %s (Upgrade)\n", value.entry.Info.Name, installedInfo.Version, value.entry.Info.Version)
|
fmt.Printf("%s: %s -> %s (Upgrade) %s\n", value.entry.Info.Name, installedInfo.GetFullVersion(), value.entry.Info.GetFullVersion(), sourceInfo)
|
||||||
} else if reinstall {
|
} else if reinstall {
|
||||||
fmt.Printf("%s: %s -> %s (Reinstall)\n", value.entry.Info.Name, installedInfo.Version, value.entry.Info.Version)
|
fmt.Printf("%s: %s -> %s (Reinstall) %s\n", value.entry.Info.Name, installedInfo.GetFullVersion(), value.entry.Info.GetFullVersion(), sourceInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +454,7 @@ func resolveCommand() {
|
|||||||
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.Println("Cancelling update...")
|
fmt.Println("Cancelling update...")
|
||||||
os.Exit(0)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,16 +465,17 @@ func resolveCommand() {
|
|||||||
}]()
|
}]()
|
||||||
fmt.Println("Fetching packages from available repositories...")
|
fmt.Println("Fetching packages from available repositories...")
|
||||||
for _, pkg := range toUpdate.Keys() {
|
for _, pkg := range toUpdate.Keys() {
|
||||||
isDependency, _ := toUpdate.Get(pkg)
|
value, _ := toUpdate.Get(pkg)
|
||||||
entry, repo, err := utils.GetRepositoryEntry(pkg)
|
entry, repo, err := utils.GetRepositoryEntry(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not find package (%s) in any repository\n", pkg)
|
log.Fatalf("Error: could not find package (%s) in any repository\n", pkg)
|
||||||
}
|
}
|
||||||
fetchedPackage, err := repo.FetchPackage(entry.Info.Name)
|
fetchedPackage, err := repo.FetchPackage(entry.Info.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not fetch package (%s). Error: %s\n", pkg, err)
|
log.Fatalf("Error: could not fetch package (%s): %s\n", pkg, err)
|
||||||
}
|
}
|
||||||
pkgsToInstall.Set(fetchedPackage, isDependency)
|
fmt.Printf("Package (%s) was successfully fetched!\n", value.entry.Info.Name)
|
||||||
|
pkgsToInstall.Set(fetchedPackage, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install fetched packages
|
// Install fetched packages
|
||||||
@ -478,13 +493,13 @@ func resolveCommand() {
|
|||||||
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 (%s). Error: %s\n", pkg, err)
|
log.Fatalf("Error: could not install package (%s): %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 {
|
if value.isDependency {
|
||||||
err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir)
|
err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not set installation reason for package\nError: %s\n", err)
|
log.Fatalf("Error: could not set installation reason for package: %s\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pkgInfo.Type == "source" && keepTempDir {
|
if pkgInfo.Type == "source" && keepTempDir {
|
||||||
@ -493,8 +508,7 @@ func resolveCommand() {
|
|||||||
}
|
}
|
||||||
case sync:
|
case sync:
|
||||||
if os.Getuid() != 0 {
|
if os.Getuid() != 0 {
|
||||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
if !yesAll {
|
if !yesAll {
|
||||||
fmt.Printf("Are you sure you wish to sync all databases? [y\\N] ")
|
fmt.Printf("Are you sure you wish to sync all databases? [y\\N] ")
|
||||||
@ -502,21 +516,20 @@ func resolveCommand() {
|
|||||||
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.Println("Cancelling sync...")
|
fmt.Println("Cancelling sync...")
|
||||||
os.Exit(0)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, repo := range utils.BPMConfig.Repositories {
|
for _, repo := range utils.BPMConfig.Repositories {
|
||||||
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
||||||
err := repo.SyncLocalDatabase()
|
err := repo.SyncLocalDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Error: could not sync local database for repository (%s): %s\n", repo.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("All package databases synced successfully!")
|
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")
|
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
packages := subcommandArgs
|
packages := subcommandArgs
|
||||||
if len(packages) == 0 {
|
if len(packages) == 0 {
|
||||||
@ -546,7 +559,7 @@ func resolveCommand() {
|
|||||||
err := utils.RemovePackage(pkg, verbose, 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("Error: could not remove package: %s\n", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
|
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
|
||||||
}
|
}
|
||||||
@ -559,23 +572,23 @@ func resolveCommand() {
|
|||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
absFile, err := filepath.Abs(file)
|
absFile, err := filepath.Abs(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not get absolute path of %s", file)
|
log.Fatalf("Error: could not get absolute path of file (%s)\n", file)
|
||||||
}
|
}
|
||||||
stat, err := os.Stat(absFile)
|
stat, err := os.Stat(absFile)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log.Fatalf(absFile + " does not exist!")
|
log.Fatalf("Error: file (%s) does not exist!\n", absFile)
|
||||||
}
|
}
|
||||||
pkgs, err := 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("Error: could not get installed packages: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(absFile, rootDir) {
|
if !strings.HasPrefix(absFile, rootDir) {
|
||||||
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
log.Fatalf("Error: could not get path of file (%s) relative to root path", absFile)
|
||||||
}
|
}
|
||||||
absFile, err = filepath.Rel(rootDir, absFile)
|
absFile, err = filepath.Rel(rootDir, absFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
log.Fatalf("Error: could not get path of file (%s) relative to root path", absFile)
|
||||||
}
|
}
|
||||||
absFile = strings.TrimPrefix(absFile, "/")
|
absFile = strings.TrimPrefix(absFile, "/")
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
|
@ -23,6 +23,7 @@ type PackageInfo struct {
|
|||||||
Name string `yaml:"name,omitempty"`
|
Name string `yaml:"name,omitempty"`
|
||||||
Description string `yaml:"description,omitempty"`
|
Description string `yaml:"description,omitempty"`
|
||||||
Version string `yaml:"version,omitempty"`
|
Version string `yaml:"version,omitempty"`
|
||||||
|
Revision int `yaml:"revision,omitempty"`
|
||||||
Url string `yaml:"url,omitempty"`
|
Url string `yaml:"url,omitempty"`
|
||||||
License string `yaml:"license,omitempty"`
|
License string `yaml:"license,omitempty"`
|
||||||
Arch string `yaml:"architecture,omitempty"`
|
Arch string `yaml:"architecture,omitempty"`
|
||||||
@ -35,6 +36,10 @@ type PackageInfo struct {
|
|||||||
Provides []string `yaml:"provides,omitempty"`
|
Provides []string `yaml:"provides,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pkgInfo *PackageInfo) GetFullVersion() string {
|
||||||
|
return pkgInfo.Version + "-" + strconv.Itoa(pkgInfo.Revision)
|
||||||
|
}
|
||||||
|
|
||||||
type InstallationReason string
|
type InstallationReason string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -132,7 +137,7 @@ func ReadPackage(filename string) (*PackageInfo, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pkgInfo, err := ReadPackageInfo(string(bs), false)
|
pkgInfo, err := ReadPackageInfo(string(bs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -306,11 +311,12 @@ func ExecutePackageScripts(filename, rootDir string, operation Operation, postOp
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error) {
|
func ReadPackageInfo(contents string) (*PackageInfo, error) {
|
||||||
pkgInfo := PackageInfo{
|
pkgInfo := PackageInfo{
|
||||||
Name: "",
|
Name: "",
|
||||||
Description: "",
|
Description: "",
|
||||||
Version: "",
|
Version: "",
|
||||||
|
Revision: 1,
|
||||||
Url: "",
|
Url: "",
|
||||||
License: "",
|
License: "",
|
||||||
Arch: "",
|
Arch: "",
|
||||||
@ -326,19 +332,19 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !defaultValues {
|
|
||||||
if pkgInfo.Name == "" {
|
if pkgInfo.Name == "" {
|
||||||
return nil, errors.New("this package contains no name")
|
return nil, errors.New("this package contains no name")
|
||||||
} else if pkgInfo.Description == "" {
|
} else if pkgInfo.Description == "" {
|
||||||
return nil, errors.New("this package contains no description")
|
return nil, errors.New("this package contains no description")
|
||||||
} else if pkgInfo.Version == "" {
|
} else if pkgInfo.Version == "" {
|
||||||
return nil, errors.New("this package contains no version")
|
return nil, errors.New("this package contains no version")
|
||||||
|
} else if pkgInfo.Revision <= 0 {
|
||||||
|
return nil, errors.New("this package contains a revision number less or equal to 0")
|
||||||
} else if pkgInfo.Arch == "" {
|
} else if pkgInfo.Arch == "" {
|
||||||
return nil, errors.New("this package contains no architecture")
|
return nil, errors.New("this package contains no architecture")
|
||||||
} else if pkgInfo.Type == "" {
|
} else if pkgInfo.Type == "" {
|
||||||
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++ {
|
for i := 0; i < len(pkgInfo.Keep); i++ {
|
||||||
pkgInfo.Keep[i] = strings.TrimPrefix(pkgInfo.Keep[i], "/")
|
pkgInfo.Keep[i] = strings.TrimPrefix(pkgInfo.Keep[i], "/")
|
||||||
}
|
}
|
||||||
@ -363,7 +369,7 @@ func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, p
|
|||||||
}
|
}
|
||||||
ret = append(ret, "Name: "+pkgInfo.Name)
|
ret = append(ret, "Name: "+pkgInfo.Name)
|
||||||
ret = append(ret, "Description: "+pkgInfo.Description)
|
ret = append(ret, "Description: "+pkgInfo.Description)
|
||||||
ret = append(ret, "Version: "+pkgInfo.Version)
|
ret = append(ret, "Version: "+pkgInfo.GetFullVersion())
|
||||||
ret = append(ret, "URL: "+pkgInfo.Url)
|
ret = append(ret, "URL: "+pkgInfo.Url)
|
||||||
ret = append(ret, "License: "+pkgInfo.License)
|
ret = append(ret, "License: "+pkgInfo.License)
|
||||||
if showArchitecture {
|
if showArchitecture {
|
||||||
@ -504,7 +510,7 @@ func extractPackage(pkgInfo *PackageInfo, verbose bool, filename, rootDir string
|
|||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename), nil
|
return errors.New("unknown type (" + strconv.Itoa(int(header.Typeflag)) + ") in " + extractFilename), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -638,7 +644,7 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, verbose, bin
|
|||||||
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("unknown type (" + strconv.Itoa(int(header.Typeflag)) + ") in " + extractFilename), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if header.Name == "source.sh" {
|
if header.Name == "source.sh" {
|
||||||
@ -776,6 +782,7 @@ fi
|
|||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_REVISION=%d", pkgInfo.Revision))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch))
|
||||||
depends := make([]string, len(pkgInfo.Depends))
|
depends := make([]string, len(pkgInfo.Depends))
|
||||||
@ -928,7 +935,7 @@ fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sed := fmt.Sprintf("s/output/files/")
|
sed := fmt.Sprintf("s/output/files/")
|
||||||
fileName := compiledInfo.Name + "-" + compiledInfo.Version + "-" + compiledInfo.Arch + ".bpm"
|
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)
|
cmd := exec.Command("/usr/bin/fakeroot", "-i fakeroot_file", "tar", "-czvpf", fileName, "pkg.info", "output/", "--transform", sed)
|
||||||
if !BPMConfig.SilentCompilation {
|
if !BPMConfig.SilentCompilation {
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
@ -987,7 +994,7 @@ func InstallPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc,
|
|||||||
return errors.New("cannot install a package with a different architecture")
|
return errors.New("cannot install a package with a different architecture")
|
||||||
}
|
}
|
||||||
if unresolved := pkgInfo.CheckDependencies(pkgInfo.Type == "source", true, 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("the following dependencies are not installed: " + strings.Join(unresolved, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pkgInfo.Type == "binary" {
|
if pkgInfo.Type == "binary" {
|
||||||
@ -1006,7 +1013,7 @@ func InstallPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc,
|
|||||||
}
|
}
|
||||||
files = i
|
files = i
|
||||||
} else {
|
} else {
|
||||||
return errors.New("Unknown package type: " + pkgInfo.Type)
|
return errors.New("unknown package type: " + pkgInfo.Type)
|
||||||
}
|
}
|
||||||
slices.Sort(files)
|
slices.Sort(files)
|
||||||
slices.Reverse(files)
|
slices.Reverse(files)
|
||||||
@ -1273,7 +1280,9 @@ func (pkgInfo *PackageInfo) ResolveAll(resolved, unresolved *[]string, checkMake
|
|||||||
entry.Info.ResolveAll(resolved, unresolved, checkMake, checkOptional, ignoreInstalled, rootDir)
|
entry.Info.ResolveAll(resolved, unresolved, checkMake, checkOptional, ignoreInstalled, rootDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !slices.Contains(*resolved, pkgInfo.Name) {
|
||||||
*resolved = append(*resolved, pkgInfo.Name)
|
*resolved = append(*resolved, pkgInfo.Name)
|
||||||
|
}
|
||||||
*unresolved = stringSliceRemove(*unresolved, pkgInfo.Name)
|
*unresolved = stringSliceRemove(*unresolved, pkgInfo.Name)
|
||||||
return *resolved, *unresolved
|
return *resolved, *unresolved
|
||||||
}
|
}
|
||||||
@ -1363,7 +1372,7 @@ func GetPackageInfo(pkg, rootDir string, defaultValues bool) *PackageInfo {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
info, err := ReadPackageInfo(string(bs), defaultValues)
|
info, err := ReadPackageInfo(string(bs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1463,6 +1472,7 @@ func RemovePackage(pkg string, verbose bool, rootDir string) error {
|
|||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version))
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_REVISION=%d", pkgInfo.Revision))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url))
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch))
|
||||||
depends := make([]string, len(pkgInfo.Depends))
|
depends := make([]string, len(pkgInfo.Depends))
|
||||||
|
@ -46,6 +46,7 @@ func (repo *Repository) ReadLocalDatabase() error {
|
|||||||
Name: "",
|
Name: "",
|
||||||
Description: "",
|
Description: "",
|
||||||
Version: "",
|
Version: "",
|
||||||
|
Revision: 1,
|
||||||
Url: "",
|
Url: "",
|
||||||
License: "",
|
License: "",
|
||||||
Arch: "",
|
Arch: "",
|
||||||
@ -137,7 +138,7 @@ func GetRepositoryEntry(str string) (*RepositoryEntry, *Repository, error) {
|
|||||||
|
|
||||||
func (repo *Repository) FetchPackage(pkg string) (string, error) {
|
func (repo *Repository) FetchPackage(pkg string) (string, error) {
|
||||||
if !repo.ContainsPackage(pkg) {
|
if !repo.ContainsPackage(pkg) {
|
||||||
return "", errors.New("Could not fetch package '" + pkg + "'")
|
return "", errors.New("could not fetch package '" + pkg + "'")
|
||||||
}
|
}
|
||||||
entry := repo.Entries[pkg]
|
entry := repo.Entries[pkg]
|
||||||
URL, err := url.JoinPath(repo.Source, entry.Download)
|
URL, err := url.JoinPath(repo.Source, entry.Download)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user