mirror of
https://github.com/taigrr/go-selfupdate
synced 2025-01-18 04:33:12 -08:00
Added ability to specify a directory of binaries for cross compiling
This commit is contained in:
parent
0bcff3c955
commit
80588a0d78
48
main.go
48
main.go
@ -15,7 +15,7 @@ import (
|
|||||||
//"encoding/base64"
|
//"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
var plat string
|
var plat, appPath, version, genDir string
|
||||||
|
|
||||||
type current struct {
|
type current struct {
|
||||||
Version string
|
Version string
|
||||||
@ -58,21 +58,14 @@ func newGzReader(r io.ReadCloser) io.ReadCloser {
|
|||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func createUpdate(path string, platform string) {
|
||||||
plat = os.Getenv("GOOS") + "-" + os.Getenv("GOARCH")
|
c := current{Version: version, Sha256: generateSha256(path)}
|
||||||
|
|
||||||
appPath := os.Args[1]
|
|
||||||
version := os.Args[2]
|
|
||||||
genDir := "public"
|
|
||||||
os.MkdirAll(genDir, 0755)
|
|
||||||
|
|
||||||
c := current{Version: version, Sha256: generateSha256(appPath)}
|
|
||||||
|
|
||||||
b, err := json.MarshalIndent(c, "", " ")
|
b, err := json.MarshalIndent(c, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error:", err)
|
fmt.Println("error:", err)
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(filepath.Join(genDir, plat+".json"), b, 0755)
|
err = ioutil.WriteFile(filepath.Join(genDir, platform+".json"), b, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -81,13 +74,13 @@ func main() {
|
|||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
w := gzip.NewWriter(&buf)
|
w := gzip.NewWriter(&buf)
|
||||||
f, err := ioutil.ReadFile(appPath)
|
f, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
w.Write(f)
|
w.Write(f)
|
||||||
w.Close() // You must close this first to flush the bytes to the buffer.
|
w.Close() // You must close this first to flush the bytes to the buffer.
|
||||||
err = ioutil.WriteFile(filepath.Join(genDir, version, plat+".gz"), buf.Bytes(), 0755)
|
err = ioutil.WriteFile(filepath.Join(genDir, version, platform+".gz"), buf.Bytes(), 0755)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(genDir)
|
files, err := ioutil.ReadDir(genDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -104,14 +97,14 @@ func main() {
|
|||||||
|
|
||||||
os.Mkdir(filepath.Join(genDir, file.Name(), version), 0755)
|
os.Mkdir(filepath.Join(genDir, file.Name(), version), 0755)
|
||||||
|
|
||||||
fName := filepath.Join(genDir, file.Name(), plat+".gz")
|
fName := filepath.Join(genDir, file.Name(), platform+".gz")
|
||||||
old, err := os.Open(fName)
|
old, err := os.Open(fName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't have an old release for this os/arch, continue on
|
// Don't have an old release for this os/arch, continue on
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fName = filepath.Join(genDir, version, plat+".gz")
|
fName = filepath.Join(genDir, version, platform+".gz")
|
||||||
newF, err := os.Open(fName)
|
newF, err := os.Open(fName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Can't open %s: error: %s\n", fName, err)
|
fmt.Fprintf(os.Stderr, "Can't open %s: error: %s\n", fName, err)
|
||||||
@ -126,7 +119,26 @@ func main() {
|
|||||||
if err := binarydist.Diff(ar, br, patch); err != nil {
|
if err := binarydist.Diff(ar, br, patch); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ioutil.WriteFile(filepath.Join(genDir, file.Name(), version, plat), patch.Bytes(), 0755)
|
ioutil.WriteFile(filepath.Join(genDir, file.Name(), version, platform), patch.Bytes(), 0755)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
plat = os.Getenv("GOOS") + "-" + os.Getenv("GOARCH")
|
||||||
|
|
||||||
|
appPath = os.Args[1]
|
||||||
|
version = os.Args[2]
|
||||||
|
genDir = "public"
|
||||||
|
os.MkdirAll(genDir, 0755)
|
||||||
|
|
||||||
|
// If dir is given create update for each file
|
||||||
|
files, err := ioutil.ReadDir(appPath)
|
||||||
|
if err == nil {
|
||||||
|
for _, file := range files {
|
||||||
|
createUpdate(filepath.Join(appPath, file.Name()), file.Name())
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createUpdate(appPath, plat)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user