1
0
mirror of https://github.com/taigrr/go-selfupdate synced 2025-01-18 04:33:12 -08:00

go-selfupdate binary uses os env to detect arch/platform so you can crosscompile

This commit is contained in:
Mark Sanborn 2013-11-15 12:34:34 -08:00
parent f1263af1c0
commit 74aa055b82

30
main.go
View File

@ -1,23 +1,21 @@
package main
import (
"fmt"
"os"
"encoding/json"
"io/ioutil"
"io"
"path/filepath"
"compress/gzip"
"bytes"
"compress/gzip"
"crypto/sha256"
"encoding/json"
"fmt"
"github.com/kr/binarydist"
"runtime"
"io"
"io/ioutil"
"os"
"path/filepath"
//"runtime"
//"encoding/base64"
)
const (
plat = runtime.GOOS + "-" + runtime.GOARCH
)
var plat string
type current struct {
Version string
@ -61,6 +59,8 @@ func newGzReader(r io.ReadCloser) io.ReadCloser {
}
func main() {
plat = os.Getenv("GOOS") + "-" + os.Getenv("GOARCH")
appPath := os.Args[1]
version := os.Args[2]
genDir := "public"
@ -72,7 +72,7 @@ func main() {
if err != nil {
fmt.Println("error:", err)
}
err = ioutil.WriteFile(filepath.Join(genDir, plat + ".json"), b, 0755)
err = ioutil.WriteFile(filepath.Join(genDir, plat+".json"), b, 0755)
if err != nil {
panic(err)
}
@ -87,7 +87,7 @@ func main() {
}
w.Write(f)
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, plat+".gz"), buf.Bytes(), 0755)
files, err := ioutil.ReadDir(genDir)
if err != nil {
@ -104,14 +104,14 @@ func main() {
os.Mkdir(filepath.Join(genDir, file.Name(), version), 0755)
fName := filepath.Join(genDir, file.Name(), plat + ".gz")
fName := filepath.Join(genDir, file.Name(), plat+".gz")
old, err := os.Open(fName)
if err != nil {
fmt.Fprintf(os.Stderr, "Can't open %s: error: %s\n", fName, err)
os.Exit(1)
}
fName = filepath.Join(genDir, version, plat + ".gz")
fName = filepath.Join(genDir, version, plat+".gz")
newF, err := os.Open(fName)
if err != nil {
fmt.Fprintf(os.Stderr, "Can't open %s: error: %s\n", fName, err)