Skip to content

Commit b623013

Browse files
authored
Add dnf support (#263)
1 parent 020dab5 commit b623013

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

pkg/os/dnf/common.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package dnf
2+
3+
import (
4+
"fmt"
5+
"github.com/linuxsuren/http-downloader/pkg/exec"
6+
"runtime"
7+
)
8+
9+
// DNFName is the tool name
10+
const DNFName = "dnf"
11+
12+
// CommonInstaller is the installer of a common dnf
13+
type CommonInstaller struct {
14+
Name string
15+
}
16+
17+
// Available check if support current platform
18+
func (d *CommonInstaller) Available() (ok bool) {
19+
if runtime.GOOS == "linux" {
20+
_, err := exec.LookPath("dnf")
21+
ok = err == nil
22+
}
23+
return
24+
}
25+
26+
// Install installs the target package
27+
func (d *CommonInstaller) Install() (err error) {
28+
if err = exec.RunCommand("dnf", "install", d.Name, "-y"); err != nil {
29+
return
30+
}
31+
return
32+
}
33+
34+
// Uninstall uninstalls the target
35+
func (d *CommonInstaller) Uninstall() (err error) {
36+
err = exec.RunCommand("dnf", "remove", d.Name, "-y")
37+
return
38+
}
39+
40+
// WaitForStart waits for the service be started
41+
func (d *CommonInstaller) WaitForStart() (ok bool, err error) {
42+
ok = true
43+
return
44+
}
45+
46+
// Start starts the target service
47+
func (d *CommonInstaller) Start() error {
48+
fmt.Println("not supported yet")
49+
return nil
50+
}
51+
52+
// Stop stops the target service
53+
func (d *CommonInstaller) Stop() error {
54+
fmt.Println("not supported yet")
55+
return nil
56+
}

pkg/os/generic_installer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package os
33
import (
44
"fmt"
55
"github.com/linuxsuren/http-downloader/pkg/os/apk"
6+
"github.com/linuxsuren/http-downloader/pkg/os/dnf"
67
"github.com/linuxsuren/http-downloader/pkg/os/snap"
78
"io/ioutil"
89
"runtime"
@@ -89,6 +90,10 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
8990
Name: genericPackage.Name,
9091
Args: genericPackage.InstallCmd.Args,
9192
}
93+
case dnf.DNFName:
94+
genericPackage.CommonInstaller = &dnf.CommonInstaller{
95+
Name: genericPackage.Name,
96+
}
9297
default:
9398
genericPackage.CommonInstaller = &generic.CommonInstaller{
9499
Name: genericPackage.Name,

0 commit comments

Comments
 (0)