mirror of
https://github.com/Jguer/yay
synced 2024-10-31 13:42:27 +00:00
96f499ff44
This reimplemens all operations yay previously supported: '-S' 'Syu' 'Si' ect. Currently the argument objects are not fully implemented with the code. Theres alot of funky conversion from argument object -> pkg, flags -> argument object This is to just get back to the functionally we had before (almost). I have not looked into it yet but alot of the time pacman flags get passed to makepkg. this cases an error for most commands now because the new system Passes all flags: `yay -Syu` -> flags = '-S' '-y' '-u' while the old system would have done: `yay -Syu` -> op = '-Suy', flags = '' So extra flags are no longer passed at all currently. This means: 'yay -S aic94xx-firmware --noconfirm -b /tmp/pacutilesu2q6hw/tmp-pacman -d' will no longer error and 'aic94xx-firmware' will be installed but the database path change will not apply and the dep checking will not be skipped.
179 lines
4.1 KiB
Go
179 lines
4.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
|
|
rpc "github.com/mikkeloscar/aur"
|
|
gopkg "github.com/mikkeloscar/gopkgbuild"
|
|
)
|
|
|
|
// Install handles package installs
|
|
func install(parser *arguments) error {
|
|
aurs, repos, _ := packageSlices(parser.targets.toSlice())
|
|
|
|
arguments := makeArguments()
|
|
arguments.op = parser.op
|
|
arguments.options = arguments.options
|
|
arguments.addTarget(repos...)
|
|
|
|
if len(repos) != 0 {
|
|
err := passToPacman(arguments)
|
|
if err != nil {
|
|
fmt.Println("Error installing repo packages.")
|
|
}
|
|
}
|
|
|
|
if len(aurs) != 0 {
|
|
err := aurInstall(aurs, make([]string,0))
|
|
if err != nil {
|
|
fmt.Println("Error installing aur packages.")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Install sends system commands to make and install a package from pkgName
|
|
func aurInstall(pkgName []string, flags []string) (err error) {
|
|
q, err := rpc.Info(pkgName)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if len(q) != len(pkgName) {
|
|
fmt.Printf("Some packages from list\n%+v\n do 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
|
|
}
|
|
|
|
func setupPackageSpace(a *rpc.Pkg) (dir string, pkgbuild *gopkg.PKGBUILD, err error) {
|
|
dir = config.BuildDir + a.PackageBase + "/"
|
|
|
|
if _, err = os.Stat(dir); !os.IsNotExist(err) {
|
|
if !continueTask("Directory exists. Clean Build?", "yY") {
|
|
_ = os.RemoveAll(config.BuildDir + a.PackageBase)
|
|
}
|
|
}
|
|
|
|
if err = downloadAndUnpack(baseURL+a.URLPath, config.BuildDir, false); err != nil {
|
|
return
|
|
}
|
|
|
|
if !continueTask("Edit PKGBUILD?", "yY") {
|
|
editcmd := exec.Command(editor(), dir+"PKGBUILD")
|
|
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 {
|
|
owner, repo := parseSource(pkgsource)
|
|
if owner != "" && repo != "" {
|
|
err = branchInfo(a.Name, owner, repo)
|
|
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")
|
|
}
|
|
|
|
dir, _, err := setupPackageSpace(a)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if specialDBsauce {
|
|
return
|
|
}
|
|
|
|
runDeps, makeDeps, err := pkgDependencies(a)
|
|
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 {
|
|
if !continueTask("Continue?", "nN") {
|
|
return finalmdeps, fmt.Errorf("user did not like the dependencies")
|
|
}
|
|
}
|
|
|
|
aurQ, _ := rpc.Info(aurDeps)
|
|
if len(aurQ) != len(aurDeps) {
|
|
(aurQuery)(aurQ).missingPackage(aurDeps)
|
|
if !continueTask("Continue?", "nN") {
|
|
return finalmdeps, fmt.Errorf("unable to install dependencies")
|
|
}
|
|
}
|
|
|
|
arguments := makeArguments()
|
|
arguments.addArg("S", "asdeps")
|
|
depArgs := arguments.formatArgs()
|
|
|
|
if config.NoConfirm {
|
|
arguments.addArg("noconfirm")
|
|
}
|
|
// Repo dependencies
|
|
if len(repoDeps) != 0 {
|
|
errR := passToPacman(arguments)
|
|
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 {
|
|
cleanRemove(repoDeps)
|
|
cleanRemove(aurDeps)
|
|
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
|
|
makepkgcmd.Dir = dir
|
|
err = makepkgcmd.Run()
|
|
if err == nil {
|
|
_ = saveVCSInfo()
|
|
if config.CleanAfter {
|
|
fmt.Println("\x1b[1;32m==> CleanAfter enabled. Deleting source folder.\x1b[0m")
|
|
os.RemoveAll(dir)
|
|
}
|
|
}
|
|
return
|
|
}
|