generated from SummerSec/template
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🛸使用go-github-update框架,替代原本go-update框架。原本框架在Linux体验并不是很好
- Loading branch information
Showing
6 changed files
with
269 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,115 @@ | ||
package core | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/tj/go-update" | ||
"github.com/tj/go-update/progress" | ||
githubUpdateStore "github.com/tj/go-update/stores/github" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
const ( | ||
Owner = "SummerSec" | ||
Repo = "SpringExploit" | ||
) | ||
|
||
func selfUpdate() { | ||
var command string | ||
switch runtime.GOOS { | ||
case "windows": | ||
command = Repo + ".exe" | ||
default: | ||
command = Repo | ||
} | ||
m := &update.Manager{ | ||
Command: command, | ||
Store: &githubUpdateStore.Store{ | ||
Owner: Owner, | ||
Repo: Repo, | ||
Version: version, | ||
}, | ||
} | ||
|
||
releases, err := m.LatestReleases() | ||
if err != nil { | ||
log.Error("Failed to get releases", err) | ||
return | ||
} | ||
if len(releases) == 0 { | ||
log.Info("No updates available") | ||
return | ||
} | ||
latest := releases[0] | ||
var currentOS string | ||
switch runtime.GOOS { | ||
case "darwin": | ||
currentOS = "macOS" | ||
default: | ||
currentOS = runtime.GOOS | ||
} | ||
final := latest.FindZip(currentOS, runtime.GOARCH) | ||
if final == nil { | ||
log.Error("No update available for", currentOS, "and", runtime.GOARCH) | ||
} | ||
tarball, err := final.DownloadProxy(progress.Reader) | ||
if err != nil { | ||
log.Error("could not install latest release ", err) | ||
return | ||
} | ||
if err := m.Install(tarball); err != nil { | ||
log.Error("could not install latest release", err) | ||
return | ||
} | ||
|
||
log.Infof("Successfully Updated to %s Version %s", Repo, latest.Version) | ||
|
||
} | ||
|
||
// 获取最新版本 | ||
func getLatestVersion() { | ||
log.Info("Crrunent Version : ", version) | ||
latestverion := getLatestVersionFromGithub() | ||
log.Infof("Latest Version: %s", latestverion) | ||
if strings.Compare(latestverion, version) > 0 { | ||
log.Info("Use Command SpringExploit -update to update to latest version ") | ||
} | ||
|
||
} | ||
|
||
// 从github获取最新版本 | ||
func getLatestVersionFromGithub() string { | ||
m := &update.Manager{ | ||
Store: &githubUpdateStore.Store{ | ||
Owner: Owner, | ||
Repo: Repo, | ||
Version: version, | ||
}, | ||
} | ||
releases, err := m.LatestReleases() | ||
if err != nil { | ||
log.Error("Failed to get releases ", err) | ||
return "" | ||
} | ||
defer func() { | ||
if errs := recover(); errs != nil { | ||
log.Debug("No updates available ", errs) | ||
} | ||
}() | ||
|
||
if releases == nil { | ||
log.Info("No updates available") | ||
return version | ||
} else { | ||
return releases[0].Version | ||
} | ||
} | ||
// | ||
//import ( | ||
// log "github.com/sirupsen/logrus" | ||
// "github.com/tj/go-update" | ||
// "github.com/tj/go-update/progress" | ||
// githubUpdateStore "github.com/tj/go-update/stores/github" | ||
// "runtime" | ||
// "strings" | ||
//) | ||
// | ||
//const ( | ||
// Owner = "SummerSec" | ||
// Repo = "SpringExploit" | ||
//) | ||
// | ||
//func selfUpdate() { | ||
// var command string | ||
// | ||
// //// get current executable path | ||
// //executable, err := os.Executable() | ||
// //if err != nil { | ||
// // log.Fatal(err) | ||
// //} | ||
// | ||
// switch runtime.GOOS { | ||
// case "windows": | ||
// command = Repo + ".exe" | ||
// default: | ||
// command = Repo | ||
// } | ||
// log.Debugf("command: %s", command) | ||
// m := &update.Manager{ | ||
// Command: command, | ||
// Store: &githubUpdateStore.Store{ | ||
// Owner: Owner, | ||
// Repo: Repo, | ||
// Version: version, | ||
// }, | ||
// } | ||
// | ||
// releases, err := m.LatestReleases() | ||
// if err != nil { | ||
// log.Error("Failed to get releases", err) | ||
// return | ||
// } | ||
// if len(releases) == 0 { | ||
// log.Info("No updates available") | ||
// return | ||
// } | ||
// latest := releases[0] | ||
// var currentOS string | ||
// switch runtime.GOOS { | ||
// case "darwin": | ||
// currentOS = "macOS" | ||
// default: | ||
// currentOS = runtime.GOOS | ||
// } | ||
// final := latest.FindZip(currentOS, runtime.GOARCH) | ||
// if final == nil { | ||
// log.Error("No update available for", currentOS, "and", runtime.GOARCH) | ||
// } | ||
// tarball, err := final.DownloadProxy(progress.Reader) | ||
// if err != nil { | ||
// log.Error("could not install latest release ", err) | ||
// return | ||
// } | ||
// if err := m.Install(tarball); err != nil { | ||
// log.Error("could not install latest release", err) | ||
// return | ||
// } | ||
// | ||
// log.Infof("Successfully Updated to %s Version %s", Repo, latest.Version) | ||
// | ||
//} | ||
// | ||
//// 获取最新版本 | ||
//func getLatestVersion() { | ||
// log.Info("Crrunent Version : ", version) | ||
// latestverion := getLatestVersionFromGithub() | ||
// log.Infof("Latest Version: %s", latestverion) | ||
// if strings.Compare(latestverion, version) > 0 { | ||
// log.Info("Use Command SpringExploit -update to update to latest version ") | ||
// } | ||
// | ||
//} | ||
// | ||
//// 从github获取最新版本 | ||
//func getLatestVersionFromGithub() string { | ||
// m := &update.Manager{ | ||
// Store: &githubUpdateStore.Store{ | ||
// Owner: Owner, | ||
// Repo: Repo, | ||
// Version: version, | ||
// }, | ||
// } | ||
// releases, err := m.LatestReleases() | ||
// if err != nil { | ||
// log.Error("Failed to get releases ", err) | ||
// return "" | ||
// } | ||
// defer func() { | ||
// if errs := recover(); errs != nil { | ||
// log.Debug("No updates available ", errs) | ||
// } | ||
// }() | ||
// | ||
// if releases == nil { | ||
// log.Info("No updates available") | ||
// return version | ||
// } else { | ||
// return releases[0].Version | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package core | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"github.com/blang/semver" | ||
"github.com/rhysd/go-github-selfupdate/selfupdate" | ||
log "github.com/sirupsen/logrus" | ||
"os" | ||
) | ||
|
||
const info = "SummerSec/SpringExploit" | ||
|
||
func doSelfUpdate() { | ||
latest, found, err := selfupdate.DetectLatest(info) | ||
if err != nil { | ||
log.Infoln("Error occurred while detecting version:", err) | ||
return | ||
} | ||
|
||
v := semver.MustParse(version) | ||
if !found || latest.Version.LTE(v) { | ||
log.Infof("Current binary is the latest version %s", version) | ||
return | ||
} | ||
|
||
latest1, err := selfupdate.UpdateSelf(v, info) | ||
|
||
if latest1.Version.LTE(v) { | ||
log.Infof("Current binary is the latest version %s", version) | ||
|
||
} else { | ||
log.Infoln("Successfully updated to version", latest.Version) | ||
log.Infoln("Release note:\n", latest.ReleaseNotes) | ||
} | ||
} | ||
|
||
func confirmAndSelfUpdate() { | ||
latest, found, err := selfupdate.DetectLatest(info) | ||
if err != nil { | ||
log.Infoln("Error occurred while detecting version:", err) | ||
return | ||
} | ||
|
||
v := semver.MustParse(version) | ||
if !found || latest.Version.LTE(v) { | ||
log.Infof("Current version is the latest version %s", version) | ||
return | ||
} | ||
|
||
fmt.Print("Do you want to update to", latest.Version, "? (y/n): ") | ||
input, err := bufio.NewReader(os.Stdin).ReadString('\n') | ||
if err != nil || (input != "y\n" && input != "n\n") { | ||
log.Println("Invalid input") | ||
return | ||
} | ||
if input == "n\n" { | ||
return | ||
} | ||
|
||
exe, err := os.Executable() | ||
if err != nil { | ||
log.Println("Could not locate executable path") | ||
return | ||
} | ||
if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil { | ||
log.Println("Error occurred while updating binary:", err) | ||
return | ||
} | ||
log.Println("Successfully updated to version", latest.Version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.