1
0
mirror of https://github.com/IceWhaleTech/CasaOS.git synced 2025-07-03 23:30:39 +02:00
Files
CasaOS/service/system.go

80 lines
2.3 KiB
Go
Raw Normal View History

2021-09-26 10:35:02 +08:00
package service
import (
"bufio"
"fmt"
"io"
"os"
2021-09-27 14:17:36 +08:00
"github.com/IceWhaleTech/CasaOS/pkg/config"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
2021-09-27 14:17:36 +08:00
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
2021-09-26 10:35:02 +08:00
)
type SystemService interface {
UpSystemConfig(str string, widget string)
2021-09-26 10:35:02 +08:00
UpdateSystemVersion(version string)
GetSystemConfigDebug() []string
GetCasaOSLogs(lineNumber int) string
2021-09-26 10:35:02 +08:00
}
type systemService struct {
2021-09-27 14:17:36 +08:00
log loger.OLog
2021-09-26 10:35:02 +08:00
}
func (s *systemService) UpdateSystemVersion(version string) {
2021-09-27 14:17:36 +08: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 10:35:02 +08:00
}
func (s *systemService) GetSystemConfigDebug() []string {
return command2.ExecResultStrArray("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;GetSysInfo")
}
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 10:35:02 +08:00
}
if len(widget) > 0 && widget != config.SystemConfigInfo.WidgetList {
config.Cfg.Section("system").Key("WidgetList").SetValue(widget)
config.SystemConfigInfo.WidgetList = widget
2021-09-26 10:35:02 +08:00
}
config.Cfg.SaveTo("conf/conf.ini")
}
func (s *systemService) GetCasaOSLogs(lineNumber int) string {
reader, err := file.NewReadLineFromEnd(s.log.Path())
if err != nil {
return ""
}
defer reader.Close()
test, err := reader.ReadLine()
fmt.Println(err)
fmt.Println(test)
return string(test)
file, _ := os.Open(s.log.Path())
fileScanner := bufio.NewReader(file)
lineNumber = 5
lineCount := 1
var r string
for i := lineCount; i < lineNumber; i++ {
line, _, err := fileScanner.ReadLine()
r += string(line)
if err == io.EOF {
return r
}
// 如下是某些业务逻辑操作
// 如下代码打印每次读取的文件行内容
}
defer file.Close()
return r
}
2021-09-27 14:17:36 +08:00
func NewSystemService(log loger.OLog) SystemService {
return &systemService{log: log}
2021-09-26 10:35:02 +08:00
}