|
@@ -1,9 +1,16 @@
|
|
package util
|
|
package util
|
|
|
|
|
|
-import "fmt"
|
|
|
|
|
|
+import (
|
|
|
|
+ "fmt"
|
|
|
|
+ "io"
|
|
|
|
+ "net/http"
|
|
|
|
+ "os"
|
|
|
|
+ "os/exec"
|
|
|
|
+ "strings"
|
|
|
|
+)
|
|
|
|
|
|
// TarBin describes the default installation point of tar command.
|
|
// 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.
|
|
// MakepkgBin describes the default installation point of makepkg command.
|
|
const MakepkgBin string = "/usr/bin/makepkg"
|
|
const MakepkgBin string = "/usr/bin/makepkg"
|
|
@@ -57,3 +64,55 @@ func ContinueTask(s string, def string) (cont bool) {
|
|
|
|
|
|
return true
|
|
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
|
|
|
|
+}
|