2017-08-02 17:24:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2017-08-07 13:43:25 +00:00
|
|
|
func newInstall(pkgs []string, flags []string) error {
|
|
|
|
aurs, repos, _ := packageSlices(pkgs)
|
|
|
|
|
|
|
|
if len(repos) != 0 {
|
|
|
|
err := passToPacman("-S", repos, flags)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error installing repo packages.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(aurs) != 0 {
|
|
|
|
err := aurInstall(aurs, flags)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error installing aur packages.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-02 17:24:03 +00:00
|
|
|
// Install handles package installs
|
|
|
|
func install(pkgs []string, flags []string) error {
|
2017-08-04 09:26:53 +00:00
|
|
|
aurs, repos, _ := packageSlices(pkgs)
|
2017-08-02 17:24:03 +00:00
|
|
|
|
|
|
|
if len(repos) != 0 {
|
2017-08-04 09:26:53 +00:00
|
|
|
err := passToPacman("-S", repos, flags)
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error installing repo packages.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(aurs) != 0 {
|
2017-08-04 09:26:53 +00:00
|
|
|
err := aurInstall(aurs, flags)
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error installing aur packages.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install sends system commands to make and install a package from pkgName
|
2017-08-04 09:26:53 +00:00
|
|
|
func aurInstall(pkgName []string, flags []string) (err error) {
|
2017-08-02 17:24:03 +00:00
|
|
|
q, err := rpc.Info(pkgName)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(q) != len(pkgName) {
|
|
|
|
fmt.Printf("Some package from list\n%+v\ndoes not exist", pkgName)
|
|
|
|
}
|
|
|
|
|
|
|
|
var finalrm []string
|
|
|
|
for _, i := range q {
|
|
|
|
mrm, err := PkgInstall(&i, flags)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error installing", i.Name, ":", err)
|
|
|
|
}
|
|
|
|
finalrm = append(finalrm, mrm...)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(finalrm) != 0 {
|
|
|
|
err = removeMakeDeps(finalrm)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:54:34 +00:00
|
|
|
func setupPackageSpace(a *rpc.Pkg) (dir string, pkgbuild *gopkg.PKGBUILD, err error) {
|
|
|
|
dir = config.BuildDir + a.PackageBase + "/"
|
2017-08-02 17:24:03 +00:00
|
|
|
|
|
|
|
if _, err = os.Stat(dir); !os.IsNotExist(err) {
|
2017-08-04 09:26:53 +00:00
|
|
|
if !continueTask("Directory exists. Clean Build?", "yY") {
|
2017-08-02 17:24:03 +00:00
|
|
|
_ = os.RemoveAll(config.BuildDir + a.PackageBase)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 09:26:53 +00:00
|
|
|
if err = downloadAndUnpack(baseURL+a.URLPath, config.BuildDir, false); err != nil {
|
2017-08-02 17:24:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-04 09:26:53 +00:00
|
|
|
if !continueTask("Edit PKGBUILD?", "yY") {
|
|
|
|
editcmd := exec.Command(editor(), dir+"PKGBUILD")
|
2017-08-02 17:24:03 +00:00
|
|
|
editcmd.Stdin, editcmd.Stdout, editcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
|
|
|
editcmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgbuild, err = gopkg.ParseSRCINFO(dir + ".SRCINFO")
|
|
|
|
if err == nil {
|
|
|
|
for _, pkgsource := range pkgbuild.Source {
|
2017-08-04 09:26:53 +00:00
|
|
|
owner, repo := parseSource(pkgsource)
|
2017-08-02 17:24:03 +00:00
|
|
|
if owner != "" && repo != "" {
|
2017-08-04 09:26:53 +00:00
|
|
|
err = branchInfo(a.Name, owner, repo)
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// PkgInstall handles install from Info Result.
|
|
|
|
func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
|
|
|
|
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-10-02 15:54:34 +00:00
|
|
|
dir, _, err := setupPackageSpace(a)
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if specialDBsauce {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-04 09:26:53 +00:00
|
|
|
runDeps, makeDeps, err := pkgDependencies(a)
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
repoDeps := append(runDeps[0], makeDeps[0]...)
|
|
|
|
aurDeps := append(runDeps[1], makeDeps[1]...)
|
|
|
|
finalmdeps = append(finalmdeps, makeDeps[0]...)
|
|
|
|
finalmdeps = append(finalmdeps, makeDeps[1]...)
|
|
|
|
|
|
|
|
if len(aurDeps) != 0 || len(repoDeps) != 0 {
|
2017-08-04 09:26:53 +00:00
|
|
|
if !continueTask("Continue?", "nN") {
|
2017-08-02 17:24:03 +00:00
|
|
|
return finalmdeps, fmt.Errorf("user did not like the dependencies")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aurQ, _ := rpc.Info(aurDeps)
|
|
|
|
if len(aurQ) != len(aurDeps) {
|
2017-08-04 09:26:53 +00:00
|
|
|
(aurQuery)(aurQ).missingPackage(aurDeps)
|
|
|
|
if !continueTask("Continue?", "nN") {
|
2017-08-02 17:24:03 +00:00
|
|
|
return finalmdeps, fmt.Errorf("unable to install dependencies")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var depArgs []string
|
|
|
|
if config.NoConfirm {
|
|
|
|
depArgs = []string{"--asdeps", "--noconfirm"}
|
|
|
|
} else {
|
|
|
|
depArgs = []string{"--asdeps"}
|
|
|
|
}
|
|
|
|
// Repo dependencies
|
|
|
|
if len(repoDeps) != 0 {
|
2017-08-04 09:26:53 +00:00
|
|
|
errR := passToPacman("-S", repoDeps, depArgs)
|
2017-08-02 17:24:03 +00:00
|
|
|
if errR != nil {
|
|
|
|
return finalmdeps, errR
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle AUR dependencies
|
|
|
|
for _, dep := range aurQ {
|
|
|
|
finalmdepsR, errA := PkgInstall(&dep, depArgs)
|
|
|
|
finalmdeps = append(finalmdeps, finalmdepsR...)
|
|
|
|
|
|
|
|
if errA != nil {
|
2017-08-04 09:26:53 +00:00
|
|
|
cleanRemove(repoDeps)
|
|
|
|
cleanRemove(aurDeps)
|
2017-08-02 17:24:03 +00:00
|
|
|
return finalmdeps, errA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{"-sri"}
|
|
|
|
args = append(args, flags...)
|
|
|
|
makepkgcmd := exec.Command(config.MakepkgBin, args...)
|
|
|
|
makepkgcmd.Stdin, makepkgcmd.Stdout, makepkgcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
2017-10-02 15:54:34 +00:00
|
|
|
makepkgcmd.Dir = dir
|
2017-08-02 17:24:03 +00:00
|
|
|
err = makepkgcmd.Run()
|
|
|
|
if err == nil {
|
2017-08-04 09:26:53 +00:00
|
|
|
_ = saveVCSInfo()
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|