mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	自动安装nftables时尝试使用apt-get
This commit is contained in:
		@@ -90,18 +90,26 @@ func (this *Installer) Install() error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var cmd *executils.Cmd
 | 
			
		||||
	var aptCmd *executils.Cmd
 | 
			
		||||
 | 
			
		||||
	// check dnf
 | 
			
		||||
	{
 | 
			
		||||
		dnfExe, err := executils.LookPath("dnf")
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			cmd = executils.NewCmd(dnfExe, "-y", "install", "nftables")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// check apt
 | 
			
		||||
	if cmd == nil {
 | 
			
		||||
		aptExe, err := executils.LookPath("apt")
 | 
			
		||||
		aptGetExe, err := executils.LookPath("apt-get")
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			cmd = executils.NewCmd(aptExe, "install", "nftables")
 | 
			
		||||
			cmd = executils.NewCmd(aptGetExe, "install", "nftables")
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		aptExe, aptErr := executils.LookPath("apt")
 | 
			
		||||
		if aptErr == nil {
 | 
			
		||||
			aptCmd = executils.NewCmd(aptExe, "install", "nftables")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -117,12 +125,22 @@ func (this *Installer) Install() error {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cmd.WithTimeout(10 * time.Minute)
 | 
			
		||||
	cmd.WithStderr()
 | 
			
		||||
	err := cmd.Run()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// try 'apt-get' instead of 'apt'
 | 
			
		||||
		if aptCmd != nil {
 | 
			
		||||
			cmd = aptCmd
 | 
			
		||||
			cmd.WithTimeout(10 * time.Minute)
 | 
			
		||||
			cmd.WithStderr()
 | 
			
		||||
			err = cmd.Run()
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("%w: %s", err, cmd.Stderr())
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	remotelogs.Println("NFTABLES", "installed nftables with command '"+cmd.String()+"' successfully")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user