Skip to content

Commit e2c1da7

Browse files
authored
Add generic install (#259)
1 parent 524ed98 commit e2c1da7

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

pkg/os/generic/common.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}

pkg/os/generic_installer.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/linuxsuren/http-downloader/pkg/os/apt"
1212
"github.com/linuxsuren/http-downloader/pkg/os/brew"
1313
"github.com/linuxsuren/http-downloader/pkg/os/core"
14+
"github.com/linuxsuren/http-downloader/pkg/os/generic"
1415
"github.com/linuxsuren/http-downloader/pkg/os/yum"
1516
"gopkg.in/yaml.v3"
1617
)
@@ -81,6 +82,19 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
8182
genericPackage.CommonInstaller = &brew.CommonInstaller{Name: genericPackage.Name}
8283
case "apk":
8384
genericPackage.CommonInstaller = &apk.CommonInstaller{Name: genericPackage.Name}
85+
default:
86+
genericPackage.CommonInstaller = &generic.CommonInstaller{
87+
Name: genericPackage.Name,
88+
OS: genericPackage.OS,
89+
InstallCmd: generic.CmdWithArgs{
90+
Cmd: genericPackage.InstallCmd.Cmd,
91+
Args: genericPackage.InstallCmd.Args,
92+
},
93+
UninstallCmd: generic.CmdWithArgs{
94+
Cmd: genericPackage.UninstallCmd.Cmd,
95+
Args: genericPackage.UninstallCmd.Args,
96+
},
97+
}
8498
}
8599

86100
registry.Registry(genericPackage.Name, &genericPackage)

0 commit comments

Comments
 (0)