@cryptotaxi247 / kubo / commits / 8a8730fa4

repo: detect OS variant, for now only linux-musl

License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>

Lars Gierth committed Jul 10, 2016 at 03:53 UTC 8a8730fa4032942ec5181341104d2e75135af05c
1 file changed +36 -3
repo/fsrepo/migrations/migrations.go
+36 -3
@@ -2,6 +2,7 @@ package mfsr
2
3 import (
4 "bufio"
5 + "bytes"
6 "fmt"
7 "io"
8 "io/ioutil"
@@ -44,7 +45,7 @@ func RunMigration(newv int) error {
45
46 err = verifyMigrationSupportsVersion(loc, newv)
47 if err != nil {
47 - return fmt.Errorf("could not find migrations binary that supports version %d", newv)
48 + return fmt.Errorf("no migration binary found that supports version %d - %s", newv, err)
49 }
50
51 migrateBin = loc
@@ -104,7 +105,7 @@ func verifyMigrationSupportsVersion(fsrbin string, vn int) error {
105 return nil
106 }
107
107 - return fmt.Errorf("migrations binary doesnt support version %d", vn)
108 + return fmt.Errorf("migrations binary doesnt support version %d: %s", vn, fsrbin)
109 }
110
111 func migrationsVersion(bin string) (int, error) {
@@ -204,7 +205,11 @@ func GetBinaryForVersion(distname, binnom, root, vers, out string) error {
205 default:
206 archive = "tar.gz"
207 }
207 - finame := fmt.Sprintf("%s_%s_%s-%s.%s", distname, vers, runtime.GOOS, runtime.GOARCH, archive)
208 + osv, err := osWithVariant()
209 + if err != nil {
210 + return err
211 + }
212 + finame := fmt.Sprintf("%s_%s_%s-%s.%s", distname, vers, osv, runtime.GOARCH, archive)
213 distpath := fmt.Sprintf("%s/%s/%s/%s", root, distname, vers, finame)
214
215 data, err := httpFetch(distpath)
@@ -226,3 +231,31 @@ func GetBinaryForVersion(distname, binnom, root, vers, out string) error {
231
232 return unpackArchive(distname, binnom, arcpath, out, archive)
233 }
234 +
235 +func osWithVariant() (string, error) {
236 + if runtime.GOOS != "linux" {
237 + return runtime.GOOS, nil
238 + }
239 +
240 + bin, err := exec.LookPath(filepath.Base(os.Args[0]))
241 + if err != nil {
242 + return "", fmt.Errorf("failed to resolve go-ipfs: %s", err)
243 + }
244 +
245 + cmd := exec.Command("ldd", bin)
246 + buf := new(bytes.Buffer)
247 + cmd.Stdout = buf
248 + err = cmd.Run()
249 + if err != nil {
250 + return "", fmt.Errorf("failed to run ldd: %s", err)
251 + }
252 +
253 + scan := bufio.NewScanner(buf)
254 + for scan.Scan() {
255 + if strings.Contains(scan.Text(), "libc") && strings.Contains(scan.Text(), "musl") {
256 + return "linux-musl", nil
257 + }
258 + }
259 +
260 + return "linux", nil
261 +}