Skip to content

Commit

Permalink
fix: exec command use
Browse files Browse the repository at this point in the history
  • Loading branch information
pupilcc committed Jan 9, 2024
1 parent 2f0b7f7 commit 6b2046e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions middleware/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"go.uber.org/zap"
"os"
"os/exec"
"os/user"
"path/filepath"
)

var usr, _ = user.Current()

func InitAcme() {
ca()
email()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 6b2046e

Please sign in to comment.