From 8e65d3669159c92e42e462d1f9e46b9ad0913a55 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 22 Dec 2013 00:16:49 +0100 Subject: [PATCH] Build script --- .gitignore | 1 + build.sh | 16 ++++++++++++++++ main.go | 12 ++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100755 build.sh diff --git a/.gitignore b/.gitignore index e6f784269..c91511084 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ syncthing +*.tar.gz diff --git a/build.sh b/build.sh new file mode 100755 index 000000000..a677758d4 --- /dev/null +++ b/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +version=$(git describe --always) + +for goos in darwin linux freebsd ; do + for goarch in amd64 386 ; do + export GOOS="$goos" + export GOARCH="$goarch" + go build -ldflags "-X main.Version $version" \ + && mkdir -p "syncthing-$goos-$goarch" \ + && mv syncthing "syncthing-$goos-$goarch" \ + && cp syncthing.ini "syncthing-$goos-$goarch" \ + && tar zcf "syncthing-$goos-$goarch.tar.gz" "syncthing-$goos-$goarch" \ + && rm -r "syncthing-$goos-$goarch" + done +done diff --git a/main.go b/main.go index cc63e6c0f..f6b143e0d 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ type DebugOptions struct { } var opts Options +var Version string const ( confDirName = ".syncthing" @@ -67,9 +68,11 @@ func main() { opts.ConfDir = strings.Replace(opts.ConfDir, "~", getHomeDir(), 1) } + infoln("Version", Version) + // Ensure that our home directory exists and that we have a certificate and key. - ensureDir(ConfDir) + ensureDir(ConfDir, 0700) cert, err := loadCert(ConfDir) if err != nil { newCertificate(ConfDir) @@ -120,6 +123,7 @@ func main() { nodeAddrs[nodeID] = addrs } + ensureDir(dir, -1) m := NewModel(dir) // Walk the repository and update the local model before establishing any @@ -304,13 +308,13 @@ func loadIndex(m *Model) { m.SeedIndex(idx) } -func ensureDir(dir string) { +func ensureDir(dir string, mode int) { fi, err := os.Stat(dir) if os.IsNotExist(err) { err := os.MkdirAll(dir, 0700) fatalErr(err) - } else if fi.Mode()&0077 != 0 { - err := os.Chmod(dir, 0700) + } else if mode >= 0 && err == nil && int(fi.Mode()&0777) != mode { + err := os.Chmod(dir, os.FileMode(mode)) fatalErr(err) } }