Skip to content

Commit 020dab5

Browse files
authored
Add syscall support for the generic installation (#261)
1 parent f2fbde4 commit 020dab5

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

pkg/os/generic/common.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package generic
33
import (
44
"fmt"
55
"github.com/linuxsuren/http-downloader/pkg/exec"
6+
"os"
67
"runtime"
8+
"syscall"
79
)
810

911
// CommonInstaller is the installer of a common bash
@@ -16,8 +18,27 @@ type CommonInstaller struct {
1618

1719
// CmdWithArgs is a command and with args
1820
type CmdWithArgs struct {
19-
Cmd string `yaml:"cmd"`
20-
Args []string `yaml:"args"`
21+
Cmd string `yaml:"cmd"`
22+
Args []string `yaml:"args"`
23+
SystemCall bool `yaml:"systemCall"`
24+
}
25+
26+
// Run runs the current command
27+
func (c CmdWithArgs) Run() (err error) {
28+
fmt.Println(c.SystemCall)
29+
if c.SystemCall {
30+
var targetBinary string
31+
if targetBinary, err = exec.LookPath(c.Cmd); err != nil {
32+
err = fmt.Errorf("cannot find %s", c.Cmd)
33+
} else {
34+
sysCallArgs := []string{c.Cmd}
35+
sysCallArgs = append(sysCallArgs, c.Args...)
36+
err = syscall.Exec(targetBinary, sysCallArgs, os.Environ())
37+
}
38+
} else {
39+
err = exec.RunCommand(c.Cmd, c.Args...)
40+
}
41+
return
2142
}
2243

2344
// Available check if support current platform
@@ -28,13 +49,13 @@ func (d *CommonInstaller) Available() (ok bool) {
2849

2950
// Install installs the target package
3051
func (d *CommonInstaller) Install() (err error) {
31-
err = exec.RunCommand(d.InstallCmd.Cmd, d.InstallCmd.Args...)
52+
err = d.InstallCmd.Run()
3253
return
3354
}
3455

35-
// Uninstall uninstalls the Conntrack
56+
// Uninstall uninstalls the target package
3657
func (d *CommonInstaller) Uninstall() (err error) {
37-
err = exec.RunCommand(d.UninstallCmd.Cmd, d.UninstallCmd.Args...)
58+
err = d.UninstallCmd.Run()
3859
return
3960
}
4061

@@ -44,13 +65,13 @@ func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
4465
return
4566
}
4667

47-
// Start starts the Conntrack service
68+
// Start starts the desired service
4869
func (d *CommonInstaller) Start() error {
4970
fmt.Println("not supported yet")
5071
return nil
5172
}
5273

53-
// Stop stops the Conntrack service
74+
// Stop stops the desired service
5475
func (d *CommonInstaller) Stop() error {
5576
fmt.Println("not supported yet")
5677
return nil

pkg/os/generic_installer.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ type genericPackage struct {
4545

4646
// CmdWithArgs is a command with arguments
4747
type CmdWithArgs struct {
48-
Cmd string `yaml:"cmd"`
49-
Args []string `yaml:"args"`
48+
Cmd string `yaml:"cmd"`
49+
Args []string `yaml:"args"`
50+
SystemCall bool `yaml:"systemCall"`
5051
}
5152

5253
func parseGenericPackages(configFile string, genericPackages *genericPackages) (err error) {
@@ -93,12 +94,14 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
9394
Name: genericPackage.Name,
9495
OS: genericPackage.OS,
9596
InstallCmd: generic.CmdWithArgs{
96-
Cmd: genericPackage.InstallCmd.Cmd,
97-
Args: genericPackage.InstallCmd.Args,
97+
Cmd: genericPackage.InstallCmd.Cmd,
98+
Args: genericPackage.InstallCmd.Args,
99+
SystemCall: genericPackage.InstallCmd.SystemCall,
98100
},
99101
UninstallCmd: generic.CmdWithArgs{
100-
Cmd: genericPackage.UninstallCmd.Cmd,
101-
Args: genericPackage.UninstallCmd.Args,
102+
Cmd: genericPackage.UninstallCmd.Cmd,
103+
Args: genericPackage.UninstallCmd.Args,
104+
SystemCall: genericPackage.UninstallCmd.SystemCall,
102105
},
103106
}
104107
}

0 commit comments

Comments
 (0)