2017-08-02 17:24:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
2018-02-07 12:36:51 +00:00
|
|
|
alpm "github.com/jguer/go-alpm"
|
2017-08-02 17:24:03 +00:00
|
|
|
rpc "github.com/mikkeloscar/aur"
|
2017-08-04 09:26:53 +00:00
|
|
|
gopkg "github.com/mikkeloscar/gopkgbuild"
|
2017-08-02 17:24:03 +00:00
|
|
|
)
|
|
|
|
|
2018-01-20 22:37:10 +00:00
|
|
|
// Install handles package installs
|
2018-01-04 00:59:57 +00:00
|
|
|
func install(parser *arguments) error {
|
2018-01-17 21:48:23 +00:00
|
|
|
aurs, repos, missing, err := packageSlices(parser.targets.toSlice())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(missing) > 0 {
|
|
|
|
fmt.Println(missing)
|
|
|
|
return fmt.Errorf("Could not find all Targets")
|
|
|
|
}
|
2018-01-04 00:59:57 +00:00
|
|
|
|
2018-01-04 08:13:47 +00:00
|
|
|
arguments := parser.copy()
|
|
|
|
arguments.delArg("u", "sysupgrade")
|
|
|
|
arguments.delArg("y", "refresh")
|
2018-01-21 11:48:09 +00:00
|
|
|
arguments.op = "S"
|
2018-01-04 08:13:47 +00:00
|
|
|
arguments.targets = make(stringSet)
|
2018-01-04 00:59:57 +00:00
|
|
|
arguments.addTarget(repos...)
|
2018-01-05 22:12:14 +00:00
|
|
|
|
2017-08-02 17:24:03 +00:00
|
|
|
if len(repos) != 0 {
|
2018-01-04 00:59:57 +00:00
|
|
|
err := passToPacman(arguments)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error installing repo packages.")
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(aurs) != 0 {
|
2018-01-17 21:48:23 +00:00
|
|
|
//todo make pretty
|
2018-02-07 12:36:51 +00:00
|
|
|
fmt.Println(greenFg(arrow), greenFg("Resolving Dependencies"))
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
dt, err := getDepTree(aurs)
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
2018-01-17 21:48:23 +00:00
|
|
|
return err
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 22:37:10 +00:00
|
|
|
if len(dt.Missing) > 0 {
|
2018-01-17 21:48:23 +00:00
|
|
|
fmt.Println(dt.Missing)
|
|
|
|
return fmt.Errorf("Could not find all Deps")
|
|
|
|
}
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
dc, err := getDepCatagories(aurs, dt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range dc.AurMake {
|
|
|
|
if pkg.Maintainer == "" {
|
2018-01-26 01:18:49 +00:00
|
|
|
fmt.Println(boldRedFgBlackBg(arrow+"Warning:"),
|
|
|
|
blackBg(pkg.Name+"-"+pkg.Version+"is orphaned"))
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range dc.Aur {
|
|
|
|
if pkg.Maintainer == "" {
|
2018-01-26 01:18:49 +00:00
|
|
|
fmt.Println(boldRedFgBlackBg(arrow+"Warning:"),
|
|
|
|
blackBg(pkg.Name+"-"+pkg.Version+"is orphaned"))
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-05 20:05:58 +00:00
|
|
|
printDownloadsFromRepo("Repo", dc.Repo)
|
|
|
|
printDownloadsFromRepo("Repo Make", dc.RepoMake)
|
|
|
|
printDownloadsFromAur("AUR", dc.Aur)
|
|
|
|
printDownloadsFromAur("AUR Make", dc.AurMake)
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
askCleanBuilds(dc.AurMake)
|
|
|
|
askCleanBuilds(dc.Aur)
|
|
|
|
fmt.Println()
|
|
|
|
|
2018-02-07 12:36:51 +00:00
|
|
|
if !continueTask("Proceed with install?", "nN") {
|
2018-01-17 21:48:23 +00:00
|
|
|
return fmt.Errorf("Aborting due to user")
|
|
|
|
}
|
2018-02-07 12:36:51 +00:00
|
|
|
// if !continueTask("Proceed with download?", "nN") {
|
|
|
|
// return fmt.Errorf("Aborting due to user")
|
|
|
|
// }
|
|
|
|
|
|
|
|
err = checkForConflicts(dc.Aur, dc.AurMake, dc.Repo, dc.RepoMake)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
|
|
|
err = dowloadPkgBuilds(dc.AurMake)
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
2018-01-17 21:48:23 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = dowloadPkgBuilds(dc.Aur)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
askEditPkgBuilds(dc.AurMake)
|
|
|
|
askEditPkgBuilds(dc.Aur)
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-02-07 12:36:51 +00:00
|
|
|
// if !continueTask("Proceed with install?", "nN") {
|
|
|
|
// return fmt.Errorf("Aborting due to user")
|
|
|
|
// }
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
err = downloadPkgBuildsSources(dc.AurMake)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = downloadPkgBuildsSources(dc.Aur)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
err = buildInstallPkgBuilds(dc.AurMake, parser.targets)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = buildInstallPkgBuilds(dc.Aur, parser.targets)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 22:37:10 +00:00
|
|
|
if len(dc.RepoMake)+len(dc.AurMake) > 0 {
|
2018-01-31 21:04:21 +00:00
|
|
|
if continueTask("Remove make dependencies?", "yY") {
|
2018-01-17 21:48:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
removeArguments := makeArguments()
|
2018-02-07 12:36:51 +00:00
|
|
|
removeArguments.addOP("R")
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
for _, pkg := range dc.RepoMake {
|
|
|
|
removeArguments.addTarget(pkg.Name())
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
for _, pkg := range dc.AurMake {
|
|
|
|
removeArguments.addTarget(pkg.Name)
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-02-07 12:36:51 +00:00
|
|
|
oldValue := config.NoConfirm
|
|
|
|
config.NoConfirm = true
|
2018-01-17 21:48:23 +00:00
|
|
|
passToPacman(removeArguments)
|
2018-02-07 12:36:51 +00:00
|
|
|
config.NoConfirm = oldValue
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return nil
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
|
|
|
return nil
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
func askCleanBuilds(pkgs []*rpc.Pkg) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
dir := config.BuildDir + pkg.PackageBase + "/"
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
if _, err := os.Stat(dir); !os.IsNotExist(err) {
|
2018-01-20 22:37:10 +00:00
|
|
|
if !continueTask(pkg.Name+" Directory exists. Clean Build?", "yY") {
|
2018-01-17 21:48:23 +00:00
|
|
|
_ = os.RemoveAll(config.BuildDir + pkg.PackageBase)
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-02-07 12:36:51 +00:00
|
|
|
func checkForConflicts(aur []*rpc.Pkg, aurMake []*rpc.Pkg, repo []*alpm.Package,
|
|
|
|
repoMake []*alpm.Package) error {
|
|
|
|
|
|
|
|
localDb, err := alpmHandle.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var toRemove []string
|
|
|
|
|
|
|
|
for _, pkg := range aur {
|
|
|
|
for _, cpkg := range pkg.Conflicts {
|
|
|
|
if _, err := localDb.PkgByName(cpkg); err == nil {
|
|
|
|
toRemove = append(toRemove, cpkg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range aurMake {
|
|
|
|
for _, cpkg := range pkg.Conflicts {
|
|
|
|
if _, err := localDb.PkgByName(cpkg); err == nil {
|
|
|
|
toRemove = append(toRemove, cpkg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range repo {
|
|
|
|
pkg.Conflicts().ForEach(func(conf alpm.Depend) error {
|
|
|
|
if _, err := localDb.PkgByName(conf.Name); err == nil {
|
|
|
|
toRemove = append(toRemove, conf.Name)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range repoMake {
|
|
|
|
pkg.Conflicts().ForEach(func(conf alpm.Depend) error {
|
|
|
|
if _, err := localDb.PkgByName(conf.Name); err == nil {
|
|
|
|
toRemove = append(toRemove, conf.Name)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(toRemove) != 0 {
|
|
|
|
fmt.Println(
|
|
|
|
redFg("The following packages conflict with packages to install:"))
|
|
|
|
for _, pkg := range toRemove {
|
|
|
|
fmt.Println(yellowFg(pkg))
|
|
|
|
}
|
|
|
|
|
|
|
|
if !continueTask("Remove conflicting package(s)?", "nN") {
|
|
|
|
return fmt.Errorf("Aborting due to user")
|
|
|
|
}
|
|
|
|
|
|
|
|
removeArguments := makeArguments()
|
|
|
|
removeArguments.addArg("R", "d", "d")
|
|
|
|
|
|
|
|
for _, pkg := range toRemove {
|
|
|
|
removeArguments.addTarget(pkg)
|
|
|
|
}
|
|
|
|
|
|
|
|
oldValue := config.NoConfirm
|
|
|
|
config.NoConfirm = true
|
|
|
|
passToPacman(removeArguments)
|
|
|
|
config.NoConfirm = oldValue
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
func askEditPkgBuilds(pkgs []*rpc.Pkg) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
dir := config.BuildDir + pkg.PackageBase + "/"
|
2018-01-20 22:37:10 +00:00
|
|
|
|
|
|
|
if !continueTask(pkg.Name+" Edit PKGBUILD?", "yY") {
|
2018-01-17 21:48:23 +00:00
|
|
|
editcmd := exec.Command(editor(), dir+"PKGBUILD")
|
|
|
|
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
|
|
|
editcmd.Run()
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO")
|
|
|
|
if err == nil {
|
|
|
|
for _, pkgsource := range pkgbuild.Source {
|
|
|
|
owner, repo := parseSource(pkgsource)
|
|
|
|
if owner != "" && repo != "" {
|
|
|
|
err = branchInfo(pkg.Name, owner, repo)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
func dowloadPkgBuilds(pkgs []*rpc.Pkg) (err error) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
//todo make pretty
|
2018-01-20 22:37:10 +00:00
|
|
|
fmt.Println("Downloading:", pkg.Name+"-"+pkg.Version)
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-20 22:37:10 +00:00
|
|
|
err = downloadAndUnpack(baseURL+pkg.URLPath, config.BuildDir, false)
|
|
|
|
if err != nil {
|
2018-01-17 21:48:23 +00:00
|
|
|
return
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func downloadPkgBuildsSources(pkgs []*rpc.Pkg) (err error) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
dir := config.BuildDir + pkg.PackageBase + "/"
|
|
|
|
err = passToMakepkg(dir, "-f", "--verifysource")
|
|
|
|
if err != nil {
|
|
|
|
return
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return
|
|
|
|
}
|
2018-01-05 22:12:14 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
func buildInstallPkgBuilds(pkgs []*rpc.Pkg, targets stringSet) (err error) {
|
|
|
|
//for n := len(pkgs) -1 ; n > 0; n-- {
|
|
|
|
for n := 0; n < len(pkgs); n++ {
|
|
|
|
pkg := pkgs[n]
|
2018-01-19 14:51:18 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
dir := config.BuildDir + pkg.PackageBase + "/"
|
|
|
|
if targets.get(pkg.Name) {
|
|
|
|
err = passToMakepkg(dir, "-Cscfi", "--noconfirm")
|
|
|
|
} else {
|
|
|
|
err = passToMakepkg(dir, "-Cscfi", "--noconfirm", "--asdeps")
|
2018-01-04 00:59:57 +00:00
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|