diff --git a/middleware/acme.go b/middleware/acme.go index 8299046..aea99f5 100644 --- a/middleware/acme.go +++ b/middleware/acme.go @@ -5,8 +5,12 @@ import ( "go.uber.org/zap" "os" "os/exec" + "os/user" + "path/filepath" ) +var usr, _ = user.Current() + func InitAcme() { ca() email() @@ -16,7 +20,7 @@ func InitAcme() { func ca() { logger := GetLogger() ca := os.Getenv("ACME_CA") - cmd := exec.Command("~/.acme.sh/acme.sh --set-default-ca --server", ca) + cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--set-default-ca", "--server", ca) cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout err := cmd.Start() @@ -28,7 +32,7 @@ func ca() { func email() { logger := GetLogger() email := os.Getenv("ACME_EMAIL") - cmd := exec.Command("~/.acme.sh/acme.sh --update-account --email", email) + cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--update-account", "--email", email) cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout err := cmd.Start() @@ -42,7 +46,7 @@ func Issue(name string) { produce := os.Getenv("ACME_PRODUCE") alias := os.Getenv("ACME_ALIAS") - cmd := exec.Command("~/.acme.sh/acme.sh --issue", "--dns", produce, "-d", name, "--challenge-alias", alias) + cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--issue", "--dns", produce, "-d", name, "--challenge-alias", alias) cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout err := cmd.Start() @@ -53,7 +57,7 @@ func Issue(name string) { func Install(name string, id string) { logger := GetLogger() - cmd := exec.Command("~/.acme.sh/acme.sh --install-cert", "-d", name, "--key-file", service.CertPath+id+".key", "--fullchain-file", service.CertPath+id+".crt") + cmd := exec.Command(filepath.Join(usr.HomeDir, ".acme.sh/acme.sh"), "--install-cert", "-d", name, "--key-file", service.CertPath+id+".key", "--fullchain-file", service.CertPath+id+".crt") cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout err := cmd.Start() @@ -66,7 +70,9 @@ func export() { logger := GetLogger() account := os.Getenv("ACME_ACCOUNT") token := os.Getenv("ACME_TOKEN") - cmd := exec.Command("export CF_EMAIL=%s && export CF_KEY=%s", account, token) + cmd := exec.Command("env") + cmd.Env = append(cmd.Env, "CF_EMAIL="+account) + cmd.Env = append(cmd.Env, "CF_KEY="+token) cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout err := cmd.Start()