generated from Tux-MacG1v/preview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
108 lines (91 loc) · 2.25 KB
/
main.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
package main
import (
"fmt"
"io"
"net/http"
"os"
"os/exec"
"strings"
)
func importModule(moduleName string) error {
cmd := exec.Command("go", "get", moduleName)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func downloadGitHubRelease(owner, repo string) error {
tagNameURL := fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/main/version.db", owner, repo)
resp, err := http.Get(tagNameURL)
if err != nil {
return err
}
defer resp.Body.Close()
tagName := ""
if resp.StatusCode == http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
tagName = strings.TrimSpace(string(bodyBytes))
}
if tagName == "" {
return fmt.Errorf("failed to get tag name")
}
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/tags/%s", owner, repo, tagName)
resp, err = http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to get release info")
}
var releaseInfo struct {
Assets []struct {
BrowserDownloadURL string `json:"browser_download_url"`
Name string `json:"name"`
} `json:"assets"`
}
if err := json.NewDecoder(resp.Body).Decode(&releaseInfo); err != nil {
return err
}
currentDir, err := os.Getwd()
if err != nil {
return err
}
for _, asset := range releaseInfo.Assets {
assetURL := asset.BrowserDownloadURL
assetName := asset.Name
downloadPath := filepath.Join(currentDir, assetName)
fmt.Println("Downloading ULTIMATE-FINDER...")
resp, err := http.Get(assetURL)
if err != nil {
return err
}
defer resp.Body.Close()
out, err := os.Create(downloadPath)
if err != nil {
return err
}
defer out.Close()
if _, err := io.Copy(out, resp.Body); err != nil {
return err
}
}
fmt.Println("LATEST TOOL DOWNLOAD COMPLETE...")
fmt.Println()
executablePath := filepath.Join(currentDir, releaseInfo.Assets[0].Name)
fmt.Println("TOOL IS RUNNING...")
cmd := exec.Command(executablePath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func main() {
owner := "Tux-MacG1v"
repo := "A-ULTIMATE-FINDER"
fmt.Println("SEARCHING FOR LATEST...")
if err := downloadGitHubRelease(owner, repo); err != nil {
fmt.Printf("Error: %v\n", err)
}
}