Added -G --getpkgbuild. Resolves #6

This commit is contained in:
Jguer 2017-02-15 01:50:26 +00:00
parent 1f4bb8eb16
commit 27759a589f
9 changed files with 147 additions and 52 deletions

View file

@ -26,6 +26,10 @@ Yay was created with a few objectives in mind and based on the design of yaourt
### Changelog
#### 1.100
- Added manpage
- Added -G to get pkgbuild from the AUR or ABS.
#### 1.91
- `--downtop` has been replaced with `--bottomup` (as is logical)
- `yay -Ssq` and `yay -Sqs` now displays AUR packages with less information

View file

@ -29,7 +29,6 @@ func narrowSearch(aq aur.Query, pq pac.Query, narrow []string) (raq aur.Query, r
if match {
rpq = append(rpq, pr)
}
}
for _, ar := range aq {
@ -354,3 +353,20 @@ func CleanDependencies(pkgs []string) error {
return err
}
// GetPkgbuild gets the pkgbuild of the package 'pkg' trying the ABS first and then the AUR trying the ABS first and then the AUR.
func GetPkgbuild(pkg string) (err error) {
wd, err := os.Getwd()
if err != nil {
return
}
wd = wd + "/"
err = pac.GetPkgbuild(pkg, wd)
if err == nil {
return
}
err = aur.GetPkgbuild(pkg, wd)
return
}

View file

@ -72,3 +72,19 @@ func Upgrade(flags []string) error {
return nil
}
// GetPkgbuild downloads pkgbuild from the AUR.
func GetPkgbuild(pkgN string, dir string) (err error) {
aq, numaq, err := Info(pkgN)
if err != nil {
return err
}
if numaq == 0 {
return fmt.Errorf("no results")
}
fmt.Printf("\x1b[1;32m==>\x1b[1;33m %s \x1b[1;32mfound in AUR.\x1b[0m\n", pkgN)
util.DownloadAndUnpack(BaseURL+aq[0].URLPath, dir, false)
return
}

View file

@ -99,13 +99,13 @@ func (a *Result) Install(flags []string) (finalmdeps []string, err error) {
dir := util.BaseDir + a.PackageBase + "/"
if _, err = os.Stat(dir); os.IsNotExist(err) {
if err = a.setupWorkspace(); err != nil {
if err = util.DownloadAndUnpack(BaseURL+a.URLPath, util.BaseDir, false); err != nil {
return
}
} else {
if !util.ContinueTask("Directory exists. Clean Build?", "yY") {
os.RemoveAll(util.BaseDir + a.PackageBase)
if err = a.setupWorkspace(); err != nil {
if err = util.DownloadAndUnpack(BaseURL+a.URLPath, util.BaseDir, false); err != nil {
return
}
}
@ -247,27 +247,3 @@ func RemoveMakeDeps(depS []string) (err error) {
return
}
func (a *Result) setupWorkspace() (err error) {
// No need to use filepath.separators because it won't run on inferior platforms
err = os.MkdirAll(util.BaseDir+"builds", 0755)
if err != nil {
fmt.Println(err)
return
}
tarLocation := util.BaseDir + a.PackageBase + ".tar.gz"
defer os.Remove(util.BaseDir + a.PackageBase + ".tar.gz")
err = downloadFile(tarLocation, BaseURL+a.URLPath)
if err != nil {
return
}
err = exec.Command(util.TarBin, "-xf", tarLocation, "-C", util.BaseDir).Run()
if err != nil {
return
}
return
}

View file

@ -2,7 +2,6 @@ package aur
import (
"encoding/json"
"io"
"net/http"
"os"
)
@ -29,23 +28,3 @@ func getJSON(url string, target interface{}) error {
return json.NewDecoder(r.Body).Decode(target)
}
func downloadFile(filepath string, url string) (err error) {
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
// Writer the body to file
_, err = io.Copy(out, resp.Body)
return err
}

View file

@ -22,8 +22,9 @@ func usage() {
yay {-U --upgrade} [options] <file(s)>
New operations:
yay -Qstats displays system information
yay -Cd remove unneeded dependencies
yay -Qstats displays system information
yay -Cd remove unneeded dependencies
yay -G [package(s)] get pkgbuild from ABS or AUR
New options:
--topdown shows repository's packages first and then aur's
@ -82,6 +83,13 @@ func main() {
switch op {
case "-Cd":
err = yay.CleanDependencies(pkgs)
case "-G":
for _, pkg := range pkgs {
err = yay.GetPkgbuild(pkg)
if err != nil {
fmt.Println(pkg+":", err)
}
}
case "-Qstats":
err = yay.LocalStatistics(version)
case "-Ss", "-Ssq", "-Sqs":

View file

@ -525,3 +525,35 @@ big:
}
return
}
// GetPkgbuild downloads pkgbuild from the ABS.
func GetPkgbuild(pkgN string, path string) (err error) {
h, err := conf.CreateHandle()
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)
util.DownloadAndUnpack(url, path, true)
return nil
}
}
return fmt.Errorf("Package not found.")
}

View file

@ -1,9 +1,16 @@
package util
import "fmt"
import (
"fmt"
"io"
"net/http"
"os"
"os/exec"
"strings"
)
// TarBin describes the default installation point of tar command.
const TarBin string = "/usr/bin/tar"
const TarBin string = "/usr/bin/bsdtar"
// MakepkgBin describes the default installation point of makepkg command.
const MakepkgBin string = "/usr/bin/makepkg"
@ -57,3 +64,55 @@ func ContinueTask(s string, def string) (cont bool) {
return true
}
func downloadFile(path string, url string) (err error) {
// Create the file
out, err := os.Create(path)
if err != nil {
return err
}
defer out.Close()
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
// Writer the body to file
_, err = io.Copy(out, resp.Body)
return err
}
// DownloadAndUnpack downloads url tgz and extracts to path.
func DownloadAndUnpack(url string, path string, trim bool) (err error) {
err = os.MkdirAll(path, 0755)
if err != nil {
return
}
tokens := strings.Split(url, "/")
fileName := tokens[len(tokens)-1]
tarLocation := path + fileName
defer os.Remove(tarLocation)
err = downloadFile(tarLocation, url)
if err != nil {
return
}
if trim {
err = exec.Command("/bin/sh", "-c",
TarBin+" --strip-components 2 --include='*/"+fileName[:len(fileName)-7]+"/trunk/' -xf "+tarLocation+" -C "+path).Run()
os.Rename(path+"trunk", path+fileName[:len(fileName)-7]) // kurwa
} else {
err = exec.Command(TarBin, "-xf", tarLocation, "-C", path).Run()
}
if err != nil {
return
}
return
}

5
yay.8
View file

@ -17,6 +17,11 @@ yay is a pacman wrapper with AUR support. It passes options to makepkg and pacma
Remove uneeded dependencies\&.
.RE
.PP
\fB\-G\fR
.RS 4
Downloads PKGBUILD from ABS or AUR.
.RE
.PP
\fB\-Qstats\fR
.RS 4
Displays information about installed packages and system health. If there are orphaned or out-of-date packages, warnings will be displayed\&.