mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	实现DNS节点远程安装
This commit is contained in:
		
							
								
								
									
										62
									
								
								cmd/installer-dns-helper/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								cmd/installer-dns-helper/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"flag"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils"
 | 
			
		||||
	"net"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	cmd := ""
 | 
			
		||||
	flag.StringVar(&cmd, "cmd", "", "command name: [unzip]")
 | 
			
		||||
 | 
			
		||||
	// unzip
 | 
			
		||||
	zipPath := ""
 | 
			
		||||
	targetPath := ""
 | 
			
		||||
	flag.StringVar(&zipPath, "zip", "", "zip path")
 | 
			
		||||
	flag.StringVar(&targetPath, "target", "", "target dir")
 | 
			
		||||
 | 
			
		||||
	// parse
 | 
			
		||||
	flag.Parse()
 | 
			
		||||
 | 
			
		||||
	if len(cmd) == 0 {
 | 
			
		||||
		stderr("need '-cmd=COMMAND' argument")
 | 
			
		||||
	} else if cmd == "test" {
 | 
			
		||||
		// 检查是否正在运行
 | 
			
		||||
		path := os.TempDir() + "/edge-dns.sock"
 | 
			
		||||
		conn, err := net.Dial("unix", path)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			_ = conn.Close()
 | 
			
		||||
			stderr("test dns node status: edge dns node is running now, can not install again")
 | 
			
		||||
		}
 | 
			
		||||
	} else if cmd == "unzip" { // 解压
 | 
			
		||||
		if len(zipPath) == 0 {
 | 
			
		||||
			stderr("ERROR: need '-zip=PATH' argument")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		if len(targetPath) == 0 {
 | 
			
		||||
			stderr("ERROR: need '-target=TARGET' argument")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		unzip := utils.NewUnzip(zipPath, targetPath)
 | 
			
		||||
		err := unzip.Run()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			stderr("ERROR: " + err.Error())
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		stdout("ok")
 | 
			
		||||
	} else {
 | 
			
		||||
		stderr("ERROR: not recognized command '" + cmd + "'")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func stdout(s string) {
 | 
			
		||||
	_, _ = os.Stdout.WriteString(s + "\n")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func stderr(s string) {
 | 
			
		||||
	_, _ = os.Stderr.WriteString(s + "\n")
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user