@@ -3,7 +3,9 @@ package generic
3
3
import (
4
4
"fmt"
5
5
"github.com/linuxsuren/http-downloader/pkg/exec"
6
+ "os"
6
7
"runtime"
8
+ "syscall"
7
9
)
8
10
9
11
// CommonInstaller is the installer of a common bash
@@ -16,8 +18,27 @@ type CommonInstaller struct {
16
18
17
19
// CmdWithArgs is a command and with args
18
20
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
21
42
}
22
43
23
44
// Available check if support current platform
@@ -28,13 +49,13 @@ func (d *CommonInstaller) Available() (ok bool) {
28
49
29
50
// Install installs the target package
30
51
func (d * CommonInstaller ) Install () (err error ) {
31
- err = exec . RunCommand ( d .InstallCmd .Cmd , d . InstallCmd . Args ... )
52
+ err = d .InstallCmd .Run ( )
32
53
return
33
54
}
34
55
35
- // Uninstall uninstalls the Conntrack
56
+ // Uninstall uninstalls the target package
36
57
func (d * CommonInstaller ) Uninstall () (err error ) {
37
- err = exec . RunCommand ( d .UninstallCmd .Cmd , d . UninstallCmd . Args ... )
58
+ err = d .UninstallCmd .Run ( )
38
59
return
39
60
}
40
61
@@ -44,13 +65,13 @@ func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
44
65
return
45
66
}
46
67
47
- // Start starts the Conntrack service
68
+ // Start starts the desired service
48
69
func (d * CommonInstaller ) Start () error {
49
70
fmt .Println ("not supported yet" )
50
71
return nil
51
72
}
52
73
53
- // Stop stops the Conntrack service
74
+ // Stop stops the desired service
54
75
func (d * CommonInstaller ) Stop () error {
55
76
fmt .Println ("not supported yet" )
56
77
return nil
0 commit comments