mirror of
https://github.com/Jguer/yay
synced 2024-08-31 13:49:28 +00:00
Removed pacargo, search and install working
This commit is contained in:
parent
33119d5c16
commit
a7c567de97
29
actions.go
29
actions.go
|
@ -11,21 +11,21 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func searchAndInstall(pkgName string, conf alpm.PacmanConfig, flags ...string) (err error) {
|
func searchAndInstall(pkgName string, conf alpm.PacmanConfig, flags string) (err error) {
|
||||||
var num int
|
var num int
|
||||||
var numberString string
|
var numberString string
|
||||||
|
|
||||||
aurRes, err := aur.Search(pkgName, true)
|
a, err := aur.Search(pkgName, true)
|
||||||
repoRes, err := SearchPackages(pkgName, conf)
|
r, err := SearchPackages(pkgName, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if repoRes.Resultcount == 0 && aurRes.Resultcount == 0 {
|
if len(r.Results) == 0 && a.Resultcount == 0 {
|
||||||
return errors.New("No Packages match search")
|
return errors.New("No Packages match search")
|
||||||
}
|
}
|
||||||
repoRes.printSearch(0)
|
r.PrintSearch(0, conf)
|
||||||
aurRes.PrintSearch(repoRes.Resultcount)
|
a.PrintSearch(len(r.Results))
|
||||||
|
|
||||||
fmt.Printf("\x1B[32m%s\033[0m\nNumbers:", "Type numbers to install. Separate each number with a space.")
|
fmt.Printf("\x1B[32m%s\033[0m\nNumbers:", "Type numbers to install. Separate each number with a space.")
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
@ -43,18 +43,17 @@ func searchAndInstall(pkgName string, conf alpm.PacmanConfig, flags ...string) (
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Println(num)
|
|
||||||
|
|
||||||
// Install package
|
// Install package
|
||||||
if num > repoRes.Resultcount-1 {
|
if num > len(r.Results)-1 {
|
||||||
index = num - repoRes.Resultcount
|
index = num - len(r.Results)
|
||||||
err = aurRes.Results[num-index].Install(BuildDir, conf, flags...)
|
err = a.Results[num-index].Install(BuildDir, conf, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Do not abandon program, we might still be able to install the rest
|
// Do not abandon program, we might still be able to install the rest
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
InstallPackage(repoRes.Results[num].Name, conf, flags...)
|
InstallPackage(r.Results[num].Name, conf, flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,17 +61,17 @@ func searchAndInstall(pkgName string, conf alpm.PacmanConfig, flags ...string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func searchMode(pkg string, conf alpm.PacmanConfig) (err error) {
|
func searchMode(pkg string, conf alpm.PacmanConfig) (err error) {
|
||||||
_, err = aur.Search(pkg, true)
|
a, err := aur.Search(pkg, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
repo, err := SearchPackages(pkg, conf)
|
r, err := SearchPackages(pkg, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
aur.printSearch(SearchMode)
|
r.PrintSearch(SearchMode, conf)
|
||||||
repo.printSearch(SearchMode)
|
a.PrintSearch(SearchMode)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
35
aur/aur.go
35
aur/aur.go
|
@ -14,16 +14,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TarBin describes the default installation point of tar command
|
// TarBin describes the default installation point of tar command
|
||||||
// Probably will replace untar with code solution
|
// Probably will replace untar with code solution.
|
||||||
const TarBin string = "/usr/bin/tar"
|
const TarBin string = "/usr/bin/tar"
|
||||||
|
|
||||||
// BaseURL givers the AUR default address
|
// BaseURL givers the AUR default address.
|
||||||
const BaseURL string = "https://aur.archlinux.org"
|
const BaseURL string = "https://aur.archlinux.org"
|
||||||
|
|
||||||
// MakepkgBin describes the default installation point of makepkg command
|
// MakepkgBin describes the default installation point of makepkg command.
|
||||||
const MakepkgBin string = "/usr/bin/makepkg"
|
const MakepkgBin string = "/usr/bin/makepkg"
|
||||||
|
|
||||||
// Result describes an AUR package
|
// SearchMode is search without numbers.
|
||||||
|
const SearchMode int = -1
|
||||||
|
|
||||||
|
// Result describes an AUR package.
|
||||||
type Result struct {
|
type Result struct {
|
||||||
ID int `json:"ID"`
|
ID int `json:"ID"`
|
||||||
Name string `json:"Name"`
|
Name string `json:"Name"`
|
||||||
|
@ -77,14 +80,14 @@ func (r Query) Swap(i, j int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintSearch handles printing search results in a given format
|
// PrintSearch handles printing search results in a given format
|
||||||
func (r Query) PrintSearch(searchFormat bool) {
|
func (r *Query) PrintSearch(start int) {
|
||||||
for i, result := range r.Results {
|
for i, result := range r.Results {
|
||||||
if searchFormat {
|
if start == -1 {
|
||||||
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
||||||
"aur", result.Name, result.Version, result.Description)
|
"aur", result.Name, result.Version, result.Description)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
||||||
|
start+i, "aur", result.Name, result.Version, result.Description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +143,7 @@ func Info(pkg string) (r Query, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install sends system commands to make and install a package from pkgName
|
// Install sends system commands to make and install a package from pkgName
|
||||||
func Install(pkg string, baseDir string, conf alpm.PacmanConfig, flags ...string) (err error) {
|
func Install(pkg string, baseDir string, conf alpm.PacmanConfig, flags string) (err error) {
|
||||||
info, err := Info(pkg)
|
info, err := Info(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -150,12 +153,12 @@ func Install(pkg string, baseDir string, conf alpm.PacmanConfig, flags ...string
|
||||||
return errors.New("Package '" + pkg + "' does not exist")
|
return errors.New("Package '" + pkg + "' does not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
info.Results[0].Install(baseDir, conf, flags...)
|
info.Results[0].Install(baseDir, conf, flags)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install handles install from Result
|
// Install handles install from Result
|
||||||
func (a Result) Install(baseDir string, conf alpm.PacmanConfig, flags ...string) (err error) {
|
func (a *Result) Install(baseDir string, conf alpm.PacmanConfig, flags string) (err error) {
|
||||||
// No need to use filepath.separators because it won't run on inferior platforms
|
// No need to use filepath.separators because it won't run on inferior platforms
|
||||||
err = os.MkdirAll(baseDir+"builds", 0755)
|
err = os.MkdirAll(baseDir+"builds", 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -196,11 +199,13 @@ func (a Result) Install(baseDir string, conf alpm.PacmanConfig, flags ...string)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var args string
|
|
||||||
if len(flags) != 0 {
|
var makepkgcmd *exec.Cmd
|
||||||
args = fmt.Sprintf(" %s", strings.Join(flags, " "))
|
if flags == "" {
|
||||||
|
makepkgcmd = exec.Command(MakepkgBin, "-sri")
|
||||||
|
} else {
|
||||||
|
makepkgcmd = exec.Command(MakepkgBin, "-sri", flags)
|
||||||
}
|
}
|
||||||
makepkgcmd := exec.Command(MakepkgBin, "-sri"+args)
|
|
||||||
makepkgcmd.Stdout = os.Stdout
|
makepkgcmd.Stdout = os.Stdout
|
||||||
makepkgcmd.Stderr = os.Stderr
|
makepkgcmd.Stderr = os.Stderr
|
||||||
makepkgcmd.Stdin = os.Stdin
|
makepkgcmd.Stdin = os.Stdin
|
||||||
|
@ -210,7 +215,7 @@ func (a Result) Install(baseDir string, conf alpm.PacmanConfig, flags ...string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dependencies returns package dependencies splitting between AUR results and Repo Results not installed
|
// Dependencies returns package dependencies splitting between AUR results and Repo Results not installed
|
||||||
func (a Result) Dependencies(conf alpm.PacmanConfig) (final []string, err error) {
|
func (a *Result) Dependencies(conf alpm.PacmanConfig) (final []string, err error) {
|
||||||
f := func(c rune) bool {
|
f := func(c rune) bool {
|
||||||
return c == '>' || c == '<' || c == '=' || c == ' '
|
return c == '>' || c == '<' || c == '=' || c == ' '
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package pacargo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
type operation struct {
|
|
||||||
key byte
|
|
||||||
description string
|
|
||||||
modifiers []modifier
|
|
||||||
execute func()
|
|
||||||
}
|
|
||||||
|
|
||||||
type modifier struct {
|
|
||||||
description string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReturnArgs prints os args
|
|
||||||
func ReturnArgs() {
|
|
||||||
for _, o := range os.Args {
|
|
||||||
fmt.Println(o)
|
|
||||||
}
|
|
||||||
}
|
|
108
pacman.go
108
pacman.go
|
@ -9,40 +9,18 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RepoResult describes a Repository package
|
// RepoSearch describes a Repository search.
|
||||||
type RepoResult struct {
|
type RepoSearch struct {
|
||||||
Description string
|
Results []Result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Result describes a pkg.
|
||||||
|
type Result struct {
|
||||||
|
Name string
|
||||||
Repository string
|
Repository string
|
||||||
Version string
|
Version string
|
||||||
Name string
|
Description string
|
||||||
}
|
Installed bool
|
||||||
|
|
||||||
// RepoSearch describes a Repository search
|
|
||||||
type RepoSearch struct {
|
|
||||||
Resultcount int
|
|
||||||
Results []RepoResult
|
|
||||||
}
|
|
||||||
|
|
||||||
// InstallPackage handles package install
|
|
||||||
func InstallPackage(pkg string, conf alpm.PacmanConfig, flags ...string) (err error) {
|
|
||||||
if found, err := aur.IspkgInRepo(pkg, conf); found {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var args string
|
|
||||||
if len(flags) != 0 {
|
|
||||||
args = fmt.Sprintf(" %s", strings.Join(flags, " "))
|
|
||||||
}
|
|
||||||
cmd := exec.Command("sudo", "pacman", "-S", pkg+args)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
err = cmd.Run()
|
|
||||||
} else {
|
|
||||||
err = aur.Install(os.Args[2], BuildDir, conf, os.Args[3:]...)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
|
func readConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
|
||||||
|
@ -57,35 +35,77 @@ func readConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchPackages handles repo searches
|
// InstallPackage handles package install
|
||||||
func SearchPackages(pkgName string, conf alpm.PacmanConfig) (search RepoSearch, err error) {
|
func InstallPackage(pkg string, conf alpm.PacmanConfig, flags string) (err error) {
|
||||||
|
if found, err := aur.IspkgInRepo(pkg, conf); found {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
if flags == "" {
|
||||||
|
cmd = exec.Command("sudo", "pacman", "-S", pkg)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command("sudo", "pacman", "-S", pkg, flags)
|
||||||
|
}
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
} else {
|
||||||
|
err = aur.Install(pkg, BuildDir, conf, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SearchPackages handles repo searches. Creates a RepoSearch struct.
|
||||||
|
func SearchPackages(pkgName string, conf alpm.PacmanConfig) (s RepoSearch, err error) {
|
||||||
h, err := conf.CreateHandle()
|
h, err := conf.CreateHandle()
|
||||||
defer h.Release()
|
defer h.Release()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
}
|
}
|
||||||
|
|
||||||
dbList, _ := h.SyncDbs()
|
dbList, err := h.SyncDbs()
|
||||||
|
localdb, err := h.LocalDb()
|
||||||
|
|
||||||
|
var installed bool
|
||||||
for _, db := range dbList.Slice() {
|
for _, db := range dbList.Slice() {
|
||||||
for _, pkg := range db.PkgCache().Slice() {
|
for _, pkg := range db.PkgCache().Slice() {
|
||||||
if strings.Contains(pkg.Name(), pkgName) {
|
if strings.Contains(pkg.Name(), pkgName) {
|
||||||
fmt.Println(pkg.Name())
|
if r, _ := localdb.PkgByName(pkg.Name()); r != nil {
|
||||||
|
installed = true
|
||||||
|
} else {
|
||||||
|
installed = false
|
||||||
|
}
|
||||||
|
|
||||||
|
s.Results = append(s.Results, Result{
|
||||||
|
Name: pkg.Name(),
|
||||||
|
Description: pkg.Description(),
|
||||||
|
Version: pkg.Version(),
|
||||||
|
Repository: db.Name(),
|
||||||
|
Installed: installed,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s RepoSearch) printSearch(index int) (err error) {
|
//PrintSearch receives a RepoSearch type and outputs pretty text.
|
||||||
for i, result := range s.Results {
|
func (s *RepoSearch) PrintSearch(mode int, conf alpm.PacmanConfig) {
|
||||||
if index != SearchMode {
|
for i, pkg := range s.Results {
|
||||||
fmt.Printf("%d \033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
if mode != SearchMode {
|
||||||
i, result.Repository, result.Name, result.Version, result.Description)
|
if pkg.Installed == true {
|
||||||
|
fmt.Printf("%d \033[1m%s/\x1B[33m%s\x1B[36m%s\033[0m\n%s\n",
|
||||||
|
i, pkg.Repository, pkg.Name, pkg.Version, pkg.Description)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%d \033[1m%s/\x1B[33m%s (Installed)\x1B[36m%s\033[0m\n%s\n",
|
||||||
|
i, pkg.Repository, pkg.Name, pkg.Version, pkg.Description)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
fmt.Printf("\033[1m%s/\x1B[33m%s \x1B[36m%s\033[0m\n%s\n",
|
||||||
result.Repository, result.Name, result.Version, result.Description)
|
pkg.Repository, pkg.Name, pkg.Version, pkg.Description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
75
yay.go
75
yay.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -12,23 +13,79 @@ const PacmanBin string = "/usr/bin/pacman"
|
||||||
// PacmanConf describes the default pacman config file
|
// PacmanConf describes the default pacman config file
|
||||||
const PacmanConf string = "/etc/pacman.conf"
|
const PacmanConf string = "/etc/pacman.conf"
|
||||||
|
|
||||||
// SearchMode is search without numbers
|
|
||||||
const SearchMode bool = true
|
|
||||||
|
|
||||||
// BuildDir is the root for package building
|
// BuildDir is the root for package building
|
||||||
const BuildDir string = "/tmp/yaytmp/"
|
const BuildDir string = "/tmp/yaytmp/"
|
||||||
|
|
||||||
|
// SearchMode is search without numbers.
|
||||||
|
const SearchMode int = -1
|
||||||
|
|
||||||
|
func operation() (operation string, err error) {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
return "noop", errors.New("No operation specified.")
|
||||||
|
}
|
||||||
|
for _, arg := range os.Args[1:] {
|
||||||
|
if arg[0] == '-' && arg[1] != '-' {
|
||||||
|
return arg, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "yogurt", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func packages() (packages string, err error) {
|
||||||
|
var ps []string
|
||||||
|
for _, arg := range os.Args[1:] {
|
||||||
|
if arg[0] != '-' {
|
||||||
|
ps = append(ps, arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ps) == 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
packages = strings.Join(ps, " ")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func flags() (flags string, err error) {
|
||||||
|
var fs []string
|
||||||
|
for _, arg := range os.Args[1:] {
|
||||||
|
if arg[0] == '-' && arg[1] == '-' {
|
||||||
|
fs = append(fs, arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(fs) == 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
flags = strings.Join(fs, " ")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
conf, err := readConfig(PacmanConf)
|
conf, err := readConfig(PacmanConf)
|
||||||
|
|
||||||
if os.Args[1] == "-Ss" {
|
op, err := operation()
|
||||||
err = searchMode(strings.Join(os.Args[2:], " "), conf)
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
} else if os.Args[1] == "-S" {
|
pkg, _ := packages()
|
||||||
err = InstallPackage(os.Args[2], conf, os.Args[3:]...)
|
|
||||||
} else {
|
flag, _ := flags()
|
||||||
err = searchAndInstall(os.Args[1], conf, os.Args[3:]...)
|
|
||||||
|
switch op {
|
||||||
|
case "-Ss":
|
||||||
|
err = searchMode(pkg, conf)
|
||||||
|
case "-S":
|
||||||
|
err = InstallPackage(pkg, conf, flag)
|
||||||
|
case "yogurt":
|
||||||
|
err = searchAndInstall(pkg, conf, flag)
|
||||||
|
default:
|
||||||
|
fmt.Println("Pass to pacman")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue