diff --git a/UI b/UI deleted file mode 160000 index bca2742..0000000 --- a/UI +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bca27426e1f398c31fb6c5c23885482326514f6e diff --git a/cmd/migration-tool/main.go b/cmd/migration-tool/main.go index 05e209f..a464a0c 100644 --- a/cmd/migration-tool/main.go +++ b/cmd/migration-tool/main.go @@ -1,3 +1,13 @@ +/* + * @Author: LinkLeong link@icewhale.org + * @Date: 2022-08-23 18:09:11 + * @LastEditors: LinkLeong + * @LastEditTime: 2022-08-24 18:02:59 + * @FilePath: /CasaOS/cmd/migration-tool/main.go + * @Description: + * @Website: https://www.casaos.io + * Copyright (c) 2022 by icewhale, All Rights Reserved. + */ package main import ( @@ -5,17 +15,78 @@ import ( "fmt" "os" - "github.com/IceWhaleTech/CasaOS/types" + interfaces "github.com/IceWhaleTech/CasaOS-Common" + "github.com/IceWhaleTech/CasaOS-Common/utils/systemctl" + "github.com/IceWhaleTech/CasaOS-Gateway/common" +) + +const ( + casaosServiceName = "casaos.service" ) func main() { versionFlag := flag.Bool("v", false, "version") + debugFlag := flag.Bool("d", true, "debug") + forceFlag := flag.Bool("f", false, "force") flag.Parse() if *versionFlag { - fmt.Println(types.CURRENTVERSION) + fmt.Println(common.Version) os.Exit(0) } - fmt.Println("This migration tool is not implemented yet.") + if os.Getuid() != 0 { + os.Exit(1) + } + + if *debugFlag { + // _logger.DebugMode = true + } + + if !*forceFlag { + serviceEnabled, err := systemctl.IsServiceEnabled(casaosServiceName) + if err != nil { + panic(err) + } + + if serviceEnabled { + //_logger.Info("%s is already enabled. If migration is still needed, try with -f.", userServiceName) + os.Exit(1) + } + } + + migrationTools := []interfaces.MigrationTool{ + NewMigrationToolFor_035(), + } + + var selectedMigrationTool interfaces.MigrationTool + + // look for the right migration tool matching current version + for _, tool := range migrationTools { + migrationNeeded, err := tool.IsMigrationNeeded() + if err != nil { + panic(err) + } + + if migrationNeeded { + selectedMigrationTool = tool + break + } + } + + if selectedMigrationTool == nil { + return + } + + if err := selectedMigrationTool.PreMigrate(); err != nil { + panic(err) + } + + if err := selectedMigrationTool.Migrate(); err != nil { + panic(err) + } + + if err := selectedMigrationTool.PostMigrate(); err != nil { + panic(err) + } } diff --git a/cmd/migration-tool/migration-035.go b/cmd/migration-tool/migration-035.go new file mode 100644 index 0000000..a160bec --- /dev/null +++ b/cmd/migration-tool/migration-035.go @@ -0,0 +1,52 @@ +/* + * @Author: LinkLeong link@icewhale.org + * @Date: 2022-08-24 17:36:00 + * @LastEditors: LinkLeong + * @LastEditTime: 2022-08-24 18:11:16 + * @FilePath: /CasaOS/cmd/migration-tool/migration-035.go + * @Description: + * @Website: https://www.casaos.io + * Copyright (c) 2022 by icewhale, All Rights Reserved. + */ +package main + +import ( + interfaces "github.com/IceWhaleTech/CasaOS-Common" + "github.com/IceWhaleTech/CasaOS-Common/utils/version" +) + +type migrationTool struct{} + +func (u *migrationTool) IsMigrationNeeded() (bool, error) { + + minorVersion, err := version.DetectMinorVersion() + if err != nil { + return false, err + } + + if minorVersion != 3 { + return false, nil + } + + // this is the best way to tell if CasaOS version is between 0.3.3 and 0.3.5 + + //return true, nil + return false, nil +} + +func (u *migrationTool) PreMigrate() error { + + return nil +} + +func (u *migrationTool) Migrate() error { + return nil +} + +func (u *migrationTool) PostMigrate() error { + return nil +} + +func NewMigrationToolFor_035() interfaces.MigrationTool { + return &migrationTool{} +} diff --git a/go.mod b/go.mod index 3427734..94665f6 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d + github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220811222508-6c2a1d77be66 github.com/IceWhaleTech/CasaOS-Gateway v0.3.6-alpha1 github.com/Microsoft/go-winio v0.5.0 // indirect github.com/ambelovsky/go-structs v1.1.0 // indirect diff --git a/go.sum b/go.sum index a6c1546..8a1739b 100644 --- a/go.sum +++ b/go.sum @@ -83,6 +83,7 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d h1:62lEBImTxZ83pgzywgDNIrPPuQ+j4ep9QjqrWBn1hrU= github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d/go.mod h1:lW9x+yEjqKdPbE3+cf2fGPJXCw/hChX3Omi9QHTLFsQ= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220811222508-6c2a1d77be66 h1:JXzgOmP4HCWbZ7qCl6gr2nRB5RnUN0oTFF8ohv05sZk= github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220811222508-6c2a1d77be66/go.mod h1:XGqdbedN9UlF3/rylcXKJ2BW4ayugBmEMa4Z0tk2KbQ= github.com/IceWhaleTech/CasaOS-Gateway v0.3.6-alpha1 h1:VTjFhgaDy+yDZZOkGACLoynp2fxCL1PJuwYM+tLL68o= github.com/IceWhaleTech/CasaOS-Gateway v0.3.6-alpha1/go.mod h1:wWBJTVHt0P0AGNfoOgI2+HhZ5bGZU4d5xbz/dXNBzAY= @@ -276,9 +277,11 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd v0.0.0-20161114122254-48702e0da86b/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= +github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= @@ -419,8 +422,10 @@ github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= +github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e h1:BWhy2j3IXJhjCbC68FptL43tDKIq8FladmaTs3Xs7Z8= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= diff --git a/interfaces/migrationTool.go b/interfaces/migrationTool.go new file mode 100644 index 0000000..0028c4d --- /dev/null +++ b/interfaces/migrationTool.go @@ -0,0 +1,18 @@ +/* + * @Author: LinkLeong link@icewhale.org + * @Date: 2022-08-24 17:37:36 + * @LastEditors: LinkLeong + * @LastEditTime: 2022-08-24 17:38:48 + * @FilePath: /CasaOS/interfaces/migrationTool.go + * @Description: + * @Website: https://www.casaos.io + * Copyright (c) 2022 by icewhale, All Rights Reserved. + */ +package interfaces + +type MigrationTool interface { + IsMigrationNeeded() (bool, error) + PostMigrate() error + Migrate() error + PreMigrate() error +} diff --git a/main.go b/main.go index 11ad9cb..c6034c6 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,6 @@ func main() { panic(err) } } - fmt.Println("注册成功") // s := &http.Server{ // Addr: listener.Addr().String(), //fmt.Sprintf(":%v", config.ServerInfo.HttpPort), // Handler: r, diff --git a/route/darwin.go b/route/darwin.go index 8e6dd35..d532fa3 100644 --- a/route/darwin.go +++ b/route/darwin.go @@ -5,7 +5,7 @@ * @Author: LinkLeong link@icewhale.org * @Date: 2022-08-12 14:22:28 * @LastEditors: LinkLeong - * @LastEditTime: 2022-08-12 18:41:14 + * @LastEditTime: 2022-08-24 18:52:36 * @FilePath: /CasaOS/route/darwin.go * @Description: * @Website: https://www.casaos.io @@ -14,12 +14,12 @@ package route -func MonitoryUSB() { +// func MonitoryUSB() { -} -func SendAllHardwareStatusBySocket() { +// } +// func SendAllHardwareStatusBySocket() { -} -func SendUSBBySocket() { +// } +// func SendUSBBySocket() { -} +// } diff --git a/route/periodical.go b/route/periodical.go index 1fc9eb8..6bc2a2b 100644 --- a/route/periodical.go +++ b/route/periodical.go @@ -1,11 +1,8 @@ -//go:build !darwin -// +build !darwin - /* * @Author: LinkLeong link@icewhale.com * @Date: 2022-07-01 15:11:36 * @LastEditors: LinkLeong - * @LastEditTime: 2022-08-18 16:58:00 + * @LastEditTime: 2022-08-24 18:54:03 * @FilePath: /CasaOS/route/periodical.go * @Description: * @Website: https://www.casaos.io diff --git a/route/v1/system.go b/route/v1/system.go index d9b6d29..19e1bd7 100644 --- a/route/v1/system.go +++ b/route/v1/system.go @@ -1,8 +1,9 @@ package v1 import ( - "encoding/json" + "bytes" "fmt" + "io" "io/ioutil" "net/http" "os" @@ -535,6 +536,13 @@ func GetSystemProxy(c *gin.Context) { return } defer resp.Body.Close() + for k, v := range c.Request.Header { + c.Header(k, v[0]) + } rda, _ := ioutil.ReadAll(resp.Body) - json.NewEncoder(c.Writer).Encode(json.RawMessage(string(rda))) + // json.NewEncoder(c.Writer).Encode(json.RawMessage(string(rda))) + // 响应状态码 + c.Writer.WriteHeader(resp.StatusCode) + // 复制转发的响应Body到响应Body + io.Copy(c.Writer, ioutil.NopCloser(bytes.NewBuffer(rda))) } diff --git a/service/system.go b/service/system.go index dd216e9..8717e4c 100644 --- a/service/system.go +++ b/service/system.go @@ -306,7 +306,7 @@ func (s *systemService) GetCPUTemperature() int { outPut = "0" } - celsius, _ := strconv.Atoi(outPut) + celsius, _ := strconv.Atoi(strings.TrimSpace(outPut)) if celsius > 1000 { celsius = celsius / 1000 @@ -316,8 +316,8 @@ func (s *systemService) GetCPUTemperature() int { func (s *systemService) GetCPUPower() map[string]string { data := make(map[string]string, 2) data["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10) - if file.Exists(`/sys/class/powercap/intel-rapl/intel-rapl\:0/energy_uj`) { - data["value"] = string(file.ReadFullFile(`/sys/class/powercap/intel-rapl/intel-rapl\:0/energy_uj`)) + if file.Exists("/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj") { + data["value"] = strings.TrimSpace(string(file.ReadFullFile("/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj"))) } else { data["value"] = "0" }