diff --git a/build/build-all.sh b/build/build-all.sh index 20d04545..b8f0e7b6 100755 --- a/build/build-all.sh +++ b/build/build-all.sh @@ -6,3 +6,4 @@ ./build.sh linux mips64 ./build.sh linux mips64le ./build.sh darwin amd64 +./build.sh darwin arm64 diff --git a/cmd/edge-admin/main.go b/cmd/edge-admin/main.go index 4a099a5c..1838ff8d 100644 --- a/cmd/edge-admin/main.go +++ b/cmd/edge-admin/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/TeaOSLab/EdgeAdmin/internal/apps" + "github.com/TeaOSLab/EdgeAdmin/internal/configs" teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/nodes" _ "github.com/TeaOSLab/EdgeAdmin/internal/web" @@ -13,7 +14,14 @@ func main() { app := apps.NewAppCmd(). Version(teaconst.Version). Product(teaconst.ProductName). - Usage(teaconst.ProcessName + " [-v|start|stop|restart|service|daemon]") + Usage(teaconst.ProcessName+" [-v|start|stop|restart|service|daemon|reset]"). + Option("-h", "show this help"). + Option("-v", "show version"). + Option("start", "start the service"). + Option("stop", "stop the service"). + Option("service", "register service into systemd"). + Option("daemon", "start the service with daemon"). + Option("reset", "reset configs") app.On("daemon", func() { nodes.NewAdminNode().Daemon() @@ -26,6 +34,14 @@ func main() { } fmt.Println("done") }) + app.On("reset", func() { + err := configs.ResetAPIConfig() + if err != nil { + fmt.Println("[ERROR]reset failed: " + err.Error()) + return + } + fmt.Println("done") + }) app.Run(func() { adminNode := nodes.NewAdminNode() adminNode.Run() diff --git a/internal/configs/api_config.go b/internal/configs/api_config.go index 405ff8b4..a6e04e65 100644 --- a/internal/configs/api_config.go +++ b/internal/configs/api_config.go @@ -59,6 +59,49 @@ func LoadAPIConfig() (*APIConfig, error) { return config, nil } +// ResetAPIConfig 重置配置 +func ResetAPIConfig() error { + filename := "api.yaml" + + { + configFile := Tea.ConfigFile(filename) + stat, err := os.Stat(configFile) + if err == nil && !stat.IsDir() { + err = os.Remove(configFile) + if err != nil { + return err + } + } + } + + // 重置 ~/.edge-admin/api.yaml + homeDir, homeErr := os.UserHomeDir() + if homeErr == nil { + configFile := homeDir + "/." + teaconst.ProcessName + "/" + filename + stat, err := os.Stat(configFile) + if err == nil && !stat.IsDir() { + err = os.Remove(configFile) + if err != nil { + return err + } + } + } + + // 重置 /etc/edge-admin/api.yaml + { + configFile := "/etc/" + teaconst.ProcessName + "/" + filename + stat, err := os.Stat(configFile) + if err == nil && !stat.IsDir() { + err = os.Remove(configFile) + if err != nil { + return err + } + } + } + + return nil +} + // WriteFile 写入API配置 func (this *APIConfig) WriteFile(path string) error { data, err := yaml.Marshal(this) @@ -84,7 +127,7 @@ func (this *APIConfig) WriteFile(path string) error { } } - // 写入 /etc/.edge-admin + // 写入 /etc/edge-admin { dir := "/etc/" + teaconst.ProcessName stat, err := os.Stat(dir)