From b1564cfb0d48744c5156d59d58ce9b33c09bef91 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sat, 1 Jun 2019 14:41:10 +0100 Subject: [PATCH] truststore_linux: autodetect CertutilInstallHelp --- truststore_linux.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/truststore_linux.go b/truststore_linux.go index ac1cf23..dbdd8cf 100644 --- a/truststore_linux.go +++ b/truststore_linux.go @@ -16,15 +16,23 @@ import ( ) var ( - FirefoxProfile = os.Getenv("HOME") + "/.mozilla/firefox/*" - CertutilInstallHelp = `apt install libnss3-tools" or "yum install nss-tools" or "zypper install mozilla-nss-tools` - NSSBrowsers = "Firefox and/or Chrome/Chromium" + FirefoxProfile = os.Getenv("HOME") + "/.mozilla/firefox/*" + NSSBrowsers = "Firefox and/or Chrome/Chromium" SystemTrustFilename string SystemTrustCommand []string + CertutilInstallHelp string ) func init() { + switch { + case binaryExists("apt"): + CertutilInstallHelp = "apt install libnss3-tools" + case binaryExists("yum"): + CertutilInstallHelp = "yum install nss-tools" + case binaryExists("zypper"): + CertutilInstallHelp = "zypper install mozilla-nss-tools" + } if pathExists("/etc/pki/ca-trust/source/anchors/") { SystemTrustFilename = "/etc/pki/ca-trust/source/anchors/%s.pem" SystemTrustCommand = []string{"update-ca-trust", "extract"} @@ -51,6 +59,11 @@ func pathExists(path string) bool { return err == nil } +func binaryExists(name string) bool { + _, err := exec.LookPath(name) + return err == nil +} + func (m *mkcert) systemTrustFilename() string { return fmt.Sprintf(SystemTrustFilename, strings.Replace(m.caUniqueName(), " ", "_", -1)) }