mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
Include MD5 sums in archives
This commit is contained in:
parent
23085eb5ae
commit
fbb1e168f7
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,3 +13,5 @@ perfstats*.csv
|
|||||||
coverage.xml
|
coverage.xml
|
||||||
!gui/scripts/syncthing
|
!gui/scripts/syncthing
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
syncthing.md5
|
||||||
|
syncthing.exe.md5
|
||||||
|
43
build.go
43
build.go
@ -22,6 +22,7 @@ import (
|
|||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"crypto/md5"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -190,7 +191,12 @@ func install(pkg string, tags []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func build(pkg string, tags []string) {
|
func build(pkg string, tags []string) {
|
||||||
rmr("syncthing", "syncthing.exe")
|
binary := "syncthing"
|
||||||
|
if goos == "windows" {
|
||||||
|
binary += ".exe"
|
||||||
|
}
|
||||||
|
|
||||||
|
rmr(binary, binary+".md5")
|
||||||
args := []string{"build", "-ldflags", ldflags()}
|
args := []string{"build", "-ldflags", ldflags()}
|
||||||
if len(tags) > 0 {
|
if len(tags) > 0 {
|
||||||
args = append(args, "-tags", strings.Join(tags, ","))
|
args = append(args, "-tags", strings.Join(tags, ","))
|
||||||
@ -201,6 +207,13 @@ func build(pkg string, tags []string) {
|
|||||||
args = append(args, pkg)
|
args = append(args, pkg)
|
||||||
setBuildEnv()
|
setBuildEnv()
|
||||||
runPrint("go", args...)
|
runPrint("go", args...)
|
||||||
|
|
||||||
|
// Create an md5 checksum of the binary, to be included in the archive for
|
||||||
|
// automatic upgrades.
|
||||||
|
err := md5File(binary)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildTar() {
|
func buildTar() {
|
||||||
@ -217,6 +230,7 @@ func buildTar() {
|
|||||||
{"LICENSE", name + "/LICENSE.txt"},
|
{"LICENSE", name + "/LICENSE.txt"},
|
||||||
{"AUTHORS", name + "/AUTHORS.txt"},
|
{"AUTHORS", name + "/AUTHORS.txt"},
|
||||||
{"syncthing", name + "/syncthing"},
|
{"syncthing", name + "/syncthing"},
|
||||||
|
{"syncthing.md5", name + "/syncthing.md5"},
|
||||||
}
|
}
|
||||||
for _, file := range listFiles("etc") {
|
for _, file := range listFiles("etc") {
|
||||||
files = append(files, archiveFile{file, name + "/" + file})
|
files = append(files, archiveFile{file, name + "/" + file})
|
||||||
@ -239,6 +253,7 @@ func buildZip() {
|
|||||||
{"LICENSE", name + "/LICENSE.txt"},
|
{"LICENSE", name + "/LICENSE.txt"},
|
||||||
{"AUTHORS", name + "/AUTHORS.txt"},
|
{"AUTHORS", name + "/AUTHORS.txt"},
|
||||||
{"syncthing.exe", name + "/syncthing.exe"},
|
{"syncthing.exe", name + "/syncthing.exe"},
|
||||||
|
{"syncthing.exe.md5", name + "/syncthing.exe.md5"},
|
||||||
}
|
}
|
||||||
zipFile(filename, files)
|
zipFile(filename, files)
|
||||||
log.Println(filename)
|
log.Println(filename)
|
||||||
@ -554,3 +569,29 @@ func zipFile(out string, files []archiveFile) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func md5File(file string) error {
|
||||||
|
fd, err := os.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fd.Close()
|
||||||
|
|
||||||
|
h := md5.New()
|
||||||
|
_, err = io.Copy(h, fd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := os.Create(file + ".md5")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = fmt.Fprintf(out, "%x\n", h.Sum(nil))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.Close()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user