mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 10:36:12 +00:00
Added basic remote repository functionality
This commit is contained in:
@@ -29,10 +29,12 @@ var yesAll = false
|
||||
var buildSource = false
|
||||
var skipCheck = false
|
||||
var keepTempDir = false
|
||||
var forceInstall = false
|
||||
var force = false
|
||||
var showInstalled = false
|
||||
var pkgListNumbers = false
|
||||
var pkgListNames = false
|
||||
var reinstall = false
|
||||
var nosync = true
|
||||
|
||||
func main() {
|
||||
utils.ReadConfig()
|
||||
@@ -48,6 +50,8 @@ const (
|
||||
info
|
||||
list
|
||||
install
|
||||
update
|
||||
sync
|
||||
remove
|
||||
file
|
||||
)
|
||||
@@ -62,6 +66,10 @@ func getCommandType() commandType {
|
||||
return list
|
||||
case "install":
|
||||
return install
|
||||
case "update":
|
||||
return update
|
||||
case "sync":
|
||||
return sync
|
||||
case "remove":
|
||||
return remove
|
||||
case "file":
|
||||
@@ -91,16 +99,23 @@ func resolveCommand() {
|
||||
continue
|
||||
}
|
||||
|
||||
} else {
|
||||
} else if showInstalled {
|
||||
info = utils.GetPackageInfo(pkg, rootDir, false)
|
||||
if info == nil {
|
||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||
fmt.Printf("Package (%s) is not installed\n", pkg)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
entry, err := utils.GetRepositoryEntry(pkg)
|
||||
if err != nil {
|
||||
fmt.Printf("Package (%s) could not be found in any repository\n", pkg)
|
||||
continue
|
||||
}
|
||||
info = &entry.Info
|
||||
}
|
||||
fmt.Println("----------------")
|
||||
if showInstalled {
|
||||
fmt.Println(utils.CreateReadableInfo(false, false, true, false, true, info, rootDir))
|
||||
fmt.Println(utils.CreateReadableInfo(true, true, true, false, true, info, rootDir))
|
||||
} else {
|
||||
fmt.Println(utils.CreateReadableInfo(true, true, true, true, true, info, rootDir))
|
||||
}
|
||||
@@ -164,7 +179,7 @@ func resolveCommand() {
|
||||
}
|
||||
verb = "build"
|
||||
}
|
||||
if !forceInstall {
|
||||
if !force {
|
||||
if pkgInfo.Arch != "any" && pkgInfo.Arch != utils.GetArch() {
|
||||
fmt.Printf("skipping... cannot %s a package with a different architecture\n", verb)
|
||||
continue
|
||||
@@ -226,7 +241,7 @@ func resolveCommand() {
|
||||
}
|
||||
}
|
||||
|
||||
err = utils.InstallPackage(file, rootDir, verbose, forceInstall, buildSource, skipCheck, keepTempDir)
|
||||
err = utils.InstallPackage(file, rootDir, verbose, force, buildSource, skipCheck, keepTempDir)
|
||||
if err != nil {
|
||||
if pkgInfo.Type == "source" && keepTempDir {
|
||||
fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name)
|
||||
@@ -238,6 +253,34 @@ func resolveCommand() {
|
||||
fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **")
|
||||
}
|
||||
}
|
||||
case sync:
|
||||
if os.Getuid() != 0 {
|
||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||
os.Exit(0)
|
||||
}
|
||||
if !yesAll {
|
||||
fmt.Printf("Are you sure you wish to sync all databases? [y\\N] ")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
text, _ := reader.ReadString('\n')
|
||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||
fmt.Println("Cancelling sync...")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
for _, repo := range utils.BPMConfig.Repositories {
|
||||
if repo.Disabled {
|
||||
if verbose {
|
||||
fmt.Printf("Skipping repository (%s) because it is disabled\n", repo.Name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
||||
err := repo.SyncLocalDatabase()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
fmt.Println("All package databases synced successfully!")
|
||||
case remove:
|
||||
if os.Getuid() != 0 {
|
||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||
@@ -344,11 +387,22 @@ func printHelp() {
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
fmt.Println(" -y skips the confirmation prompt")
|
||||
fmt.Println(" -f skips dependency 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("-> bpm update [-R, -v, -y, -f, --reinstall, --nosync] | updates all packages that are available in the repositories")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
fmt.Println(" -y skips the confirmation prompt")
|
||||
fmt.Println(" -f skips dependency, conflict and architecture checking")
|
||||
fmt.Println(" --reinstall Fetches and reinstalls all packages even if they do not have a newer version available")
|
||||
fmt.Println(" --nosync Skips package database syncing")
|
||||
fmt.Println("-> bpm sync [-R, -v] | Syncs package databases without updating packages")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
fmt.Println(" -y skips the confirmation prompt")
|
||||
fmt.Println("-> bpm remove [-R, -v, -y] <packages...> | removes the following packages")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
@@ -380,8 +434,23 @@ func resolveFlags() {
|
||||
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(&forceInstall, "f", false, "Force installation by skipping architecture and dependency resolution")
|
||||
installFlagSet.BoolVar(&force, "f", false, "Force installation by skipping architecture and dependency resolution")
|
||||
installFlagSet.Usage = printHelp
|
||||
// Update flags
|
||||
updateFlagSet := flag.NewFlagSet("Update flags", flag.ExitOnError)
|
||||
updateFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
updateFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
updateFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||
updateFlagSet.BoolVar(&force, "f", false, "Force update by skipping architecture and dependency resolution")
|
||||
updateFlagSet.BoolVar(&reinstall, "reinstall", false, "Fetches and reinstalls all packages even if they do not have a newer version available")
|
||||
updateFlagSet.BoolVar(&nosync, "nosync", false, "Skips package database syncing")
|
||||
updateFlagSet.Usage = printHelp
|
||||
// Sync flags
|
||||
syncFlagSet := flag.NewFlagSet("Sync flags", flag.ExitOnError)
|
||||
syncFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
syncFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
syncFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||
syncFlagSet.Usage = printHelp
|
||||
// Remove flags
|
||||
removeFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
||||
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
@@ -415,6 +484,18 @@ func resolveFlags() {
|
||||
return
|
||||
}
|
||||
subcommandArgs = installFlagSet.Args()
|
||||
} else if getCommandType() == update {
|
||||
err := updateFlagSet.Parse(subcommandArgs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
subcommandArgs = updateFlagSet.Args()
|
||||
} else if getCommandType() == sync {
|
||||
err := syncFlagSet.Parse(subcommandArgs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
subcommandArgs = syncFlagSet.Args()
|
||||
} else if getCommandType() == remove {
|
||||
err := removeFlagSet.Parse(subcommandArgs)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user