2021-09-26 02:35:02 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2021-10-27 11:03:59 +00:00
|
|
|
"io/ioutil"
|
2021-10-27 09:27:46 +00:00
|
|
|
"os"
|
|
|
|
|
2021-09-27 06:17:36 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
|
|
|
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
2021-09-26 02:35:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SystemService interface {
|
2021-10-15 03:43:41 +00:00
|
|
|
UpSystemConfig(str string, widget string)
|
2021-09-26 02:35:02 +00:00
|
|
|
UpdateSystemVersion(version string)
|
|
|
|
GetSystemConfigDebug() []string
|
2021-10-27 09:27:46 +00:00
|
|
|
GetCasaOSLogs(lineNumber int) string
|
2021-12-06 09:08:36 +00:00
|
|
|
UpdateAssist()
|
|
|
|
UpSystemPort(port string)
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
type systemService struct {
|
2021-09-27 06:17:36 +00:00
|
|
|
log loger.OLog
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *systemService) UpdateSystemVersion(version string) {
|
2021-09-27 06:17:36 +00:00
|
|
|
//command2.OnlyExec(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
|
|
|
//s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
|
|
|
|
s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/tools.sh ;update " + version))
|
|
|
|
//s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2021-12-06 09:08:36 +00:00
|
|
|
func (s *systemService) UpdateAssist() {
|
|
|
|
s.log.Error(command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/assist.sh"))
|
|
|
|
}
|
2021-09-26 02:35:02 +00:00
|
|
|
func (s *systemService) GetSystemConfigDebug() []string {
|
|
|
|
return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetSysInfo")
|
|
|
|
}
|
2021-10-15 03:43:41 +00:00
|
|
|
func (s *systemService) UpSystemConfig(str string, widget string) {
|
|
|
|
if len(str) > 0 && str != config.SystemConfigInfo.ConfigStr {
|
|
|
|
config.Cfg.Section("system").Key("ConfigStr").SetValue(str)
|
|
|
|
config.SystemConfigInfo.ConfigStr = str
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2021-10-15 03:43:41 +00:00
|
|
|
if len(widget) > 0 && widget != config.SystemConfigInfo.WidgetList {
|
|
|
|
config.Cfg.Section("system").Key("WidgetList").SetValue(widget)
|
|
|
|
config.SystemConfigInfo.WidgetList = widget
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2021-10-27 11:03:59 +00:00
|
|
|
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2021-12-06 09:08:36 +00:00
|
|
|
func (s *systemService) UpSystemPort(port string) {
|
|
|
|
if len(port) > 0 && port != config.ServerInfo.HttpPort {
|
|
|
|
config.Cfg.Section("server").Key("HttpPort").SetValue(port)
|
|
|
|
config.ServerInfo.HttpPort = port
|
|
|
|
}
|
|
|
|
config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
|
|
|
|
}
|
2021-10-27 09:27:46 +00:00
|
|
|
func (s *systemService) GetCasaOSLogs(lineNumber int) string {
|
2021-10-27 11:03:59 +00:00
|
|
|
file, err := os.Open(s.log.Path())
|
2021-10-27 09:27:46 +00:00
|
|
|
if err != nil {
|
2021-10-27 11:03:59 +00:00
|
|
|
return err.Error()
|
2021-10-27 09:27:46 +00:00
|
|
|
}
|
|
|
|
defer file.Close()
|
2021-10-27 11:03:59 +00:00
|
|
|
content, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
return err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(content)
|
2021-10-27 09:27:46 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 06:17:36 +00:00
|
|
|
func NewSystemService(log loger.OLog) SystemService {
|
|
|
|
return &systemService{log: log}
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|