system.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package service
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "github.com/IceWhaleTech/CasaOS/pkg/config"
  6. command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
  7. "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
  8. )
  9. type SystemService interface {
  10. UpSystemConfig(str string, widget string)
  11. UpdateSystemVersion(version string)
  12. GetSystemConfigDebug() []string
  13. GetCasaOSLogs(lineNumber int) string
  14. UpdateAssist()
  15. UpSystemPort(port string)
  16. GetTimeZone() string
  17. }
  18. type systemService struct {
  19. log loger.OLog
  20. }
  21. func (s *systemService) UpdateSystemVersion(version string) {
  22. //command2.OnlyExec(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
  23. //s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
  24. s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/tools.sh ;update " + version))
  25. //s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
  26. }
  27. func (s *systemService) UpdateAssist() {
  28. s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/assist.sh"))
  29. }
  30. func (s *systemService) GetTimeZone() string {
  31. return command2.ExecResultStr("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetTimeZone")
  32. }
  33. func (s *systemService) GetSystemConfigDebug() []string {
  34. return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetSysInfo")
  35. }
  36. func (s *systemService) UpSystemConfig(str string, widget string) {
  37. if len(str) > 0 && str != config.SystemConfigInfo.ConfigStr {
  38. config.Cfg.Section("system").Key("ConfigStr").SetValue(str)
  39. config.SystemConfigInfo.ConfigStr = str
  40. }
  41. if len(widget) > 0 && widget != config.SystemConfigInfo.WidgetList {
  42. config.Cfg.Section("system").Key("WidgetList").SetValue(widget)
  43. config.SystemConfigInfo.WidgetList = widget
  44. }
  45. config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
  46. }
  47. func (s *systemService) UpSystemPort(port string) {
  48. if len(port) > 0 && port != config.ServerInfo.HttpPort {
  49. config.Cfg.Section("server").Key("HttpPort").SetValue(port)
  50. config.ServerInfo.HttpPort = port
  51. }
  52. config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
  53. }
  54. func (s *systemService) GetCasaOSLogs(lineNumber int) string {
  55. file, err := os.Open(s.log.Path())
  56. if err != nil {
  57. return err.Error()
  58. }
  59. defer file.Close()
  60. content, err := ioutil.ReadAll(file)
  61. if err != nil {
  62. return err.Error()
  63. }
  64. return string(content)
  65. }
  66. func NewSystemService(log loger.OLog) SystemService {
  67. return &systemService{log: log}
  68. }