2016-12-17 01:40:51 +01:00
|
|
|
package aur
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"github.com/jguer/yay/pacman"
|
2017-01-05 17:13:52 +01:00
|
|
|
"github.com/jguer/yay/util"
|
2016-12-17 01:40:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Result describes an AUR package.
|
|
|
|
type Result struct {
|
2017-02-17 12:55:20 +01:00
|
|
|
Conflicts []string `json:"Conflicts"`
|
2016-12-17 01:40:51 +01:00
|
|
|
Depends []string `json:"Depends"`
|
2017-02-17 12:55:20 +01:00
|
|
|
Description string `json:"Description"`
|
|
|
|
FirstSubmitted int `json:"FirstSubmitted"`
|
|
|
|
ID int `json:"ID"`
|
|
|
|
Keywords []string `json:"Keywords"`
|
|
|
|
LastModified int64 `json:"LastModified"`
|
|
|
|
License []string `json:"License"`
|
|
|
|
Maintainer string `json:"Maintainer"`
|
2016-12-17 01:40:51 +01:00
|
|
|
MakeDepends []string `json:"MakeDepends"`
|
2017-02-17 12:55:20 +01:00
|
|
|
Name string `json:"Name"`
|
|
|
|
NumVotes int `json:"NumVotes"`
|
2016-12-17 01:40:51 +01:00
|
|
|
OptDepends []string `json:"OptDepends"`
|
2017-02-17 12:55:20 +01:00
|
|
|
OutOfDate int `json:"OutOfDate"`
|
|
|
|
PackageBase string `json:"PackageBase"`
|
|
|
|
PackageBaseID int `json:"PackageBaseID"`
|
2016-12-17 01:40:51 +01:00
|
|
|
Provides []string `json:"Provides"`
|
2017-02-17 12:55:20 +01:00
|
|
|
URL string `json:"URL"`
|
|
|
|
URLPath string `json:"URLPath"`
|
|
|
|
Version string `json:"Version"`
|
|
|
|
Installed bool
|
|
|
|
Popularity float32 `json:"Popularity"`
|
2016-12-17 01:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dependencies returns package dependencies not installed belonging to AUR
|
|
|
|
// 0 is Repo, 1 is Foreign.
|
|
|
|
func (a *Result) Dependencies() (runDeps [2][]string, makeDeps [2][]string, err error) {
|
|
|
|
var q Query
|
|
|
|
if len(a.Depends) == 0 && len(a.MakeDepends) == 0 {
|
|
|
|
var n int
|
|
|
|
q, n, err = Info(a.Name)
|
|
|
|
if n == 0 || err != nil {
|
|
|
|
err = fmt.Errorf("Unable to search dependencies, %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
q = append(q, *a)
|
|
|
|
}
|
|
|
|
|
|
|
|
depSearch := pacman.BuildDependencies(a.Depends)
|
|
|
|
if len(a.Depends) != 0 {
|
|
|
|
runDeps[0], runDeps[1] = depSearch(q[0].Depends, true, false)
|
|
|
|
if len(runDeps[0]) != 0 || len(runDeps[1]) != 0 {
|
|
|
|
fmt.Println("\x1b[1;32m=>\x1b[1;33m Run Dependencies: \x1b[0m")
|
|
|
|
printDeps(runDeps[0], runDeps[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(a.MakeDepends) != 0 {
|
|
|
|
makeDeps[0], makeDeps[1] = depSearch(q[0].MakeDepends, false, false)
|
|
|
|
if len(makeDeps[0]) != 0 || len(makeDeps[1]) != 0 {
|
|
|
|
fmt.Println("\x1b[1;32m=>\x1b[1;33m Make Dependencies: \x1b[0m")
|
|
|
|
printDeps(makeDeps[0], makeDeps[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
depSearch(a.MakeDepends, false, true)
|
|
|
|
|
|
|
|
err = nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func printDeps(repoDeps []string, aurDeps []string) {
|
|
|
|
if len(repoDeps) != 0 {
|
|
|
|
fmt.Print("\x1b[1;32m==> Repository dependencies: \x1b[0m")
|
|
|
|
for _, repoD := range repoDeps {
|
|
|
|
fmt.Print("\x1b[33m", repoD, " \x1b[0m")
|
|
|
|
}
|
|
|
|
fmt.Print("\n")
|
|
|
|
|
|
|
|
}
|
|
|
|
if len(aurDeps) != 0 {
|
|
|
|
fmt.Print("\x1b[1;32m==> AUR dependencies: \x1b[0m")
|
|
|
|
for _, aurD := range aurDeps {
|
|
|
|
fmt.Print("\x1b[33m", aurD, " \x1b[0m")
|
|
|
|
}
|
|
|
|
fmt.Print("\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 03:29:52 +01:00
|
|
|
// Install handles install from Info Result.
|
|
|
|
func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
|
2016-12-17 01:40:51 +01:00
|
|
|
fmt.Printf("\x1b[1;32m==> Installing\x1b[33m %s\x1b[0m\n", a.Name)
|
|
|
|
if a.Maintainer == "" {
|
|
|
|
fmt.Println("\x1b[1;31;40m==> Warning:\x1b[0;;40m This package is orphaned.\x1b[0m")
|
|
|
|
}
|
2017-01-05 17:13:52 +01:00
|
|
|
dir := util.BaseDir + a.PackageBase + "/"
|
2016-12-17 01:40:51 +01:00
|
|
|
|
|
|
|
if _, err = os.Stat(dir); os.IsNotExist(err) {
|
2017-02-15 02:50:26 +01:00
|
|
|
if err = util.DownloadAndUnpack(BaseURL+a.URLPath, util.BaseDir, false); err != nil {
|
2016-12-17 01:40:51 +01:00
|
|
|
return
|
|
|
|
}
|
2016-12-17 03:29:52 +01:00
|
|
|
} else {
|
2017-01-05 17:13:52 +01:00
|
|
|
if !util.ContinueTask("Directory exists. Clean Build?", "yY") {
|
|
|
|
os.RemoveAll(util.BaseDir + a.PackageBase)
|
2017-02-15 02:50:26 +01:00
|
|
|
if err = util.DownloadAndUnpack(BaseURL+a.URLPath, util.BaseDir, false); err != nil {
|
2016-12-17 03:29:52 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2016-12-17 01:40:51 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 17:13:52 +01:00
|
|
|
if !util.ContinueTask("Edit PKGBUILD?", "yY") {
|
2017-02-17 12:55:20 +01:00
|
|
|
editcmd := exec.Command(util.Editor(), dir+"PKGBUILD")
|
2016-12-17 01:40:51 +01:00
|
|
|
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
|
|
|
editcmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
runDeps, makeDeps, err := a.Dependencies()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
repoDeps := append(runDeps[0], makeDeps[0]...)
|
|
|
|
aurDeps := append(runDeps[1], makeDeps[1]...)
|
2016-12-17 03:29:52 +01:00
|
|
|
finalmdeps = append(finalmdeps, makeDeps[0]...)
|
|
|
|
finalmdeps = append(finalmdeps, makeDeps[1]...)
|
2016-12-17 01:40:51 +01:00
|
|
|
|
|
|
|
if len(aurDeps) != 0 || len(repoDeps) != 0 {
|
2017-01-05 17:13:52 +01:00
|
|
|
if !util.ContinueTask("Continue?", "nN") {
|
2016-12-17 03:29:52 +01:00
|
|
|
return finalmdeps, fmt.Errorf("user did not like the dependencies")
|
2016-12-17 01:40:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
aurQ, n, _ := MultiInfo(aurDeps)
|
2016-12-17 01:40:51 +01:00
|
|
|
if n != len(aurDeps) {
|
|
|
|
aurQ.MissingPackage(aurDeps)
|
2017-01-05 17:13:52 +01:00
|
|
|
if !util.ContinueTask("Continue?", "nN") {
|
2016-12-17 03:29:52 +01:00
|
|
|
return finalmdeps, fmt.Errorf("unable to install dependencies")
|
2016-12-17 01:40:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 03:00:20 +01:00
|
|
|
var depArgs []string
|
2017-02-17 12:55:20 +01:00
|
|
|
if util.NoConfirm {
|
2017-02-15 03:00:20 +01:00
|
|
|
depArgs = []string{"--asdeps", "--noconfirm"}
|
|
|
|
} else {
|
|
|
|
depArgs = []string{"--asdeps"}
|
|
|
|
}
|
2016-12-17 01:40:51 +01:00
|
|
|
// Repo dependencies
|
|
|
|
if len(repoDeps) != 0 {
|
2017-02-15 03:00:20 +01:00
|
|
|
errR := pacman.Install(repoDeps, depArgs)
|
2016-12-17 01:40:51 +01:00
|
|
|
if errR != nil {
|
2016-12-17 03:29:52 +01:00
|
|
|
return finalmdeps, errR
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 03:00:20 +01:00
|
|
|
// Handle AUR dependencies
|
2016-12-17 03:29:52 +01:00
|
|
|
for _, dep := range aurQ {
|
2017-02-15 03:00:20 +01:00
|
|
|
finalmdepsR, errA := dep.Install(depArgs)
|
2016-12-17 03:29:52 +01:00
|
|
|
finalmdeps = append(finalmdeps, finalmdepsR...)
|
|
|
|
|
|
|
|
if errA != nil {
|
|
|
|
pacman.CleanRemove(repoDeps)
|
2016-12-17 01:40:51 +01:00
|
|
|
pacman.CleanRemove(aurDeps)
|
2016-12-17 03:29:52 +01:00
|
|
|
return finalmdeps, errA
|
2016-12-17 01:40:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os.Chdir(dir)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
args := []string{"-sri"}
|
2016-12-17 01:40:51 +01:00
|
|
|
args = append(args, flags...)
|
2017-02-17 12:55:20 +01:00
|
|
|
makepkgcmd := exec.Command(util.MakepkgBin, args...)
|
2016-12-17 01:40:51 +01:00
|
|
|
makepkgcmd.Stdin, makepkgcmd.Stdout, makepkgcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
|
|
|
err = makepkgcmd.Run()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-17 03:29:52 +01:00
|
|
|
// PrintInfo prints package info like pacman -Si.
|
2016-12-17 01:40:51 +01:00
|
|
|
func (a *Result) PrintInfo() {
|
|
|
|
fmt.Println("\x1b[1;37mRepository :\x1b[0m", "aur")
|
|
|
|
fmt.Println("\x1b[1;37mName :\x1b[0m", a.Name)
|
|
|
|
fmt.Println("\x1b[1;37mVersion :\x1b[0m", a.Version)
|
|
|
|
fmt.Println("\x1b[1;37mDescription :\x1b[0m", a.Description)
|
|
|
|
if a.URL != "" {
|
|
|
|
fmt.Println("\x1b[1;37mURL :\x1b[0m", a.URL)
|
|
|
|
} else {
|
|
|
|
fmt.Println("\x1b[1;37mURL :\x1b[0m", "None")
|
|
|
|
}
|
|
|
|
fmt.Println("\x1b[1;37mLicenses :\x1b[0m", a.License)
|
|
|
|
|
|
|
|
if len(a.Provides) != 0 {
|
|
|
|
fmt.Println("\x1b[1;37mProvides :\x1b[0m", a.Provides)
|
|
|
|
} else {
|
|
|
|
fmt.Println("\x1b[1;37mProvides :\x1b[0m", "None")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(a.Depends) != 0 {
|
|
|
|
fmt.Println("\x1b[1;37mDepends On :\x1b[0m", a.Depends)
|
|
|
|
} else {
|
|
|
|
fmt.Println("\x1b[1;37mDepends On :\x1b[0m", "None")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(a.MakeDepends) != 0 {
|
|
|
|
fmt.Println("\x1b[1;37mMake depends On :\x1b[0m", a.MakeDepends)
|
|
|
|
} else {
|
|
|
|
fmt.Println("\x1b[1;37mMake depends On :\x1b[0m", "None")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(a.OptDepends) != 0 {
|
|
|
|
fmt.Println("\x1b[1;37mOptional Deps :\x1b[0m", a.OptDepends)
|
|
|
|
} else {
|
|
|
|
fmt.Println("\x1b[1;37mOptional Deps :\x1b[0m", "None")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(a.Conflicts) != 0 {
|
|
|
|
fmt.Println("\x1b[1;37mConflicts With :\x1b[0m", a.Conflicts)
|
|
|
|
} else {
|
|
|
|
fmt.Println("\x1b[1;37mConflicts With :\x1b[0m", "None")
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.Maintainer != "" {
|
|
|
|
fmt.Println("\x1b[1;37mMaintainer :\x1b[0m", a.Maintainer)
|
|
|
|
} else {
|
|
|
|
fmt.Println("\x1b[1;37mMaintainer :\x1b[0m", "None")
|
|
|
|
}
|
|
|
|
fmt.Println("\x1b[1;37mVotes :\x1b[0m", a.NumVotes)
|
|
|
|
fmt.Println("\x1b[1;37mPopularity :\x1b[0m", a.Popularity)
|
|
|
|
|
|
|
|
if a.OutOfDate != 0 {
|
|
|
|
fmt.Println("\x1b[1;37mOut-of-date :\x1b[0m", "Yes")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-17 03:29:52 +01:00
|
|
|
// RemoveMakeDeps receives a make dependency list and removes those
|
|
|
|
// that are no longer necessary.
|
|
|
|
func RemoveMakeDeps(depS []string) (err error) {
|
|
|
|
hanging := pacman.SliceHangingPackages(depS)
|
|
|
|
|
|
|
|
if len(hanging) != 0 {
|
2017-01-05 17:13:52 +01:00
|
|
|
if !util.ContinueTask("Confirm Removal?", "nN") {
|
2016-12-17 03:29:52 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = pacman.CleanRemove(hanging)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|