Kaynağa Gözat

Merge branch 'v0.3.7' of https://github.com/IceWhaleTech/CasaOS into v0.3.7

LinkLeong 2 yıl önce
ebeveyn
işleme
4bb81e4669
4 değiştirilmiş dosya ile 20 ekleme ve 94 silme
  1. 0 14
      cmd/migration-tool/migration-sample.go
  2. 0 3
      route/route.go
  3. 6 55
      route/v1/system.go
  4. 14 22
      service/system.go

+ 0 - 14
cmd/migration-tool/migration-036.go → cmd/migration-tool/migration-sample.go

@@ -11,18 +11,13 @@
 package main
 
 import (
-	"strings"
-
 	interfaces "github.com/IceWhaleTech/CasaOS-Common"
 	"github.com/IceWhaleTech/CasaOS-Common/utils/version"
-	"github.com/IceWhaleTech/CasaOS/pkg/config"
-	"github.com/IceWhaleTech/CasaOS/service"
 )
 
 type migrationTool struct{}
 
 func (u *migrationTool) IsMigrationNeeded() (bool, error) {
-
 	majorVersion, minorVersion, patchVersion, err := version.DetectLegacyVersion()
 	if err != nil {
 		if err == version.ErrLegacyVersionNotFound {
@@ -46,22 +41,13 @@ func (u *migrationTool) IsMigrationNeeded() (bool, error) {
 
 	_logger.Info("Migration is needed for a CasaOS version 0.3.5 and older...")
 	return true, nil
-
 }
 
 func (u *migrationTool) PreMigrate() error {
-
 	return nil
 }
 
 func (u *migrationTool) Migrate() error {
-
-	if service.MyService.System().GetSysInfo().KernelArch == "aarch64" && config.ServerInfo.USBAutoMount != "True" && strings.Contains(service.MyService.System().GetDeviceTree(), "Raspberry Pi") {
-		service.MyService.System().UpdateUSBAutoMount("False")
-		service.MyService.System().ExecUSBAutoMountShell("False")
-	}
-
-	_logger.Info("update done")
 	return nil
 }
 

+ 0 - 3
route/route.go

@@ -146,9 +146,6 @@ func InitRouter() *gin.Engine {
 			// v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)
 			// v1SysGroup.GET("/network", v1.GetSystemNetInfo)
 
-			v1SysGroup.PUT("/usb-auto-mount", v1.PutSystemUSBAutoMount) ///sys/usb/:status
-			v1SysGroup.GET("/usb-auto-mount", v1.GetSystemUSBAutoMount) ///sys/usb/status
-
 			v1SysGroup.GET("/server-info", nil)
 			v1SysGroup.PUT("/server-info", nil)
 			v1SysGroup.GET("/apps-state", v1.GetSystemAppsStatus)

+ 6 - 55
route/v1/system.go

@@ -164,51 +164,6 @@ func PostKillCasaOS(c *gin.Context) {
 	os.Exit(0)
 }
 
-// @Summary Turn off usb auto-mount
-// @Produce  application/json
-// @Accept application/json
-// @Tags sys
-// @Security ApiKeyAuth
-// @Success 200 {string} string "ok"
-// @Router /sys/usb/off [put]
-func PutSystemUSBAutoMount(c *gin.Context) {
-	js := make(map[string]string)
-	c.ShouldBind(&js)
-	status := js["state"]
-	if status == "on" {
-		service.MyService.System().UpdateUSBAutoMount("True")
-		service.MyService.System().ExecUSBAutoMountShell("True")
-	} else {
-		service.MyService.System().UpdateUSBAutoMount("False")
-		service.MyService.System().ExecUSBAutoMountShell("False")
-	}
-	c.JSON(common_err.SUCCESS,
-		model.Result{
-			Success: common_err.SUCCESS,
-			Message: common_err.GetMsg(common_err.SUCCESS),
-		})
-}
-
-// @Summary Turn off usb auto-mount
-// @Produce  application/json
-// @Accept application/json
-// @Tags sys
-// @Security ApiKeyAuth
-// @Success 200 {string} string "ok"
-// @Router /sys/usb [get]
-func GetSystemUSBAutoMount(c *gin.Context) {
-	state := "True"
-	if config.ServerInfo.USBAutoMount == "False" {
-		state = "False"
-	}
-	c.JSON(common_err.SUCCESS,
-		model.Result{
-			Success: common_err.SUCCESS,
-			Message: common_err.GetMsg(common_err.SUCCESS),
-			Data:    state,
-		})
-}
-
 func GetSystemAppsStatus(c *gin.Context) {
 	systemAppList := service.MyService.App().GetSystemAppList()
 	appList := []model2.MyAppList{}
@@ -225,12 +180,12 @@ func GetSystemAppsStatus(c *gin.Context) {
 			Id:       v.ID,
 			Port:     v.Labels["web"],
 			Index:    v.Labels["index"],
-			//Order:      m.Labels["order"],
+			// Order:      m.Labels["order"],
 			Image:  v.Image,
 			Latest: false,
-			//Type:   m.Labels["origin"],
-			//Slogan: m.Slogan,
-			//Rely:     m.Rely,
+			// Type:   m.Labels["origin"],
+			// Slogan: m.Slogan,
+			// Rely:     m.Rely,
 			Host:     v.Labels["host"],
 			Protocol: v.Labels["protocol"],
 		})
@@ -251,7 +206,6 @@ func GetSystemAppsStatus(c *gin.Context) {
 // @Success 200 {string} string "ok"
 // @Router /sys/hardware/info [get]
 func GetSystemHardwareInfo(c *gin.Context) {
-
 	data := make(map[string]string, 1)
 	data["drive_model"] = service.MyService.System().GetDeviceTree()
 	c.JSON(common_err.SUCCESS,
@@ -270,7 +224,7 @@ func GetSystemHardwareInfo(c *gin.Context) {
 // @Success 200 {string} string "ok"
 // @Router /sys/utilization [get]
 func GetSystemUtilization(c *gin.Context) {
-	var data = make(map[string]interface{})
+	data := make(map[string]interface{})
 	cpu := service.MyService.System().GetCpuPercent()
 	num := service.MyService.System().GetCpuCoreNum()
 	cpuData := make(map[string]interface{})
@@ -282,7 +236,7 @@ func GetSystemUtilization(c *gin.Context) {
 	data["cpu"] = cpuData
 	data["mem"] = service.MyService.System().GetMemInfo()
 
-	//拼装网络信息
+	// 拼装网络信息
 	netList := service.MyService.System().GetNetInfo()
 	newNet := []model.IOCountersStat{}
 	nets := service.MyService.System().GetNet(true)
@@ -313,7 +267,6 @@ func GetSystemUtilization(c *gin.Context) {
 // @Success 200 {string} string "ok"
 // @Router /sys/socket/port [get]
 func GetSystemSocketPort(c *gin.Context) {
-
 	c.JSON(common_err.SUCCESS,
 		model.Result{
 			Success: common_err.SUCCESS,
@@ -336,7 +289,6 @@ func GetSystemCupInfo(c *gin.Context) {
 	data["percent"] = cpu
 	data["num"] = num
 	c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
-
 }
 
 // @Summary get mem info
@@ -349,7 +301,6 @@ func GetSystemCupInfo(c *gin.Context) {
 func GetSystemMemInfo(c *gin.Context) {
 	mem := service.MyService.System().GetMemInfo()
 	c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: mem})
-
 }
 
 // @Summary get disk info

+ 14 - 22
service/system.go

@@ -30,8 +30,6 @@ type SystemService interface {
 	UpdateAssist()
 	UpSystemPort(port string)
 	GetTimeZone() string
-	UpdateUSBAutoMount(state string)
-	ExecUSBAutoMountShell(state string)
 	UpAppOrderFile(str, id string)
 	GetAppOrderFile(id string) []byte
 	GetNet(physics bool) []string
@@ -53,14 +51,7 @@ type SystemService interface {
 	GetCPUTemperature() int
 	GetCPUPower() map[string]string
 }
-type systemService struct {
-}
-
-func (s *systemService) UpdateUSBAutoMount(state string) {
-	config.ServerInfo.USBAutoMount = state
-	config.Cfg.Section("server").Key("USBAutoMount").SetValue(state)
-	config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
-}
+type systemService struct{}
 
 func (c *systemService) MkdirAll(path string) (int, error) {
 	_, err := os.Stat(path)
@@ -76,8 +67,8 @@ func (c *systemService) MkdirAll(path string) (int, error) {
 	}
 	return common_err.SERVICE_ERROR, err
 }
-func (c *systemService) RenameFile(oldF, newF string) (int, error) {
 
+func (c *systemService) RenameFile(oldF, newF string) (int, error) {
 	_, err := os.Stat(newF)
 	if err == nil {
 		return common_err.DIR_ALREADY_EXISTS, nil
@@ -92,6 +83,7 @@ func (c *systemService) RenameFile(oldF, newF string) (int, error) {
 	}
 	return common_err.SERVICE_ERROR, err
 }
+
 func (c *systemService) CreateFile(path string) (int, error) {
 	_, err := os.Stat(path)
 	if err == nil {
@@ -104,9 +96,11 @@ func (c *systemService) CreateFile(path string) (int, error) {
 	}
 	return common_err.SERVICE_ERROR, err
 }
+
 func (c *systemService) GetDeviceTree() string {
 	return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetDeviceTree")
 }
+
 func (c *systemService) GetSysInfo() host.InfoStat {
 	info, _ := host.Info()
 	return *info
@@ -128,9 +122,7 @@ func (c *systemService) GetNetState(name string) string {
 }
 
 func (c *systemService) GetDirPathOne(path string) (m model.Path) {
-
 	f, err := os.Stat(path)
-
 	if err != nil {
 		return
 	}
@@ -175,6 +167,7 @@ func (c *systemService) GetDirPath(path string) []model.Path {
 	}
 	return dirs
 }
+
 func (c *systemService) GetCpuInfo() []cpu.InfoStat {
 	info, _ := cpu.Info()
 	return info
@@ -207,6 +200,7 @@ func (c *systemService) GetNetInfo() []net.IOCountersStat {
 	parts, _ := net.IOCounters(true)
 	return parts
 }
+
 func (c *systemService) GetNet(physics bool) []string {
 	t := "1"
 	if physics {
@@ -230,6 +224,7 @@ func (s *systemService) UpdateSystemVersion(version string) {
 	//s.log.Error(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version)
 	//s.log.Error(command2.ExecResultStr(config.AppInfo.ProjectPath + "/shell/tool.sh -r " + version))
 }
+
 func (s *systemService) UpdateAssist() {
 	command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/assist.sh")
 }
@@ -238,14 +233,6 @@ func (s *systemService) GetTimeZone() string {
 	return command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;GetTimeZone")
 }
 
-func (s *systemService) ExecUSBAutoMountShell(state string) {
-	if state == "False" {
-		command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Stop_Auto")
-	} else {
-		command2.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;USB_Start_Auto")
-	}
-}
-
 func (s *systemService) GetSystemConfigDebug() []string {
 	return command2.ExecResultStrArray("source " + config.AppInfo.ShellPath + "/helper.sh ;GetSysInfo")
 }
@@ -253,9 +240,11 @@ func (s *systemService) GetSystemConfigDebug() []string {
 func (s *systemService) UpAppOrderFile(str, id string) {
 	file.WriteToPath([]byte(str), config.AppInfo.DBPath+"/"+id, "app_order.json")
 }
+
 func (s *systemService) GetAppOrderFile(id string) []byte {
 	return file.ReadFullFile(config.AppInfo.UserDataPath + "/" + id + "/app_order.json")
 }
+
 func (s *systemService) UpSystemPort(port string) {
 	if len(port) > 0 && port != config.ServerInfo.HttpPort {
 		config.Cfg.Section("server").Key("HttpPort").SetValue(port)
@@ -263,6 +252,7 @@ func (s *systemService) UpSystemPort(port string) {
 	}
 	config.Cfg.SaveTo(config.SystemConfigInfo.ConfigPath)
 }
+
 func (s *systemService) GetCasaOSLogs(lineNumber int) string {
 	file, err := os.Open(filepath.Join(config.AppInfo.LogPath, fmt.Sprintf("%s.%s",
 		config.AppInfo.LogSaveName,
@@ -299,8 +289,8 @@ func GetDeviceAllIP() []string {
 func (s *systemService) IsServiceRunning(name string) bool {
 	status := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;CheckServiceStatus smbd")
 	return strings.TrimSpace(status) == "running"
-
 }
+
 func (s *systemService) GetCPUTemperature() int {
 	outPut := ""
 	if file.Exists("/sys/class/thermal/thermal_zone0/temp") {
@@ -318,6 +308,7 @@ func (s *systemService) GetCPUTemperature() int {
 	}
 	return celsius
 }
+
 func (s *systemService) GetCPUPower() map[string]string {
 	data := make(map[string]string, 2)
 	data["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
@@ -328,6 +319,7 @@ func (s *systemService) GetCPUPower() map[string]string {
 	}
 	return data
 }
+
 func NewSystemService() SystemService {
 	return &systemService{}
 }