wireguard.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package config
  2. import (
  3. "encoding/json"
  4. "goseg/structs"
  5. "os"
  6. "path/filepath"
  7. )
  8. // write a conf to disk
  9. func CreateDefaultWGConf() error {
  10. conf := Conf()
  11. releaseChannel := conf.UpdateBranch
  12. wgRepo := VersionInfo.Groundseg.Latest.Wireguard.Repo
  13. amdHash := VersionInfo.Groundseg.Latest.Wireguard.Amd64Sha256
  14. armHash := VersionInfo.Groundseg.Latest.Wireguard.Arm64Sha256
  15. defaultConfig := structs.WgConfig{
  16. WireguardName: "wireguard",
  17. WireguardVersion: releaseChannel,
  18. Repo: wgRepo,
  19. Amd64Sha256: amdHash,
  20. Arm64Sha256: armHash,
  21. CapAdd: []string{"NET_ADMIN", "SYS_MODULE"},
  22. Volumes: []string{"/lib/modules:/lib/modules"},
  23. Sysctls: struct {
  24. NetIpv4ConfAllSrcValidMark int `json:"net.ipv4.conf.all.src_valid_mark"`
  25. }{
  26. NetIpv4ConfAllSrcValidMark: 1,
  27. },
  28. }
  29. path := filepath.Join(BasePath, "settings", "wireguard.json")
  30. if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
  31. return err
  32. }
  33. file, err := os.Create(path)
  34. if err != nil {
  35. return err
  36. }
  37. defer file.Close()
  38. encoder := json.NewEncoder(file)
  39. encoder.SetIndent("", " ")
  40. if err := encoder.Encode(&defaultConfig); err != nil {
  41. return err
  42. }
  43. return nil
  44. }