2016-12-01 00:11:13 +01:00
|
|
|
package pacman
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
2016-12-01 02:29:09 +01:00
|
|
|
"github.com/jguer/go-alpm"
|
2017-01-05 17:13:52 +01:00
|
|
|
"github.com/jguer/yay/util"
|
2016-12-01 00:11:13 +01:00
|
|
|
)
|
|
|
|
|
2017-02-05 05:15:44 +01:00
|
|
|
// Query describes a Repository search.
|
|
|
|
type Query []Result
|
2016-12-01 00:11:13 +01:00
|
|
|
|
|
|
|
// Result describes a pkg.
|
|
|
|
type Result struct {
|
|
|
|
Name string
|
|
|
|
Repository string
|
|
|
|
Version string
|
|
|
|
Description string
|
2016-12-02 13:19:03 +01:00
|
|
|
Group string
|
2016-12-01 00:11:13 +01:00
|
|
|
Installed bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdatePackages handles cache update and upgrade
|
|
|
|
func UpdatePackages(flags []string) error {
|
2017-02-17 12:55:20 +01:00
|
|
|
args := append([]string{"pacman", "-Syu"}, flags...)
|
2016-12-01 00:11:13 +01:00
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
cmd := exec.Command("sudo", args...)
|
|
|
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
2016-12-01 00:11:13 +01:00
|
|
|
err := cmd.Run()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-12-02 13:19:03 +01:00
|
|
|
// Search handles repo searches. Creates a RepoSearch struct.
|
2017-02-18 16:29:40 +01:00
|
|
|
func Search(pkgInputN []string) (s Query, n int, err error) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-01 00:11:13 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
|
2016-12-02 13:19:03 +01:00
|
|
|
localDb, err := h.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return
|
2016-12-01 00:11:13 +01:00
|
|
|
}
|
2016-12-02 13:19:03 +01:00
|
|
|
dbList, err := h.SyncDbs()
|
2016-12-01 00:11:13 +01:00
|
|
|
if err != nil {
|
2016-12-02 13:19:03 +01:00
|
|
|
return
|
2016-12-01 00:11:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var installed bool
|
2016-12-02 15:58:03 +01:00
|
|
|
dbS := dbList.Slice()
|
2017-01-07 04:01:33 +01:00
|
|
|
|
|
|
|
// BottomUp functions
|
|
|
|
initL := func(len int) int {
|
|
|
|
return len - 1
|
2016-12-02 15:58:03 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 04:01:33 +01:00
|
|
|
compL := func(len int, i int) bool {
|
2017-02-17 12:55:20 +01:00
|
|
|
return i > 0
|
2017-01-07 04:01:33 +01:00
|
|
|
}
|
2016-12-02 15:58:03 +01:00
|
|
|
|
2017-01-07 04:01:33 +01:00
|
|
|
finalL := func(i int) int {
|
|
|
|
return i - 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// TopDown functions
|
|
|
|
if util.SortMode == util.TopDown {
|
|
|
|
initL = func(len int) int {
|
|
|
|
return 0
|
2016-12-02 15:58:03 +01:00
|
|
|
}
|
|
|
|
|
2017-01-07 04:01:33 +01:00
|
|
|
compL = func(len int, i int) bool {
|
2017-02-17 12:55:20 +01:00
|
|
|
return i < len
|
2017-01-07 04:01:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
finalL = func(i int) int {
|
|
|
|
return i + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lenDbs := len(dbS)
|
|
|
|
for f := initL(lenDbs); compL(lenDbs, f); f = finalL(f) {
|
|
|
|
pkgS := dbS[f].PkgCache().Slice()
|
|
|
|
lenPkgs := len(pkgS)
|
|
|
|
|
|
|
|
for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) {
|
|
|
|
|
2017-02-18 16:29:40 +01:00
|
|
|
match := true
|
|
|
|
for _, pkgN := range pkgInputN {
|
|
|
|
if !(strings.Contains(pkgS[i].Name(), pkgN) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgN)) {
|
|
|
|
match = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if match {
|
|
|
|
installed = false
|
2016-12-02 15:58:03 +01:00
|
|
|
if r, _ := localDb.PkgByName(pkgS[i].Name()); r != nil {
|
2016-12-01 00:11:13 +01:00
|
|
|
installed = true
|
|
|
|
}
|
2017-02-18 16:29:40 +01:00
|
|
|
n++
|
2016-12-01 00:11:13 +01:00
|
|
|
|
2016-12-02 13:19:03 +01:00
|
|
|
s = append(s, Result{
|
2016-12-02 15:58:03 +01:00
|
|
|
Name: pkgS[i].Name(),
|
|
|
|
Description: pkgS[i].Description(),
|
|
|
|
Version: pkgS[i].Version(),
|
|
|
|
Repository: dbS[f].Name(),
|
|
|
|
Group: strings.Join(pkgS[i].Groups().Slice(), ","),
|
2016-12-01 00:11:13 +01:00
|
|
|
Installed: installed,
|
|
|
|
})
|
|
|
|
}
|
2016-12-02 15:58:03 +01:00
|
|
|
}
|
2016-12-01 00:11:13 +01:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//PrintSearch receives a RepoSearch type and outputs pretty text.
|
2017-02-05 05:15:44 +01:00
|
|
|
func (s Query) PrintSearch() {
|
2016-12-02 13:19:03 +01:00
|
|
|
for i, res := range s {
|
|
|
|
var toprint string
|
2017-01-05 17:13:52 +01:00
|
|
|
if util.SearchVerbosity == util.NumberMenu {
|
|
|
|
if util.SortMode == util.BottomUp {
|
2016-12-02 13:19:03 +01:00
|
|
|
toprint += fmt.Sprintf("%d ", len(s)-i-1)
|
|
|
|
} else {
|
|
|
|
toprint += fmt.Sprintf("%d ", i)
|
|
|
|
}
|
2017-01-05 17:13:52 +01:00
|
|
|
} else if util.SearchVerbosity == util.Minimal {
|
|
|
|
fmt.Println(res.Name)
|
|
|
|
continue
|
2016-12-01 00:11:13 +01:00
|
|
|
}
|
2016-12-02 13:19:03 +01:00
|
|
|
toprint += fmt.Sprintf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m",
|
|
|
|
res.Repository, res.Name, res.Version)
|
2016-12-01 00:11:13 +01:00
|
|
|
|
2016-12-02 13:19:03 +01:00
|
|
|
if len(res.Group) != 0 {
|
|
|
|
toprint += fmt.Sprintf("(%s) ", res.Group)
|
|
|
|
}
|
2016-12-01 00:11:13 +01:00
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
if res.Installed {
|
2016-12-02 13:19:03 +01:00
|
|
|
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
|
|
|
|
}
|
2016-12-01 00:11:13 +01:00
|
|
|
|
2016-12-02 13:19:03 +01:00
|
|
|
toprint += "\n" + res.Description
|
|
|
|
fmt.Println(toprint)
|
2016-12-01 00:11:13 +01:00
|
|
|
}
|
2016-12-02 13:19:03 +01:00
|
|
|
}
|
2016-12-01 00:11:13 +01:00
|
|
|
|
2016-12-01 01:36:58 +01:00
|
|
|
// PackageSlices separates an input slice into aur and repo slices
|
|
|
|
func PackageSlices(toCheck []string) (aur []string, repo []string, err error) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-01 01:36:58 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
dbList, err := h.SyncDbs()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range toCheck {
|
|
|
|
found := false
|
|
|
|
for _, db := range dbList.Slice() {
|
|
|
|
_, err = db.PkgByName(pkg)
|
|
|
|
if err == nil {
|
|
|
|
found = true
|
|
|
|
repo = append(repo, pkg)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
2017-02-17 12:55:20 +01:00
|
|
|
if _, errdb := dbList.PkgCachebyGroup(pkg); errdb == nil {
|
2016-12-09 03:12:13 +01:00
|
|
|
repo = append(repo, pkg)
|
|
|
|
} else {
|
|
|
|
aur = append(aur, pkg)
|
|
|
|
}
|
2016-12-01 01:36:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 03:13:17 +01:00
|
|
|
err = nil
|
2016-12-01 01:36:58 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-16 01:40:12 +01:00
|
|
|
// BuildDependencies finds packages, on the second run
|
|
|
|
// compares with a baselist and avoids searching those
|
|
|
|
func BuildDependencies(baselist []string) func(toCheck []string, isBaseList bool, last bool) (repo []string, notFound []string) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, _ := util.Conf.CreateHandle()
|
2016-12-15 21:50:22 +01:00
|
|
|
|
2016-12-16 01:40:12 +01:00
|
|
|
localDb, _ := h.LocalDb()
|
|
|
|
dbList, _ := h.SyncDbs()
|
2016-12-15 21:50:22 +01:00
|
|
|
|
|
|
|
f := func(c rune) bool {
|
|
|
|
return c == '>' || c == '<' || c == '=' || c == ' '
|
|
|
|
}
|
|
|
|
|
2016-12-16 01:40:12 +01:00
|
|
|
return func(toCheck []string, isBaseList bool, close bool) (repo []string, notFound []string) {
|
|
|
|
if close {
|
|
|
|
h.Release()
|
|
|
|
return
|
2016-12-15 21:50:22 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 01:40:12 +01:00
|
|
|
Loop:
|
|
|
|
for _, dep := range toCheck {
|
|
|
|
if !isBaseList {
|
|
|
|
for _, base := range baselist {
|
|
|
|
if base == dep {
|
|
|
|
continue Loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, erp := localDb.PkgCache().FindSatisfier(dep); erp == nil {
|
|
|
|
continue
|
|
|
|
} else if pkg, erp := dbList.FindSatisfier(dep); erp == nil {
|
|
|
|
repo = append(repo, pkg.Name())
|
|
|
|
} else {
|
|
|
|
field := strings.FieldsFunc(dep, f)
|
|
|
|
notFound = append(notFound, field[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2016-12-15 21:50:22 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 01:40:12 +01:00
|
|
|
// DepSatisfier receives a string slice, returns a slice of packages found in
|
|
|
|
// repos and one of packages not found in repos. Leaves out installed packages.
|
|
|
|
func DepSatisfier(toCheck []string) (repo []string, notFound []string, err error) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-01 00:11:13 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
localDb, err := h.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dbList, err := h.SyncDbs()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f := func(c rune) bool {
|
|
|
|
return c == '>' || c == '<' || c == '=' || c == ' '
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, dep := range toCheck {
|
2016-12-16 01:40:12 +01:00
|
|
|
if _, erp := localDb.PkgCache().FindSatisfier(dep); erp == nil {
|
2016-12-01 00:11:13 +01:00
|
|
|
continue
|
2016-12-16 01:40:12 +01:00
|
|
|
} else if pkg, erp := dbList.FindSatisfier(dep); erp == nil {
|
|
|
|
repo = append(repo, pkg.Name())
|
|
|
|
} else {
|
|
|
|
field := strings.FieldsFunc(dep, f)
|
|
|
|
notFound = append(notFound, field[0])
|
2016-12-01 00:11:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 23:47:05 +01:00
|
|
|
err = nil
|
2016-12-01 00:11:13 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-02 13:19:03 +01:00
|
|
|
// Install sends an install command to pacman with the pkgName slice
|
|
|
|
func Install(pkgName []string, flags []string) (err error) {
|
|
|
|
if len(pkgName) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
args := []string{"pacman", "-S"}
|
2016-12-05 01:26:01 +01:00
|
|
|
args = append(args, pkgName...)
|
2017-02-17 12:55:20 +01:00
|
|
|
args = append(args, flags...)
|
2016-12-05 01:26:01 +01:00
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
cmd := exec.Command("sudo", args...)
|
2016-12-15 21:50:22 +01:00
|
|
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
2016-12-05 01:26:01 +01:00
|
|
|
cmd.Run()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CleanRemove sends a full removal command to pacman with the pkgName slice
|
|
|
|
func CleanRemove(pkgName []string) (err error) {
|
|
|
|
if len(pkgName) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
args := []string{"pacman", "-Rnsc"}
|
2016-12-02 13:19:03 +01:00
|
|
|
args = append(args, pkgName...)
|
2017-05-01 03:23:26 +02:00
|
|
|
args = append(args, "--noutil.Conf.rm")
|
2016-12-02 13:19:03 +01:00
|
|
|
|
2017-02-17 12:55:20 +01:00
|
|
|
cmd := exec.Command("sudo", args...)
|
2016-12-15 21:50:22 +01:00
|
|
|
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
|
2016-12-02 13:19:03 +01:00
|
|
|
cmd.Run()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-01 00:11:13 +01:00
|
|
|
// ForeignPackages returns a map of foreign packages, with their version and date as values.
|
|
|
|
func ForeignPackages() (foreign map[string]*struct {
|
|
|
|
Version string
|
|
|
|
Date int64
|
|
|
|
}, n int, err error) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-01 00:11:13 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
localDb, err := h.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dbList, err := h.SyncDbs()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
foreign = make(map[string]*struct {
|
|
|
|
Version string
|
|
|
|
Date int64
|
|
|
|
})
|
|
|
|
// Find foreign packages in system
|
|
|
|
for _, pkg := range localDb.PkgCache().Slice() {
|
|
|
|
// Change to more effective method
|
|
|
|
found := false
|
|
|
|
for _, db := range dbList.Slice() {
|
|
|
|
_, err = db.PkgByName(pkg.Name())
|
|
|
|
if err == nil {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
foreign[pkg.Name()] = &struct {
|
|
|
|
Version string
|
|
|
|
Date int64
|
|
|
|
}{pkg.Version(), pkg.InstallDate().Unix()}
|
|
|
|
n++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2016-12-01 01:36:58 +01:00
|
|
|
|
|
|
|
// Statistics returns statistics about packages installed in system
|
2016-12-15 02:18:07 +01:00
|
|
|
func Statistics() (info struct {
|
2016-12-01 01:36:58 +01:00
|
|
|
Totaln int
|
|
|
|
Expln int
|
|
|
|
TotalSize int64
|
|
|
|
}, err error) {
|
|
|
|
var tS int64 // TotalSize
|
|
|
|
var nPkg int
|
|
|
|
var ePkg int
|
|
|
|
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-01 01:36:58 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
localDb, err := h.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:18:07 +01:00
|
|
|
for _, pkg := range localDb.PkgCache().Slice() {
|
2016-12-01 01:36:58 +01:00
|
|
|
tS += pkg.ISize()
|
|
|
|
nPkg++
|
|
|
|
if pkg.Reason() == 0 {
|
|
|
|
ePkg++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info = struct {
|
|
|
|
Totaln int
|
|
|
|
Expln int
|
|
|
|
TotalSize int64
|
|
|
|
}{
|
|
|
|
nPkg, ePkg, tS,
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2016-12-15 02:18:07 +01:00
|
|
|
|
|
|
|
// BiggestPackages prints the name of the ten biggest packages in the system.
|
|
|
|
func BiggestPackages() {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-15 02:18:07 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
localDb, err := h.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgCache := localDb.PkgCache()
|
|
|
|
pkgS := pkgCache.SortBySize().Slice()
|
|
|
|
|
|
|
|
if len(pkgS) < 10 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
fmt.Printf("%s: \x1B[0;33m%dMB\x1B[0m\n", pkgS[i].Name(), pkgS[i].ISize()/(1024*1024))
|
|
|
|
}
|
|
|
|
// Could implement size here as well, but we just want the general idea
|
|
|
|
}
|
2016-12-17 03:29:52 +01:00
|
|
|
|
|
|
|
// HangingPackages returns a list of packages installed as deps
|
|
|
|
// and unneeded by the system
|
|
|
|
func HangingPackages() (hanging []string, err error) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-17 03:29:52 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
localDb, err := h.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f := func(pkg alpm.Package) error {
|
|
|
|
if pkg.Reason() != alpm.PkgReasonDepend {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
requiredby := pkg.ComputeRequiredBy()
|
|
|
|
if len(requiredby) == 0 {
|
|
|
|
hanging = append(hanging, pkg.Name())
|
|
|
|
fmt.Printf("%s: \x1B[0;33m%dMB\x1B[0m\n", pkg.Name(), pkg.ISize()/(1024*1024))
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = localDb.PkgCache().ForEach(f)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SliceHangingPackages returns a list of packages installed as deps
|
|
|
|
// and unneeded by the system from a provided list of package names.
|
|
|
|
func SliceHangingPackages(pkgS []string) (hanging []string) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2016-12-17 03:29:52 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
localDb, err := h.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
big:
|
|
|
|
for _, pkgName := range pkgS {
|
|
|
|
for _, hangN := range hanging {
|
|
|
|
if hangN == pkgName {
|
|
|
|
continue big
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg, err := localDb.PkgByName(pkgName)
|
|
|
|
if err == nil {
|
|
|
|
if pkg.Reason() != alpm.PkgReasonDepend {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
requiredby := pkg.ComputeRequiredBy()
|
|
|
|
if len(requiredby) == 0 {
|
|
|
|
hanging = append(hanging, pkgName)
|
|
|
|
fmt.Printf("%s: \x1B[0;33m%dMB\x1B[0m\n", pkg.Name(), pkg.ISize()/(1024*1024))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2017-02-15 02:50:26 +01:00
|
|
|
|
|
|
|
// GetPkgbuild downloads pkgbuild from the ABS.
|
|
|
|
func GetPkgbuild(pkgN string, path string) (err error) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2017-02-15 02:50:26 +01:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
dbList, err := h.SyncDbs()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, db := range dbList.Slice() {
|
|
|
|
pkg, err := db.PkgByName(pkgN)
|
|
|
|
if err == nil {
|
|
|
|
var url string
|
|
|
|
if db.Name() == "core" || db.Name() == "extra" {
|
|
|
|
url = "https://projects.archlinux.org/svntogit/packages.git/snapshot/packages/" + pkg.Name() + ".tar.gz"
|
|
|
|
} else if db.Name() == "community" {
|
|
|
|
url = "https://projects.archlinux.org/svntogit/community.git/snapshot/community-packages/" + pkg.Name() + ".tar.gz"
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("Not in standard repositories")
|
|
|
|
}
|
|
|
|
fmt.Printf("\x1b[1;32m==>\x1b[1;33m %s \x1b[1;32mfound in ABS.\x1b[0m\n", pkgN)
|
2017-02-17 12:55:20 +01:00
|
|
|
errD := util.DownloadAndUnpack(url, path, true)
|
|
|
|
return errD
|
2017-02-15 02:50:26 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-17 12:55:20 +01:00
|
|
|
return fmt.Errorf("package not found")
|
2017-02-15 02:50:26 +01:00
|
|
|
}
|
2017-04-09 23:17:10 +02:00
|
|
|
|
|
|
|
//CreatePackageList appends Repo packages to completion cache
|
|
|
|
func CreatePackageList(out *os.File) (err error) {
|
2017-05-01 03:23:26 +02:00
|
|
|
h, err := util.Conf.CreateHandle()
|
2017-04-09 23:17:10 +02:00
|
|
|
defer h.Release()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
dbList, err := h.SyncDbs()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p := func(pkg alpm.Package) error {
|
|
|
|
fmt.Print(pkg.Name())
|
|
|
|
out.WriteString(pkg.Name())
|
|
|
|
if util.Shell == "fish" {
|
|
|
|
fmt.Print("\t" + pkg.DB().Name() + "\n")
|
|
|
|
out.WriteString("\t" + pkg.DB().Name() + "\n")
|
|
|
|
} else {
|
|
|
|
fmt.Print("\n")
|
|
|
|
out.WriteString("\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
f := func(db alpm.Db) error {
|
|
|
|
db.PkgCache().ForEach(p)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
dbList.ForEach(f)
|
|
|
|
return nil
|
|
|
|
}
|