|
1 | 1 | package route |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "fmt" |
5 | 6 | "os" |
6 | 7 | "strings" |
7 | 8 | "time" |
8 | 9 |
|
| 10 | + "github.com/IceWhaleTech/CasaOS/model" |
| 11 | + "github.com/IceWhaleTech/CasaOS/pkg/config" |
9 | 12 | "github.com/IceWhaleTech/CasaOS/pkg/samba" |
| 13 | + "github.com/IceWhaleTech/CasaOS/pkg/utils/encryption" |
10 | 14 | "github.com/IceWhaleTech/CasaOS/pkg/utils/file" |
11 | 15 | "github.com/IceWhaleTech/CasaOS/pkg/utils/loger" |
12 | 16 | "github.com/IceWhaleTech/CasaOS/service" |
| 17 | + "github.com/IceWhaleTech/CasaOS/types" |
13 | 18 | "go.uber.org/zap" |
14 | 19 | ) |
15 | 20 |
|
16 | 21 | func InitFunction() { |
17 | 22 | go InitNetworkMount() |
| 23 | + go InitInfo() |
18 | 24 | } |
| 25 | + |
| 26 | +func InitInfo() { |
| 27 | + mb := model.BaseInfo{} |
| 28 | + if file.Exists(config.AppInfo.DBPath + "/baseinfo.conf") { |
| 29 | + err := json.Unmarshal(file.ReadFullFile(config.AppInfo.DBPath+"/baseinfo.conf"), &mb) |
| 30 | + if err != nil { |
| 31 | + loger.Error("baseinfo.conf", zap.String("error", err.Error())) |
| 32 | + } |
| 33 | + } |
| 34 | + if file.Exists("/etc/CHANNEL") { |
| 35 | + channel := file.ReadFullFile("/etc/CHANNEL") |
| 36 | + mb.Channel = string(channel) |
| 37 | + } |
| 38 | + mac, err := service.MyService.System().GetMacAddress() |
| 39 | + if err != nil { |
| 40 | + loger.Error("GetMacAddress", zap.String("error", err.Error())) |
| 41 | + } |
| 42 | + mb.Hash = encryption.GetMD5ByStr(mac) |
| 43 | + mb.Version = types.CURRENTVERSION |
| 44 | + os.Remove(config.AppInfo.DBPath + "/baseinfo.conf") |
| 45 | + by, err := json.Marshal(mb) |
| 46 | + if err != nil { |
| 47 | + loger.Error("init info err", zap.Any("err", err)) |
| 48 | + return |
| 49 | + } |
| 50 | + file.WriteToFullPath(by, config.AppInfo.DBPath+"/baseinfo.conf", 0o666) |
| 51 | +} |
| 52 | + |
19 | 53 | func InitNetworkMount() { |
20 | 54 | time.Sleep(time.Second * 10) |
21 | 55 | connections := service.MyService.Connections().GetConnectionsList() |
|
0 commit comments