|
1 | 1 | package core |
2 | 2 |
|
3 | | -import ( |
4 | | - log "github.com/sirupsen/logrus" |
5 | | - "github.com/tj/go-update" |
6 | | - "github.com/tj/go-update/progress" |
7 | | - githubUpdateStore "github.com/tj/go-update/stores/github" |
8 | | - "runtime" |
9 | | - "strings" |
10 | | -) |
11 | | - |
12 | | -const ( |
13 | | - Owner = "SummerSec" |
14 | | - Repo = "SpringExploit" |
15 | | -) |
16 | | - |
17 | | -func selfUpdate() { |
18 | | - var command string |
19 | | - switch runtime.GOOS { |
20 | | - case "windows": |
21 | | - command = Repo + ".exe" |
22 | | - default: |
23 | | - command = Repo |
24 | | - } |
25 | | - m := &update.Manager{ |
26 | | - Command: command, |
27 | | - Store: &githubUpdateStore.Store{ |
28 | | - Owner: Owner, |
29 | | - Repo: Repo, |
30 | | - Version: version, |
31 | | - }, |
32 | | - } |
33 | | - |
34 | | - releases, err := m.LatestReleases() |
35 | | - if err != nil { |
36 | | - log.Error("Failed to get releases", err) |
37 | | - return |
38 | | - } |
39 | | - if len(releases) == 0 { |
40 | | - log.Info("No updates available") |
41 | | - return |
42 | | - } |
43 | | - latest := releases[0] |
44 | | - var currentOS string |
45 | | - switch runtime.GOOS { |
46 | | - case "darwin": |
47 | | - currentOS = "macOS" |
48 | | - default: |
49 | | - currentOS = runtime.GOOS |
50 | | - } |
51 | | - final := latest.FindZip(currentOS, runtime.GOARCH) |
52 | | - if final == nil { |
53 | | - log.Error("No update available for", currentOS, "and", runtime.GOARCH) |
54 | | - } |
55 | | - tarball, err := final.DownloadProxy(progress.Reader) |
56 | | - if err != nil { |
57 | | - log.Error("could not install latest release ", err) |
58 | | - return |
59 | | - } |
60 | | - if err := m.Install(tarball); err != nil { |
61 | | - log.Error("could not install latest release", err) |
62 | | - return |
63 | | - } |
64 | | - |
65 | | - log.Infof("Successfully Updated to %s Version %s", Repo, latest.Version) |
66 | | - |
67 | | -} |
68 | | - |
69 | | -// 获取最新版本 |
70 | | -func getLatestVersion() { |
71 | | - log.Info("Crrunent Version : ", version) |
72 | | - latestverion := getLatestVersionFromGithub() |
73 | | - log.Infof("Latest Version: %s", latestverion) |
74 | | - if strings.Compare(latestverion, version) > 0 { |
75 | | - log.Info("Use Command SpringExploit -update to update to latest version ") |
76 | | - } |
77 | | - |
78 | | -} |
79 | | - |
80 | | -// 从github获取最新版本 |
81 | | -func getLatestVersionFromGithub() string { |
82 | | - m := &update.Manager{ |
83 | | - Store: &githubUpdateStore.Store{ |
84 | | - Owner: Owner, |
85 | | - Repo: Repo, |
86 | | - Version: version, |
87 | | - }, |
88 | | - } |
89 | | - releases, err := m.LatestReleases() |
90 | | - if err != nil { |
91 | | - log.Error("Failed to get releases ", err) |
92 | | - return "" |
93 | | - } |
94 | | - defer func() { |
95 | | - if errs := recover(); errs != nil { |
96 | | - log.Debug("No updates available ", errs) |
97 | | - } |
98 | | - }() |
99 | | - |
100 | | - if releases == nil { |
101 | | - log.Info("No updates available") |
102 | | - return version |
103 | | - } else { |
104 | | - return releases[0].Version |
105 | | - } |
106 | | -} |
| 3 | +// |
| 4 | +//import ( |
| 5 | +// log "github.com/sirupsen/logrus" |
| 6 | +// "github.com/tj/go-update" |
| 7 | +// "github.com/tj/go-update/progress" |
| 8 | +// githubUpdateStore "github.com/tj/go-update/stores/github" |
| 9 | +// "runtime" |
| 10 | +// "strings" |
| 11 | +//) |
| 12 | +// |
| 13 | +//const ( |
| 14 | +// Owner = "SummerSec" |
| 15 | +// Repo = "SpringExploit" |
| 16 | +//) |
| 17 | +// |
| 18 | +//func selfUpdate() { |
| 19 | +// var command string |
| 20 | +// |
| 21 | +// //// get current executable path |
| 22 | +// //executable, err := os.Executable() |
| 23 | +// //if err != nil { |
| 24 | +// // log.Fatal(err) |
| 25 | +// //} |
| 26 | +// |
| 27 | +// switch runtime.GOOS { |
| 28 | +// case "windows": |
| 29 | +// command = Repo + ".exe" |
| 30 | +// default: |
| 31 | +// command = Repo |
| 32 | +// } |
| 33 | +// log.Debugf("command: %s", command) |
| 34 | +// m := &update.Manager{ |
| 35 | +// Command: command, |
| 36 | +// Store: &githubUpdateStore.Store{ |
| 37 | +// Owner: Owner, |
| 38 | +// Repo: Repo, |
| 39 | +// Version: version, |
| 40 | +// }, |
| 41 | +// } |
| 42 | +// |
| 43 | +// releases, err := m.LatestReleases() |
| 44 | +// if err != nil { |
| 45 | +// log.Error("Failed to get releases", err) |
| 46 | +// return |
| 47 | +// } |
| 48 | +// if len(releases) == 0 { |
| 49 | +// log.Info("No updates available") |
| 50 | +// return |
| 51 | +// } |
| 52 | +// latest := releases[0] |
| 53 | +// var currentOS string |
| 54 | +// switch runtime.GOOS { |
| 55 | +// case "darwin": |
| 56 | +// currentOS = "macOS" |
| 57 | +// default: |
| 58 | +// currentOS = runtime.GOOS |
| 59 | +// } |
| 60 | +// final := latest.FindZip(currentOS, runtime.GOARCH) |
| 61 | +// if final == nil { |
| 62 | +// log.Error("No update available for", currentOS, "and", runtime.GOARCH) |
| 63 | +// } |
| 64 | +// tarball, err := final.DownloadProxy(progress.Reader) |
| 65 | +// if err != nil { |
| 66 | +// log.Error("could not install latest release ", err) |
| 67 | +// return |
| 68 | +// } |
| 69 | +// if err := m.Install(tarball); err != nil { |
| 70 | +// log.Error("could not install latest release", err) |
| 71 | +// return |
| 72 | +// } |
| 73 | +// |
| 74 | +// log.Infof("Successfully Updated to %s Version %s", Repo, latest.Version) |
| 75 | +// |
| 76 | +//} |
| 77 | +// |
| 78 | +//// 获取最新版本 |
| 79 | +//func getLatestVersion() { |
| 80 | +// log.Info("Crrunent Version : ", version) |
| 81 | +// latestverion := getLatestVersionFromGithub() |
| 82 | +// log.Infof("Latest Version: %s", latestverion) |
| 83 | +// if strings.Compare(latestverion, version) > 0 { |
| 84 | +// log.Info("Use Command SpringExploit -update to update to latest version ") |
| 85 | +// } |
| 86 | +// |
| 87 | +//} |
| 88 | +// |
| 89 | +//// 从github获取最新版本 |
| 90 | +//func getLatestVersionFromGithub() string { |
| 91 | +// m := &update.Manager{ |
| 92 | +// Store: &githubUpdateStore.Store{ |
| 93 | +// Owner: Owner, |
| 94 | +// Repo: Repo, |
| 95 | +// Version: version, |
| 96 | +// }, |
| 97 | +// } |
| 98 | +// releases, err := m.LatestReleases() |
| 99 | +// if err != nil { |
| 100 | +// log.Error("Failed to get releases ", err) |
| 101 | +// return "" |
| 102 | +// } |
| 103 | +// defer func() { |
| 104 | +// if errs := recover(); errs != nil { |
| 105 | +// log.Debug("No updates available ", errs) |
| 106 | +// } |
| 107 | +// }() |
| 108 | +// |
| 109 | +// if releases == nil { |
| 110 | +// log.Info("No updates available") |
| 111 | +// return version |
| 112 | +// } else { |
| 113 | +// return releases[0].Version |
| 114 | +// } |
| 115 | +//} |
0 commit comments