Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify if installing on linux with musl library #246

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func NewInstaller(opts ...installerConfig) (*Installer, error) {
log.Println("[WARN] amd64 architecture not detected, defaulting to x86_64. Behaviour may be undefined")
}

// Only perform a check if current OS is linux
if runtime.GOOS == "linux" {
err := i.checkMusl()
if err != nil {
return nil, err
}
}

return i, nil
}

Expand Down Expand Up @@ -311,6 +319,23 @@ func checkVersion(lib, version, versionRange string) error {
return fmt.Errorf("version %s of %s does not match constraint %s", version, lib, versionRange)
}

// checkMusl checks if the OS uses musl library instead of glibc
func (i *Installer) checkMusl() error {
lddPath, err := exec.LookPath("ldd")
if err != nil {
return fmt.Errorf("could not find ldd in environment path")
}

cmd := exec.Command(lddPath, "/bin/echo")
out, err := cmd.CombinedOutput()

if strings.Contains(string(out), "musl") {
log.Println("[WARN] Usage of musl library is known to cause problems, prefer using glibc instead.")
}

return err
}

// download template structure: "https://github.com/pact-foundation/pact-reference/releases/download/PACKAGE-vVERSION/LIBNAME-OS-ARCH.EXTENSION.gz"
var downloadTemplate = "https://github.com/pact-foundation/pact-reference/releases/download/%s-v%s/%s-%s-%s.%s.gz"

Expand Down