mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	优化远程安装时uname读取方法
This commit is contained in:
		@@ -125,14 +125,14 @@ func (this *BaseInstaller) LookupLatestInstaller(filePrefix string) (string, err
 | 
				
			|||||||
		return "", err
 | 
							return "", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lastVersion := ""
 | 
						var lastVersion = ""
 | 
				
			||||||
	result := ""
 | 
						var result = ""
 | 
				
			||||||
	for _, match := range matches {
 | 
						for _, match := range matches {
 | 
				
			||||||
		baseName := filepath.Base(match)
 | 
							var baseName = filepath.Base(match)
 | 
				
			||||||
		if !pattern.MatchString(baseName) {
 | 
							if !pattern.MatchString(baseName) {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		m := pattern.FindStringSubmatch(baseName)
 | 
							var m = pattern.FindStringSubmatch(baseName)
 | 
				
			||||||
		if len(m) < 2 {
 | 
							if len(m) < 2 {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -147,28 +147,10 @@ func (this *BaseInstaller) LookupLatestInstaller(filePrefix string) (string, err
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// InstallHelper 上传安装助手
 | 
					// InstallHelper 上传安装助手
 | 
				
			||||||
func (this *BaseInstaller) InstallHelper(targetDir string, role nodeconfigs.NodeRole) (env *Env, err error) {
 | 
					func (this *BaseInstaller) InstallHelper(targetDir string, role nodeconfigs.NodeRole) (env *Env, err error) {
 | 
				
			||||||
	var unameRetries = 3
 | 
						var uname = this.uname()
 | 
				
			||||||
	var uname string
 | 
					 | 
				
			||||||
	for i := 0; i < unameRetries; i++ {
 | 
					 | 
				
			||||||
		// 此处不能使用 /usr/bin/uname,因为uname不一定在 /usr/bin 下
 | 
					 | 
				
			||||||
		uname, _, err = this.client.Exec("uname -a")
 | 
					 | 
				
			||||||
		if len(uname) == 0 {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if err == nil {
 | 
					 | 
				
			||||||
			break
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return env, errors.New("unable to execute 'uname -a' on this system: " + err.Error())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(uname) == 0 {
 | 
						var osName = ""
 | 
				
			||||||
		return nil, errors.New("unable to execute 'uname -a' on this system")
 | 
						var archName = ""
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	osName := ""
 | 
					 | 
				
			||||||
	archName := ""
 | 
					 | 
				
			||||||
	if strings.Contains(uname, "Darwin") {
 | 
						if strings.Contains(uname, "Darwin") {
 | 
				
			||||||
		osName = "darwin"
 | 
							osName = "darwin"
 | 
				
			||||||
	} else if strings.Contains(uname, "Linux") {
 | 
						} else if strings.Contains(uname, "Linux") {
 | 
				
			||||||
@@ -230,3 +212,18 @@ func (this *BaseInstaller) InstallHelper(targetDir string, role nodeconfigs.Node
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return env, nil
 | 
						return env, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (this *BaseInstaller) uname() (uname string) {
 | 
				
			||||||
 | 
						var unameRetries = 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := 0; i < unameRetries; i++ {
 | 
				
			||||||
 | 
							for _, unameExe := range []string{"uname", "/bin/uname", "/usr/bin/uname"} {
 | 
				
			||||||
 | 
								uname, _, _ = this.client.Exec(unameExe + " -a")
 | 
				
			||||||
 | 
								if len(uname) > 0 {
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return "x86_64 GNU/Linux"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user