Skip to content

Commit e6b335f

Browse files
authored
Add support install socat and conntrack (#103)
1 parent e674f5b commit e6b335f

File tree

8 files changed

+207
-70
lines changed

8 files changed

+207
-70
lines changed

pkg/os/apt/conntrack.go

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

pkg/os/apt/docker.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"time"
1010
)
1111

12-
// DockerInstallerInUbuntu is the installer of Docker in Ubuntu
13-
type DockerInstallerInUbuntu struct {
12+
// dockerInstallerInUbuntu is the installer of Docker in Ubuntu
13+
type dockerInstallerInUbuntu struct {
1414
count int
1515
}
1616

1717
// Available check if support current platform
18-
func (d *DockerInstallerInUbuntu) Available() (ok bool) {
18+
func (d *dockerInstallerInUbuntu) Available() (ok bool) {
1919
if runtime.GOOS == "linux" {
2020
_, err := exec.LookPath("apt-get")
2121
ok = err == nil
@@ -24,7 +24,7 @@ func (d *DockerInstallerInUbuntu) Available() (ok bool) {
2424
}
2525

2626
// Install installs the Docker
27-
func (d *DockerInstallerInUbuntu) Install() (err error) {
27+
func (d *dockerInstallerInUbuntu) Install() (err error) {
2828
if err = exec.RunCommand("apt-get", "update", "-y"); err != nil {
2929
return
3030
}
@@ -79,7 +79,7 @@ func (d *DockerInstallerInUbuntu) Install() (err error) {
7979
}
8080

8181
// Uninstall uninstalls the Docker
82-
func (d *DockerInstallerInUbuntu) Uninstall() (err error) {
82+
func (d *dockerInstallerInUbuntu) Uninstall() (err error) {
8383
if err = exec.RunCommand("apt-get", "remove", "-y",
8484
"docker",
8585
"docker-engine",
@@ -96,7 +96,7 @@ func (d *DockerInstallerInUbuntu) Uninstall() (err error) {
9696
}
9797

9898
// WaitForStart waits for the service be started
99-
func (d *DockerInstallerInUbuntu) WaitForStart() (ok bool, err error) {
99+
func (d *dockerInstallerInUbuntu) WaitForStart() (ok bool, err error) {
100100
var result string
101101
if result, err = exec.RunCommandAndReturn("systemctl", "", "status", "docker"); err != nil {
102102
return
@@ -119,12 +119,12 @@ func (d *DockerInstallerInUbuntu) WaitForStart() (ok bool, err error) {
119119
}
120120

121121
// Start starts the Docker service
122-
func (d *DockerInstallerInUbuntu) Start() error {
122+
func (d *dockerInstallerInUbuntu) Start() error {
123123
fmt.Println("not implemented yet")
124124
return nil
125125
}
126126

127127
// Stop stops the Docker service
128-
func (d *DockerInstallerInUbuntu) Stop() error {
128+
func (d *dockerInstallerInUbuntu) Stop() error {
129129
return exec.RunCommand("systemctl", "start", "docker")
130130
}

pkg/os/apt/init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ import "github.com/linuxsuren/http-downloader/pkg/os/core"
44

55
// SetInstallerRegistry sets the installer of registry
66
func SetInstallerRegistry(registry core.InstallerRegistry) {
7-
registry.Registry("docker", &DockerInstallerInUbuntu{})
7+
registry.Registry("docker", &dockerInstallerInUbuntu{})
8+
registry.Registry("conntrack", &conntrackInstallerInUbuntu{})
9+
registry.Registry("socat", &socatInstallerInUbuntu{})
810
}

pkg/os/apt/socat.go

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

pkg/os/yum/conntrack.go

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ import (
44
"fmt"
55
"github.com/linuxsuren/http-downloader/pkg/exec"
66
"runtime"
7-
"strings"
8-
"time"
97
)
108

11-
// ConntrackInstallerInCentOS is the installer of Docker in CentOS
12-
type ConntrackInstallerInCentOS struct {
9+
// conntrackInstallerInCentOS is the installer of Docker in CentOS
10+
type conntrackInstallerInCentOS struct {
1311
count int
1412
}
1513

1614
// Available check if support current platform
17-
func (d *ConntrackInstallerInCentOS) Available() (ok bool) {
15+
func (d *conntrackInstallerInCentOS) Available() (ok bool) {
1816
if runtime.GOOS == "linux" {
1917
_, err := exec.LookPath("yum")
2018
ok = err == nil
@@ -23,70 +21,35 @@ func (d *ConntrackInstallerInCentOS) Available() (ok bool) {
2321
}
2422

2523
// Install installs the Docker
26-
func (d *ConntrackInstallerInCentOS) Install() (err error) {
24+
func (d *conntrackInstallerInCentOS) Install() (err error) {
2725
if err = exec.RunCommand("yum", "install", "-y",
28-
"yum-utils"); err != nil {
29-
return
30-
}
31-
if err = exec.RunCommand("yum-config-manager", "--add-repo",
32-
"https://download.docker.com/linux/centos/docker-ce.repo"); err != nil {
33-
return
34-
}
35-
if err = exec.RunCommand("yum", "install", "-y",
36-
"docker-ce",
37-
"docker-ce-cli",
38-
"containerd.io"); err != nil {
26+
"conntrack"); err != nil {
3927
return
4028
}
4129
return
4230
}
4331

4432
// Uninstall uninstalls the Docker
45-
func (d *ConntrackInstallerInCentOS) Uninstall() (err error) {
33+
func (d *conntrackInstallerInCentOS) Uninstall() (err error) {
4634
err = exec.RunCommand("yum", "remove", "-y",
47-
"docker",
48-
"docker-client",
49-
"docker-client-latest",
50-
"docker-common",
51-
"docker-latest",
52-
"docker-latest-logrotate",
53-
"docker-logrotate",
54-
"docker-engine",
55-
"docker-ce",
56-
"docker-ce-cli",
57-
"containerd.io")
35+
"conntrack")
5836
return
5937
}
6038

6139
// WaitForStart waits for the service be started
62-
func (d *ConntrackInstallerInCentOS) WaitForStart() (ok bool, err error) {
63-
var result string
64-
if result, err = exec.RunCommandAndReturn("systemctl", "", "status", "docker"); err != nil {
65-
return
66-
} else if strings.Contains(result, "Unit docker.service could not be found") {
67-
err = fmt.Errorf("unit docker.service could not be found")
68-
} else if strings.Contains(result, "Active: active") {
69-
ok = true
70-
} else {
71-
if d.count > 0 {
72-
fmt.Println("waiting for Docker service start")
73-
} else if d.count > 9 {
74-
return
75-
}
76-
77-
d.count++
78-
time.Sleep(time.Second * 1)
79-
return d.WaitForStart()
80-
}
40+
func (d *conntrackInstallerInCentOS) WaitForStart() (ok bool, err error) {
41+
ok = true
8142
return
8243
}
8344

8445
// Start starts the Docker service
85-
func (d *ConntrackInstallerInCentOS) Start() error {
86-
return exec.RunCommand("systemctl", "start", "docker")
46+
func (d *conntrackInstallerInCentOS) Start() error {
47+
fmt.Println("not supported yet")
48+
return nil
8749
}
8850

8951
// Stop stops the Docker service
90-
func (d *ConntrackInstallerInCentOS) Stop() error {
91-
return exec.RunCommand("systemctl", "stop", "docker")
52+
func (d *conntrackInstallerInCentOS) Stop() error {
53+
fmt.Println("not supported yet")
54+
return nil
9255
}

pkg/os/yum/docker.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"time"
99
)
1010

11-
// DockerInstallerInCentOS is the installer of Docker in CentOS
12-
type DockerInstallerInCentOS struct {
11+
// dockerInstallerInCentOS is the installer of Docker in CentOS
12+
type dockerInstallerInCentOS struct {
1313
count int
1414
}
1515

1616
// Available check if support current platform
17-
func (d *DockerInstallerInCentOS) Available() (ok bool) {
17+
func (d *dockerInstallerInCentOS) Available() (ok bool) {
1818
if runtime.GOOS == "linux" {
1919
_, err := exec.LookPath("yum")
2020
ok = err == nil
@@ -23,7 +23,7 @@ func (d *DockerInstallerInCentOS) Available() (ok bool) {
2323
}
2424

2525
// Install installs the Docker
26-
func (d *DockerInstallerInCentOS) Install() (err error) {
26+
func (d *dockerInstallerInCentOS) Install() (err error) {
2727
if err = exec.RunCommand("yum", "install", "-y",
2828
"yum-utils"); err != nil {
2929
return
@@ -42,7 +42,7 @@ func (d *DockerInstallerInCentOS) Install() (err error) {
4242
}
4343

4444
// Uninstall uninstalls the Docker
45-
func (d *DockerInstallerInCentOS) Uninstall() (err error) {
45+
func (d *dockerInstallerInCentOS) Uninstall() (err error) {
4646
err = exec.RunCommand("yum", "remove", "-y",
4747
"docker",
4848
"docker-client",
@@ -59,7 +59,7 @@ func (d *DockerInstallerInCentOS) Uninstall() (err error) {
5959
}
6060

6161
// WaitForStart waits for the service be started
62-
func (d *DockerInstallerInCentOS) WaitForStart() (ok bool, err error) {
62+
func (d *dockerInstallerInCentOS) WaitForStart() (ok bool, err error) {
6363
var result string
6464
if result, err = exec.RunCommandAndReturn("systemctl", "", "status", "docker"); err != nil {
6565
return
@@ -82,11 +82,11 @@ func (d *DockerInstallerInCentOS) WaitForStart() (ok bool, err error) {
8282
}
8383

8484
// Start starts the Docker service
85-
func (d *DockerInstallerInCentOS) Start() error {
85+
func (d *dockerInstallerInCentOS) Start() error {
8686
return exec.RunCommand("systemctl", "start", "docker")
8787
}
8888

8989
// Stop stops the Docker service
90-
func (d *DockerInstallerInCentOS) Stop() error {
90+
func (d *dockerInstallerInCentOS) Stop() error {
9191
return exec.RunCommand("systemctl", "stop", "docker")
9292
}

pkg/os/yum/init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ import "github.com/linuxsuren/http-downloader/pkg/os/core"
44

55
// SetInstallerRegistry sets the installer of registry
66
func SetInstallerRegistry(registry core.InstallerRegistry) {
7-
registry.Registry("docker", &DockerInstallerInCentOS{})
7+
registry.Registry("docker", &dockerInstallerInCentOS{})
8+
registry.Registry("conntrack", &conntrackInstallerInCentOS{})
9+
registry.Registry("socat", &socatInstallerInCentOS{})
810
}

0 commit comments

Comments
 (0)