|
@@ -10,7 +10,7 @@ import (
|
|
|
)
|
|
|
|
|
|
//Download updates from given URL, return real time progress of stage (int), progress (int) and status text (string)
|
|
|
-func DownloadUpdatesFromURL(binaryURL string, webpackURL string, progressUpdateFunction func(int, float64, string)) error {
|
|
|
+func DownloadUpdatesFromURL(binaryURL string, webpackURL string, checksumURL string, progressUpdateFunction func(int, float64, string)) error {
|
|
|
//Create the update download folder
|
|
|
os.RemoveAll("./updates")
|
|
|
os.MkdirAll("./updates", 0755)
|
|
@@ -24,6 +24,7 @@ func DownloadUpdatesFromURL(binaryURL string, webpackURL string, progressUpdateF
|
|
|
//Generate the download position
|
|
|
binaryDownloadTarget := "./updates/" + filepath.Base(binaryURL)
|
|
|
webpackDownloadTarget := "./updates/" + filepath.Base(webpackURL)
|
|
|
+ checksumDownloadTarget := "./updates/" + filepath.Base(checksumURL)
|
|
|
|
|
|
//Check if the webpack is .tar.gz
|
|
|
if filepath.Ext(webpackDownloadTarget) != ".gz" {
|
|
@@ -86,7 +87,46 @@ func DownloadUpdatesFromURL(binaryURL string, webpackURL string, progressUpdateF
|
|
|
}
|
|
|
webpackDownloadComplete = 1
|
|
|
|
|
|
- //Download completed. Try unzip webpack
|
|
|
+ //Download completed.
|
|
|
+ //check checksum if exists
|
|
|
+ //just a small file, dont need progress bar
|
|
|
+ if checksumURL != "" {
|
|
|
+ err = downloadFile(checksumURL, checksumDownloadTarget)
|
|
|
+ if err != nil {
|
|
|
+ errorMessage = err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ checksumFileContent, err := os.ReadFile(checksumDownloadTarget)
|
|
|
+ if err != nil {
|
|
|
+ errorMessage = err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ binaryHash, err := getSHA1Hash(binaryDownloadTarget)
|
|
|
+ if err != nil {
|
|
|
+ errorMessage = err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ webpackHash, err := getSHA1Hash(webpackDownloadTarget)
|
|
|
+ if err != nil {
|
|
|
+ errorMessage = err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ binaryBool := readCheckSumFile(string(checksumFileContent), filepath.Base(binaryURL), binaryHash)
|
|
|
+ webPackBool := readCheckSumFile(string(checksumFileContent), filepath.Base(webpackURL), webpackHash)
|
|
|
+ os.Remove(checksumDownloadTarget)
|
|
|
+ if !binaryBool {
|
|
|
+ progressUpdateFunction(1, 100, "Binary checksum mismatch")
|
|
|
+ errorMessage = err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if !webPackBool {
|
|
|
+ progressUpdateFunction(1, 100, "Web pack checksum mismatch")
|
|
|
+ errorMessage = err.Error()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Try unzip webpack
|
|
|
gzipstrean, err := os.Open(webpackDownloadTarget)
|
|
|
if err != nil {
|
|
|
return err
|