@@ -3,7 +3,9 @@ package generic
33import (
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
1820type 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
3051func (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
3657func (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
4869func (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
5475func (d * CommonInstaller ) Stop () error {
5576 fmt .Println ("not supported yet" )
5677 return nil
0 commit comments