|
| 1 | +package generic |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "github.com/linuxsuren/http-downloader/pkg/exec" |
| 6 | + "runtime" |
| 7 | +) |
| 8 | + |
| 9 | +// CommonInstaller is the installer of a common bash |
| 10 | +type CommonInstaller struct { |
| 11 | + Name string |
| 12 | + OS string |
| 13 | + InstallCmd CmdWithArgs |
| 14 | + UninstallCmd CmdWithArgs |
| 15 | +} |
| 16 | + |
| 17 | +// CmdWithArgs is a command and with args |
| 18 | +type CmdWithArgs struct { |
| 19 | + Cmd string `yaml:"cmd"` |
| 20 | + Args []string `yaml:"args"` |
| 21 | +} |
| 22 | + |
| 23 | +// Available check if support current platform |
| 24 | +func (d *CommonInstaller) Available() (ok bool) { |
| 25 | + ok = d.OS == "" || runtime.GOOS == d.OS |
| 26 | + return |
| 27 | +} |
| 28 | + |
| 29 | +// Install installs the target package |
| 30 | +func (d *CommonInstaller) Install() (err error) { |
| 31 | + err = exec.RunCommand(d.InstallCmd.Cmd, d.InstallCmd.Args...) |
| 32 | + return |
| 33 | +} |
| 34 | + |
| 35 | +// Uninstall uninstalls the Conntrack |
| 36 | +func (d *CommonInstaller) Uninstall() (err error) { |
| 37 | + err = exec.RunCommand(d.UninstallCmd.Cmd, d.UninstallCmd.Args...) |
| 38 | + return |
| 39 | +} |
| 40 | + |
| 41 | +// WaitForStart waits for the service be started |
| 42 | +func (d *CommonInstaller) WaitForStart() (ok bool, err error) { |
| 43 | + ok = true |
| 44 | + return |
| 45 | +} |
| 46 | + |
| 47 | +// Start starts the Conntrack service |
| 48 | +func (d *CommonInstaller) Start() error { |
| 49 | + fmt.Println("not supported yet") |
| 50 | + return nil |
| 51 | +} |
| 52 | + |
| 53 | +// Stop stops the Conntrack service |
| 54 | +func (d *CommonInstaller) Stop() error { |
| 55 | + fmt.Println("not supported yet") |
| 56 | + return nil |
| 57 | +} |
0 commit comments