2017-08-02 19:24:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
rpc "github.com/mikkeloscar/aur"
|
2017-08-04 11:26:53 +02:00
|
|
|
gopkg "github.com/mikkeloscar/gopkgbuild"
|
2017-08-02 19:24:03 +02:00
|
|
|
)
|
|
|
|
|
2018-01-20 23:37:10 +01:00
|
|
|
// Install handles package installs
|
2018-01-04 01:59:57 +01:00
|
|
|
func install(parser *arguments) error {
|
2018-01-17 22:48:23 +01: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 01:59:57 +01:00
|
|
|
|
2018-01-04 09:13:47 +01:00
|
|
|
arguments := parser.copy()
|
|
|
|
arguments.delArg("u", "sysupgrade")
|
|
|
|
arguments.delArg("y", "refresh")
|
2018-01-21 12:48:09 +01:00
|
|
|
arguments.op = "S"
|
2018-01-04 09:13:47 +01:00
|
|
|
arguments.targets = make(stringSet)
|
2018-01-04 01:59:57 +01:00
|
|
|
arguments.addTarget(repos...)
|
2018-01-05 23:12:14 +01:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if len(repos) != 0 {
|
2018-01-04 01:59:57 +01:00
|
|
|
err := passToPacman(arguments)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error installing repo packages.")
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(aurs) != 0 {
|
2018-01-17 22:48:23 +01:00
|
|
|
//todo make pretty
|
|
|
|
fmt.Println("Resolving Dependencies")
|
2018-01-20 23:37:10 +01:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
dt, err := getDepTree(aurs)
|
2017-08-02 19:24:03 +02:00
|
|
|
if err != nil {
|
2018-01-17 22:48:23 +01:00
|
|
|
return err
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 23:37:10 +01:00
|
|
|
if len(dt.Missing) > 0 {
|
2018-01-17 22:48:23 +01:00
|
|
|
fmt.Println(dt.Missing)
|
|
|
|
return fmt.Errorf("Could not find all Deps")
|
|
|
|
}
|
2018-01-20 23:37:10 +01:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
dc, err := getDepCatagories(aurs, dt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range dc.AurMake {
|
|
|
|
if pkg.Maintainer == "" {
|
2018-01-26 02:18:49 +01:00
|
|
|
fmt.Println(boldRedFgBlackBg(arrow+"Warning:"),
|
|
|
|
blackBg(pkg.Name+"-"+pkg.Version+"is orphaned"))
|
2018-01-17 22:48:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range dc.Aur {
|
|
|
|
if pkg.Maintainer == "" {
|
2018-01-26 02:18:49 +01:00
|
|
|
fmt.Println(boldRedFgBlackBg(arrow+"Warning:"),
|
|
|
|
blackBg(pkg.Name+"-"+pkg.Version+"is orphaned"))
|
2018-01-17 22:48:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-05 21:05:58 +01:00
|
|
|
printDownloadsFromRepo("Repo", dc.Repo)
|
|
|
|
printDownloadsFromRepo("Repo Make", dc.RepoMake)
|
|
|
|
printDownloadsFromAur("AUR", dc.Aur)
|
|
|
|
printDownloadsFromAur("AUR Make", dc.AurMake)
|
2018-01-20 23:37:10 +01:00
|
|
|
|
2018-01-17 22:48:23 +01: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 19:24:03 +02:00
|
|
|
if err != nil {
|
2018-01-17 22:48:23 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = dowloadPkgBuilds(dc.Aur)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
askEditPkgBuilds(dc.AurMake)
|
|
|
|
askEditPkgBuilds(dc.Aur)
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
if !continueTask("Proceed with install?", "nN") {
|
|
|
|
return fmt.Errorf("Aborting due to user")
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
err = downloadPkgBuildsSources(dc.AurMake)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = downloadPkgBuildsSources(dc.Aur)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01: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 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 23:37:10 +01:00
|
|
|
if len(dc.RepoMake)+len(dc.AurMake) > 0 {
|
2018-01-31 22:04:21 +01:00
|
|
|
if continueTask("Remove make dependencies?", "yY") {
|
2018-01-17 22:48:23 +01:00
|
|
|
return nil
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
removeArguments := makeArguments()
|
|
|
|
removeArguments.addArg("R")
|
2018-01-20 23:37:10 +01:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
for _, pkg := range dc.RepoMake {
|
|
|
|
removeArguments.addTarget(pkg.Name())
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
for _, pkg := range dc.AurMake {
|
|
|
|
removeArguments.addTarget(pkg.Name)
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
|
|
|
|
passToPacman(removeArguments)
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-01-20 23:37:10 +01:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
return nil
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
|
|
|
|
return nil
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
func askCleanBuilds(pkgs []*rpc.Pkg) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
dir := config.BuildDir + pkg.PackageBase + "/"
|
2018-01-20 23:37:10 +01:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
if _, err := os.Stat(dir); !os.IsNotExist(err) {
|
2018-01-20 23:37:10 +01:00
|
|
|
if !continueTask(pkg.Name+" Directory exists. Clean Build?", "yY") {
|
2018-01-17 22:48:23 +01:00
|
|
|
_ = os.RemoveAll(config.BuildDir + pkg.PackageBase)
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
func askEditPkgBuilds(pkgs []*rpc.Pkg) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
dir := config.BuildDir + pkg.PackageBase + "/"
|
2018-01-20 23:37:10 +01:00
|
|
|
|
|
|
|
if !continueTask(pkg.Name+" Edit PKGBUILD?", "yY") {
|
2018-01-17 22:48:23 +01:00
|
|
|
editcmd := exec.Command(editor(), dir+"PKGBUILD")
|
|
|
|
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
|
|
|
editcmd.Run()
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01: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 19:24:03 +02:00
|
|
|
|
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
func dowloadPkgBuilds(pkgs []*rpc.Pkg) (err error) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
//todo make pretty
|
2018-01-20 23:37:10 +01:00
|
|
|
fmt.Println("Downloading:", pkg.Name+"-"+pkg.Version)
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2018-01-20 23:37:10 +01:00
|
|
|
err = downloadAndUnpack(baseURL+pkg.URLPath, config.BuildDir, false)
|
|
|
|
if err != nil {
|
2018-01-17 22:48:23 +01:00
|
|
|
return
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 22:48:23 +01: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 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 22:48:23 +01:00
|
|
|
return
|
|
|
|
}
|
2018-01-05 23:12:14 +01:00
|
|
|
|
2018-01-17 22:48:23 +01: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 15:51:18 +01:00
|
|
|
|
2018-01-17 22:48:23 +01: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 01:59:57 +01:00
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|