Skip to content

Commit bdea67b

Browse files
authored
Add apk support (#257)
1 parent ea4cba7 commit bdea67b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

pkg/os/apk/common.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package apk
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 apk
10+
type CommonInstaller struct {
11+
Name string
12+
}
13+
14+
// Available check if support current platform
15+
func (d *CommonInstaller) Available() (ok bool) {
16+
if runtime.GOOS == "linux" {
17+
_, err := exec.LookPath("apk")
18+
ok = err == nil
19+
}
20+
return
21+
}
22+
23+
// Install installs the target package
24+
func (d *CommonInstaller) Install() (err error) {
25+
if err = exec.RunCommand("apk", "add", d.Name); err != nil {
26+
return
27+
}
28+
return
29+
}
30+
31+
// Uninstall uninstalls the Conntrack
32+
func (d *CommonInstaller) Uninstall() (err error) {
33+
err = exec.RunCommand("apk", "del", d.Name)
34+
return
35+
}
36+
37+
// WaitForStart waits for the service be started
38+
func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
39+
ok = true
40+
return
41+
}
42+
43+
// Start starts the Conntrack service
44+
func (d *CommonInstaller) Start() error {
45+
fmt.Println("not supported yet")
46+
return nil
47+
}
48+
49+
// Stop stops the Conntrack service
50+
func (d *CommonInstaller) Stop() error {
51+
fmt.Println("not supported yet")
52+
return nil
53+
}

pkg/os/generic_installer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package os
22

33
import (
44
"fmt"
5+
"github.com/linuxsuren/http-downloader/pkg/os/apk"
56
"io/ioutil"
67
"runtime"
78
"strings"
@@ -78,6 +79,8 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
7879
genericPackage.CommonInstaller = &yum.CommonInstaller{Name: genericPackage.Name}
7980
case "brew":
8081
genericPackage.CommonInstaller = &brew.CommonInstaller{Name: genericPackage.Name}
82+
case "apk":
83+
genericPackage.CommonInstaller = &apk.CommonInstaller{Name: genericPackage.Name}
8184
}
8285

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

0 commit comments

Comments
 (0)