system.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }
  15. type systemService struct {
  16. log loger.OLog
  17. }
  18. func (s *systemService) UpdateSystemVersion(version string) {
  19. //command2.OnlyExec(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
  20. //s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
  21. s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/tools.sh ;update " + version))
  22. //s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
  23. }
  24. func (s *systemService) GetSystemConfigDebug() []string {
  25. return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetSysInfo")
  26. }
  27. func (s *systemService) UpSystemConfig(str string, widget string) {
  28. if len(str) > 0 && str != config.SystemConfigInfo.ConfigStr {
  29. config.Cfg.Section("system").Key("ConfigStr").SetValue(str)
  30. config.SystemConfigInfo.ConfigStr = str
  31. }
  32. if len(widget) > 0 && widget != config.SystemConfigInfo.WidgetList {
  33. config.Cfg.Section("system").Key("WidgetList").SetValue(widget)
  34. config.SystemConfigInfo.WidgetList = widget
  35. }
  36. config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
  37. }
  38. func (s *systemService) GetCasaOSLogs(lineNumber int) string {
  39. file, err := os.Open(s.log.Path())
  40. if err != nil {
  41. return err.Error()
  42. }
  43. defer file.Close()
  44. content, err := ioutil.ReadAll(file)
  45. if err != nil {
  46. return err.Error()
  47. }
  48. return string(content)
  49. }
  50. func NewSystemService(log loger.OLog) SystemService {
  51. return &systemService{log: log}
  52. }