-
Notifications
You must be signed in to change notification settings - Fork 38
/
install3.go
157 lines (127 loc) · 3 KB
/
install3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)
func swapFile() error {
cmd := exec.Command("sudo", "fallocate", "-l", "2G", "/swapfile")
err := cmd.Run()
if err != nil {
return err
}
cmd = exec.Command("sudo", "chmod", "600", "/swapfile")
err = cmd.Run()
if err != nil {
return err
}
cmd = exec.Command("sudo", "mkswap", "/swapfile")
err = cmd.Run()
if err != nil {
return err
}
cmd = exec.Command("sudo", "swapon", "/swapfile")
err = cmd.Run()
if err != nil {
return err
}
return nil
}
func install() error {
log.Println("\033[93mCloning repo..\033[0m")
err := os.RemoveAll("/root/rathole")
if err != nil {
return fmt.Errorf("\033[91merror @removing existing rathole dir: %s\033[0m", err.Error())
}
cmd := exec.Command("git", "clone", "https://github.com/miyugundam/rathole.git")
err = cmd.Run()
if err != nil {
return fmt.Errorf("\033[91merror cloning repository: %s\033[0m", err.Error())
}
log.Println("\033[92mRepo's clone was successful\033[0m")
return nil
}
func cargoToml() error {
cargoFile := "/root/rathole/Cargo.toml"
_, err := os.Stat(cargoFile)
if os.IsNotExist(err) {
return nil
} else if err != nil {
return err
}
file, err := os.OpenFile(cargoFile, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer file.Close()
_, err = file.WriteString("\n[workspace]\n")
if err != nil {
return err
}
return nil
}
func buildRat() error {
log.Println("\033[92mBuilding rathole..\033[0m")
cmd := exec.Command("cargo", "build")
cmd.Dir = "/root/rathole"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
log.Println("\033[92mRathole built successfully!\033[0m")
return nil
}
func swap() (bool, error) {
cmd := exec.Command("free", "-h")
output, err := cmd.Output()
if err != nil {
return false, err
}
fmt.Println(string(output))
cmd = exec.Command("swapon", "--show")
output, err = cmd.Output()
if err != nil {
return false, err
}
return strings.Contains(string(output), "/swapfile"), nil
}
func main() {
cmd := exec.Command("bash", "-c", "curl -sSf https://raw.githubusercontent.com/Azumi67/Rathole_reverseTunnel/main/rust2.sh | bash")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatal("\033[91merror running rust2.sh:\033[0m", err)
}
log.Println("\033[92mRust installation completed!\033[0m")
swapEnabled, err := swap()
if err != nil {
log.Fatal("\033[91merror checking swap status:\033[0m", err)
}
if !swapEnabled {
err := swapFile()
if err != nil {
log.Fatal("\033[91merror swapping:\033[0m", err)
}
}
err = install()
if err != nil {
log.Fatal("\033[91merror cloning repo:\033[0m", err)
}
err = os.Chdir("/root/rathole")
if err != nil {
log.Fatal("\033[91merror changing dir to rathole:\033[0m", err)
}
err = cargoToml()
if err != nil {
log.Fatal("\033[91merror modifying Cargo:\033[0m", err)
}
err = buildRat()
if err != nil {
log.Fatal("\033[91merror building rat holz:\033[0m", err)
}
}