2017-08-02 17:24:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2018-01-17 21:48:23 +00:00
|
|
|
"strconv"
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-20 22:37:10 +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
|
|
|
|
fmt.Println("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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println()
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
p1 := func(a []*alpm.Package) {
|
|
|
|
for _, v := range a {
|
|
|
|
fmt.Print(" ", v.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p2 := func(a []*rpc.Pkg) {
|
|
|
|
for _, v := range a {
|
|
|
|
fmt.Print(" ", v.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Print("Repo (" + strconv.Itoa(len(dc.Repo)) + "):")
|
|
|
|
p1(dc.Repo)
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
fmt.Print("Repo Make (" + strconv.Itoa(len(dc.RepoMake)) + "):")
|
|
|
|
p1(dc.RepoMake)
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
fmt.Print("Aur (" + strconv.Itoa(len(dc.Aur)) + "):")
|
|
|
|
p2(dc.Aur)
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
fmt.Print("Aur Make (" + strconv.Itoa(len(dc.AurMake)) + "):")
|
|
|
|
p2(dc.AurMake)
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
fmt.Println()
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
askCleanBuilds(dc.AurMake)
|
|
|
|
askCleanBuilds(dc.Aur)
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
if !continueTask("Proceed with download?", "nN") {
|
|
|
|
return fmt.Errorf("Aborting due to user")
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-17 21:48:23 +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-17 21:48:23 +00:00
|
|
|
if continueTask("Remove make dependancies?", "yY") {
|
|
|
|
return nil
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
removeArguments := makeArguments()
|
|
|
|
removeArguments.addArg("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
|
|
|
|
|
|
|
passToPacman(removeArguments)
|
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-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
|
|
|
|
}
|