2017-08-02 19:24:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
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",
|
2017-08-04 11:26:53 +02:00
|
|
|
config.TarBin+" --strip-components 2 --include='*/"+fileName[:len(fileName)-7]+"/trunk/' -xf "+tarLocation+" -C "+path).Run()
|
2017-08-02 19:24:03 +02:00
|
|
|
os.Rename(path+"trunk", path+fileName[:len(fileName)-7]) // kurwa
|
|
|
|
} else {
|
2017-08-04 11:26:53 +02:00
|
|
|
err = exec.Command(config.TarBin, "-xf", tarLocation, "-C", path).Run()
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:41:25 +01:00
|
|
|
func getPkgbuilds(pkgs []string) error {
|
2018-02-17 18:44:30 +01:00
|
|
|
//possibleAurs := make([]string, 0, 0)
|
2017-08-02 19:24:03 +02:00
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
2018-02-17 18:44:30 +01:00
|
|
|
return err
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
wd = wd + "/"
|
|
|
|
|
2018-02-17 18:44:30 +01:00
|
|
|
missing, err := getPkgbuildsfromABS(pkgs, wd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-17 18:44:30 +01:00
|
|
|
err = getPkgbuildsfromAUR(missing, wd)
|
|
|
|
return err
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetPkgbuild downloads pkgbuild from the ABS.
|
2018-02-17 18:44:30 +01:00
|
|
|
func getPkgbuildsfromABS(pkgs []string, path string) (missing []string, err error) {
|
2017-10-18 04:38:19 +02:00
|
|
|
dbList, err := alpmHandle.SyncDbs()
|
2017-08-02 19:24:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:41:25 +01:00
|
|
|
nextPkg:
|
2018-02-17 18:44:30 +01:00
|
|
|
for _, pkgN := range pkgs {
|
|
|
|
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.Base() + ".tar.gz"
|
|
|
|
} else if db.Name() == "community" {
|
|
|
|
url = "https://projects.archlinux.org/svntogit/community.git/snapshot/community-packages/" + pkg.Base() + ".tar.gz"
|
|
|
|
} else {
|
|
|
|
fmt.Println(pkgN + " not in standard repositories")
|
|
|
|
}
|
|
|
|
|
|
|
|
errD := downloadAndUnpack(url, path, true)
|
|
|
|
if errD != nil {
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(yellow(pkg.Name())), bold(green(errD.Error())))
|
2018-02-17 18:44:30 +01:00
|
|
|
}
|
2018-02-21 09:41:25 +01:00
|
|
|
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(green(arrow)), bold(green("Downloaded")), bold(yellow(pkg.Name())), bold(green("from ABS")))
|
2018-02-17 18:44:30 +01:00
|
|
|
continue nextPkg
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-17 18:44:30 +01:00
|
|
|
|
|
|
|
missing = append(missing, pkgN)
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-02-17 18:44:30 +01:00
|
|
|
|
|
|
|
return
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetPkgbuild downloads pkgbuild from the AUR.
|
2018-02-17 18:44:30 +01:00
|
|
|
func getPkgbuildsfromAUR(pkgs []string, dir string) (err error) {
|
|
|
|
aq, err := aurInfo(pkgs)
|
2017-08-02 19:24:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-02-17 18:44:30 +01:00
|
|
|
for _, pkg := range aq {
|
|
|
|
downloadAndUnpack(baseURL+aq[0].URLPath, dir, false)
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(green(arrow)), bold(green("Downloaded")), bold(yellow(pkg.Name)), bold(green("from AUR")))
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|