mc.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package config
  2. import (
  3. "encoding/json"
  4. "goseg/defaults"
  5. "goseg/structs"
  6. "os"
  7. "path/filepath"
  8. )
  9. // write a hardcoded default conf to disk
  10. func CreateDefaultMcConf() error {
  11. defaultConfig := defaults.McConfig
  12. path := filepath.Join(BasePath, "settings", "mc.json")
  13. if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
  14. return err
  15. }
  16. file, err := os.Create(path)
  17. if err != nil {
  18. return err
  19. }
  20. defer file.Close()
  21. encoder := json.NewEncoder(file)
  22. encoder.SetIndent("", " ")
  23. if err := encoder.Encode(&defaultConfig); err != nil {
  24. return err
  25. }
  26. return nil
  27. }
  28. // write a conf to disk from version server info
  29. func UpdateMcConf() error {
  30. conf := Conf()
  31. releaseChannel := conf.UpdateBranch
  32. mcRepo := VersionInfo.Miniomc.Repo
  33. amdHash := VersionInfo.Miniomc.Amd64Sha256
  34. armHash := VersionInfo.Miniomc.Arm64Sha256
  35. newConfig := structs.McConfig{
  36. McName: "minio_client",
  37. McVersion: releaseChannel,
  38. Repo: mcRepo,
  39. Amd64Sha256: amdHash,
  40. Arm64Sha256: armHash,
  41. }
  42. path := filepath.Join(BasePath, "settings", "mc.json")
  43. if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
  44. return err
  45. }
  46. file, err := os.Create(path)
  47. if err != nil {
  48. return err
  49. }
  50. defer file.Close()
  51. encoder := json.NewEncoder(file)
  52. encoder.SetIndent("", " ")
  53. if err := encoder.Encode(&newConfig); err != nil {
  54. return err
  55. }
  56. return nil
  57. }