acme_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package test
  2. import (
  3. "fmt"
  4. "github.com/0xJacky/Nginx-UI/tool"
  5. "io/ioutil"
  6. "log"
  7. "os"
  8. "os/exec"
  9. "strings"
  10. "testing"
  11. )
  12. func TestAcme(t *testing.T) {
  13. const acmePath = "/usr/local/acme.sh"
  14. _, err := os.Stat(acmePath)
  15. log.Println("[found] acme.sh ", acmePath)
  16. if err != nil {
  17. log.Println(err)
  18. if os.IsNotExist(err) {
  19. log.Println("[not found] acme.sh, installing...")
  20. out, err := exec.Command("curl", "-o", "../tmp/acme.sh", "https://get.acme.sh").
  21. CombinedOutput()
  22. if err != nil {
  23. log.Println(err)
  24. return
  25. }
  26. fmt.Printf("%s\n", out)
  27. log.Println("[acme.sh] downloaded")
  28. file, _ := ioutil.ReadFile("../tmp/acme.sh")
  29. fileString := string(file)
  30. fileString = strings.Replace(fileString, "https://raw.githubusercontent.com",
  31. "https://ghproxy.com/https://raw.githubusercontent.com", -1)
  32. _ = ioutil.WriteFile("../tmp/acme.sh", []byte(fileString), 0644)
  33. out, err = exec.Command("bash", "../tmp/acme.sh",
  34. "install",
  35. "--log",
  36. "--home", "/usr/local/acme.sh",
  37. "--cert-home", tool.GetNginxConfPath("ssl")).
  38. CombinedOutput()
  39. if err != nil {
  40. log.Println(err)
  41. return
  42. }
  43. fmt.Printf("%s\n", out)
  44. }
  45. }
  46. }