Skip to content

Commit 3548f88

Browse files
committed
🛸使用go-github-update框架,替代原本go-update框架。原本框架在Linux体验并不是很好
1 parent 25708c0 commit 3548f88

File tree

6 files changed

+269
-119
lines changed

6 files changed

+269
-119
lines changed

cmd/commons/core/runner.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,16 @@ func (r *Runner) Run() {
4242
} else if r.options.IP != "" {
4343
urls = utils.GetIPToUrlsLinks(r.options.IP, urls)
4444
} else if r.options.Update {
45-
selfUpdate()
45+
// go update
46+
//selfUpdate()
47+
// go github update
48+
doSelfUpdate()
49+
return
4650
} else if r.options.Version {
47-
getLatestVersion()
51+
// go update
52+
//getLatestVersion()
53+
// go github update
54+
confirmAndSelfUpdate()
4855
return
4956
} else if r.options.SP {
5057
return

cmd/commons/core/update.go

Lines changed: 113 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,115 @@
11
package core
22

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+
//}

cmd/commons/core/update2.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package core
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"github.com/blang/semver"
7+
"github.com/rhysd/go-github-selfupdate/selfupdate"
8+
log "github.com/sirupsen/logrus"
9+
"os"
10+
)
11+
12+
const info = "SummerSec/SpringExploit"
13+
14+
func doSelfUpdate() {
15+
latest, found, err := selfupdate.DetectLatest(info)
16+
if err != nil {
17+
log.Infoln("Error occurred while detecting version:", err)
18+
return
19+
}
20+
21+
v := semver.MustParse(version)
22+
if !found || latest.Version.LTE(v) {
23+
log.Infof("Current binary is the latest version %s", version)
24+
return
25+
}
26+
27+
latest1, err := selfupdate.UpdateSelf(v, info)
28+
29+
if latest1.Version.LTE(v) {
30+
log.Infof("Current binary is the latest version %s", version)
31+
32+
} else {
33+
log.Infoln("Successfully updated to version", latest.Version)
34+
log.Infoln("Release note:\n", latest.ReleaseNotes)
35+
}
36+
}
37+
38+
func confirmAndSelfUpdate() {
39+
latest, found, err := selfupdate.DetectLatest(info)
40+
if err != nil {
41+
log.Infoln("Error occurred while detecting version:", err)
42+
return
43+
}
44+
45+
v := semver.MustParse(version)
46+
if !found || latest.Version.LTE(v) {
47+
log.Infof("Current version is the latest version %s", version)
48+
return
49+
}
50+
51+
fmt.Print("Do you want to update to", latest.Version, "? (y/n): ")
52+
input, err := bufio.NewReader(os.Stdin).ReadString('\n')
53+
if err != nil || (input != "y\n" && input != "n\n") {
54+
log.Println("Invalid input")
55+
return
56+
}
57+
if input == "n\n" {
58+
return
59+
}
60+
61+
exe, err := os.Executable()
62+
if err != nil {
63+
log.Println("Could not locate executable path")
64+
return
65+
}
66+
if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil {
67+
log.Println("Error occurred while updating binary:", err)
68+
return
69+
}
70+
log.Println("Successfully updated to version", latest.Version)
71+
}

cmd/test/ip.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"os"
45
"strings"
56
)
67

@@ -21,4 +22,24 @@ func main() {
2122

2223
println(u1)
2324
println(u2)
25+
26+
// get the current directory
27+
dir, err := os.Getwd()
28+
if err != nil {
29+
panic(err)
30+
}
31+
println(dir)
32+
33+
// get current executable path
34+
executable, err := os.Executable()
35+
if err != nil {
36+
}
37+
println(executable)
38+
39+
d, err := os.Stat("SpringExploit.exe")
40+
if err != nil {
41+
42+
}
43+
println(d.Name())
44+
2445
}

go.mod

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ require (
1313
)
1414

1515
require (
16-
github.com/apex/log v1.9.0 // indirect
17-
github.com/c-bata/go-prompt v0.2.6 // indirect
18-
github.com/c4milo/unpackit v0.1.0 // indirect
19-
github.com/google/go-github v17.0.0+incompatible // indirect
16+
//github.com/apex/log v1.9.0 // indirect
17+
github.com/blang/semver v3.5.1+incompatible
18+
github.com/c-bata/go-prompt v0.2.6
19+
//github.com/c4milo/unpackit v0.1.0 // indirect
20+
//github.com/google/go-github v17.0.0+incompatible // indirect
2021
github.com/google/go-querystring v1.1.0 // indirect
21-
github.com/gosuri/uilive v0.0.4 // indirect
22-
github.com/gosuri/uiprogress v0.0.1 // indirect
23-
github.com/hashicorp/errwrap v1.0.0 // indirect
24-
github.com/hashicorp/go-multierror v1.1.1 // indirect
25-
github.com/panjf2000/ants/v2 v2.5.0 // indirect
26-
github.com/projectdiscovery/blackrock v0.0.0-20210415162320-b38689ae3a2e // indirect
27-
github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible
28-
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect
29-
golang.org/x/text v0.3.7 // indirect
22+
//github.com/gosuri/uilive v0.0.4 // indirect
23+
//github.com/gosuri/uiprogress v0.0.1 // indirect
24+
github.com/panjf2000/ants/v2 v2.5.0
25+
github.com/rhysd/go-github-selfupdate v1.2.3
26+
//github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible
3027
)

0 commit comments

Comments
 (0)