Skip to content

Commit a047287

Browse files
committed
feat: support to install packages via scoop
1 parent 579ac58 commit a047287

File tree

14 files changed

+191
-32
lines changed

14 files changed

+191
-32
lines changed

pkg/exec/command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
OSLinux = "linux"
3131
// OSDarwin is the alias of Darwin
3232
OSDarwin = "darwin"
33+
// OSWindows is the alias of Windows
34+
OSWindows = "windows"
3335
)
3436

3537
// DefaultExecer is a wrapper for the OS exec

pkg/os/apk/common.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ package apk
22

33
import (
44
"fmt"
5+
56
"github.com/linuxsuren/http-downloader/pkg/exec"
67
)
78

9+
const (
10+
// Tool is the tool name of apk
11+
Tool = "apk"
12+
)
13+
814
// CommonInstaller is the installer of a common apk
915
type CommonInstaller struct {
1016
Name string
@@ -13,22 +19,22 @@ type CommonInstaller struct {
1319

1420
// Available check if support current platform
1521
func (d *CommonInstaller) Available() (ok bool) {
16-
if d.Execer.OS() == "linux" {
17-
_, err := d.Execer.LookPath("apk")
22+
if d.Execer.OS() == exec.OSLinux {
23+
_, err := d.Execer.LookPath(Tool)
1824
ok = err == nil
1925
}
2026
return
2127
}
2228

2329
// Install installs the target package
2430
func (d *CommonInstaller) Install() (err error) {
25-
err = d.Execer.RunCommand("apk", "add", d.Name)
31+
err = d.Execer.RunCommand(Tool, "add", d.Name)
2632
return
2733
}
2834

2935
// Uninstall uninstalls the target package
3036
func (d *CommonInstaller) Uninstall() (err error) {
31-
err = d.Execer.RunCommand("apk", "del", d.Name)
37+
err = d.Execer.RunCommand(Tool, "del", d.Name)
3238
return
3339
}
3440

pkg/os/apt/common.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ package apt
22

33
import (
44
"fmt"
5+
56
"github.com/linuxsuren/http-downloader/pkg/exec"
67
)
78

9+
const (
10+
// Tool is the tool name of apt-get
11+
Tool = "apt-get"
12+
)
13+
814
// CommonInstaller is the installer of Conntrack in CentOS
915
type CommonInstaller struct {
1016
Name string
@@ -13,24 +19,24 @@ type CommonInstaller struct {
1319

1420
// Available check if support current platform
1521
func (d *CommonInstaller) Available() (ok bool) {
16-
if d.Execer.OS() == "linux" {
17-
_, err := d.Execer.LookPath("apt-get")
22+
if d.Execer.OS() == exec.OSLinux {
23+
_, err := d.Execer.LookPath(Tool)
1824
ok = err == nil
1925
}
2026
return
2127
}
2228

2329
// Install installs the Conntrack
2430
func (d *CommonInstaller) Install() (err error) {
25-
if err = d.Execer.RunCommand("apt-get", "update", "-y"); err == nil {
26-
err = d.Execer.RunCommand("apt-get", "install", "-y", d.Name)
31+
if err = d.Execer.RunCommand(Tool, "update", "-y"); err == nil {
32+
err = d.Execer.RunCommand(Tool, "install", "-y", d.Name)
2733
}
2834
return
2935
}
3036

3137
// Uninstall uninstalls the Conntrack
3238
func (d *CommonInstaller) Uninstall() (err error) {
33-
err = d.Execer.RunCommand("apt-get", "remove", "-y", d.Name)
39+
err = d.Execer.RunCommand(Tool, "remove", "-y", d.Name)
3440
return
3541
}
3642

pkg/os/brew/common.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ package brew
22

33
import (
44
"fmt"
5+
56
"github.com/linuxsuren/http-downloader/pkg/exec"
67
)
78

9+
const (
10+
// Tool is the tool name of brew
11+
Tool = "brew"
12+
)
13+
814
// CommonInstaller is the installer of a common brew
915
type CommonInstaller struct {
1016
Name string
@@ -13,24 +19,24 @@ type CommonInstaller struct {
1319

1420
// Available check if support current platform
1521
func (d *CommonInstaller) Available() (ok bool) {
16-
if d.Execer.OS() == "darwin" {
17-
_, err := d.Execer.LookPath("brew")
22+
if d.Execer.OS() == exec.OSDarwin || d.Execer.OS() == exec.OSLinux {
23+
_, err := d.Execer.LookPath(Tool)
1824
ok = err == nil
1925
}
2026
return
2127
}
2228

2329
// Install installs the target package
2430
func (d *CommonInstaller) Install() (err error) {
25-
if err = d.Execer.RunCommand("brew", "install", d.Name); err != nil {
31+
if err = d.Execer.RunCommand(Tool, "install", d.Name); err != nil {
2632
return
2733
}
2834
return
2935
}
3036

3137
// Uninstall uninstalls the Conntrack
3238
func (d *CommonInstaller) Uninstall() (err error) {
33-
err = d.Execer.RunCommand("brew", "remove", d.Name)
39+
err = d.Execer.RunCommand(Tool, "remove", d.Name)
3440
return
3541
}
3642

pkg/os/brew/common_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package brew
22

33
import (
44
"errors"
5+
"testing"
6+
57
"github.com/linuxsuren/http-downloader/pkg/exec"
68
"github.com/stretchr/testify/assert"
7-
"testing"
89
)
910

1011
func TestCommon(t *testing.T) {
@@ -28,7 +29,7 @@ func TestCommon(t *testing.T) {
2829
}, {
2930
name: "not is darwin",
3031
installer: CommonInstaller{
31-
Execer: exec.FakeExecer{ExpectOS: "linux"},
32+
Execer: exec.FakeExecer{ExpectOS: exec.OSWindows},
3233
},
3334
expectAvailable: false,
3435
hasErr: false,

pkg/os/dnf/common.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dnf
22

33
import (
44
"fmt"
5+
56
"github.com/linuxsuren/http-downloader/pkg/exec"
67
)
78

@@ -16,24 +17,24 @@ type CommonInstaller struct {
1617

1718
// Available check if support current platform
1819
func (d *CommonInstaller) Available() (ok bool) {
19-
if d.Execer.OS() == "linux" {
20-
_, err := d.Execer.LookPath("dnf")
20+
if d.Execer.OS() == exec.OSLinux {
21+
_, err := d.Execer.LookPath(DNFName)
2122
ok = err == nil
2223
}
2324
return
2425
}
2526

2627
// Install installs the target package
2728
func (d *CommonInstaller) Install() (err error) {
28-
if err = d.Execer.RunCommand("dnf", "install", d.Name, "-y"); err != nil {
29+
if err = d.Execer.RunCommand(DNFName, "install", d.Name, "-y"); err != nil {
2930
return
3031
}
3132
return
3233
}
3334

3435
// Uninstall uninstalls the target
3536
func (d *CommonInstaller) Uninstall() (err error) {
36-
err = d.Execer.RunCommand("dnf", "remove", d.Name, "-y")
37+
err = d.Execer.RunCommand(DNFName, "remove", d.Name, "-y")
3738
return
3839
}
3940

pkg/os/generic_installer.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import (
1717
"github.com/linuxsuren/http-downloader/pkg/os/apk"
1818
"github.com/linuxsuren/http-downloader/pkg/os/dnf"
1919
"github.com/linuxsuren/http-downloader/pkg/os/npm"
20+
"github.com/linuxsuren/http-downloader/pkg/os/scoop"
2021
"github.com/linuxsuren/http-downloader/pkg/os/snap"
22+
"github.com/linuxsuren/http-downloader/pkg/os/winget"
2123

2224
"github.com/linuxsuren/http-downloader/pkg/exec"
2325
"github.com/linuxsuren/http-downloader/pkg/os/apt"
@@ -157,22 +159,22 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
157159
genericPackage.execer = defaultExecer
158160

159161
switch genericPackage.PackageManager {
160-
case "apt-get":
162+
case apt.Tool:
161163
genericPackage.CommonInstaller = &apt.CommonInstaller{
162164
Name: genericPackage.Name,
163165
Execer: defaultExecer,
164166
}
165-
case "yum":
167+
case yum.Tool:
166168
genericPackage.CommonInstaller = &yum.CommonInstaller{
167169
Name: genericPackage.Name,
168170
Execer: defaultExecer,
169171
}
170-
case "brew":
172+
case brew.Tool:
171173
genericPackage.CommonInstaller = &brew.CommonInstaller{
172174
Name: genericPackage.Name,
173175
Execer: defaultExecer,
174176
}
175-
case "apk":
177+
case apk.Tool:
176178
genericPackage.CommonInstaller = &apk.CommonInstaller{
177179
Name: genericPackage.Name,
178180
Execer: defaultExecer,
@@ -193,6 +195,16 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry
193195
Name: genericPackage.Name,
194196
Execer: defaultExecer,
195197
}
198+
case winget.Tool:
199+
genericPackage.CommonInstaller = &winget.CommonInstaller{
200+
Name: genericPackage.Name,
201+
Execer: defaultExecer,
202+
}
203+
case scoop.Tool:
204+
genericPackage.CommonInstaller = &scoop.CommonInstaller{
205+
Name: genericPackage.Name,
206+
Execer: defaultExecer,
207+
}
196208
default:
197209
genericPackage.CommonInstaller = &generic.CommonInstaller{
198210
Name: genericPackage.Name,

pkg/os/npm/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ type CommonInstaller struct {
1717

1818
// Available check if support current platform
1919
func (d *CommonInstaller) Available() (ok bool) {
20-
_, err := d.Execer.LookPath("npm")
20+
_, err := d.Execer.LookPath(NPMName)
2121
ok = err == nil
2222
return
2323
}
2424

2525
// Install installs the target package
2626
func (d *CommonInstaller) Install() (err error) {
27-
err = d.Execer.RunCommand("npm", "i", "-g", d.Name)
27+
err = d.Execer.RunCommand(NPMName, "i", "-g", d.Name)
2828
return
2929
}
3030

3131
// Uninstall uninstalls the target package
3232
func (d *CommonInstaller) Uninstall() (err error) {
33-
err = d.Execer.RunCommand("npm", "uninstall", "-g", d.Name)
33+
err = d.Execer.RunCommand(NPMName, "uninstall", "-g", d.Name)
3434
return
3535
}
3636

pkg/os/scoop/common.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package scoop
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/linuxsuren/http-downloader/pkg/exec"
7+
)
8+
9+
// Tool is the tool name of this intergration
10+
const Tool = "scoop"
11+
12+
// CommonInstaller is the installer of Conntrack in CentOS
13+
type CommonInstaller struct {
14+
Name string
15+
Execer exec.Execer
16+
}
17+
18+
// Available check if support current platform
19+
func (d *CommonInstaller) Available() (ok bool) {
20+
if d.Execer.OS() == exec.OSWindows {
21+
_, err := d.Execer.LookPath(Tool)
22+
ok = err == nil
23+
}
24+
return
25+
}
26+
27+
// Install installs the Conntrack
28+
func (d *CommonInstaller) Install() (err error) {
29+
if err = d.Execer.RunCommand(Tool, "bucket", "add", "extras"); err == nil {
30+
err = d.Execer.RunCommand(Tool, "install", d.Name)
31+
}
32+
return
33+
}
34+
35+
// Uninstall uninstalls the Conntrack
36+
func (d *CommonInstaller) Uninstall() (err error) {
37+
err = d.Execer.RunCommand(Tool, "uninstall", d.Name)
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/scoop/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package scoop implements the scoop integration
2+
package scoop

0 commit comments

Comments
 (0)