From 21fbbc50cdb256351419796606bb76b3c61f1fe1 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 11 May 2015 18:39:53 +0200 Subject: [PATCH] hax --- .gitignore | 1 + build.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9eb6435c6..ab1052d36 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ coverage.xml syncthing.md5 syncthing.exe.md5 RELEASE +deb diff --git a/build.go b/build.go index f5b275609..61aa78482 100644 --- a/build.go +++ b/build.go @@ -131,6 +131,9 @@ func main() { case "zip": buildZip() + case "deb": + buildDeb() + case "clean": clean() @@ -272,6 +275,74 @@ func buildZip() { log.Println(filename) } +func buildDeb() { + os.RemoveAll("deb") + + build("./cmd/syncthing", []string{"noupgrade"}) + + files := []archiveFile{ + {src: "README.md", dst: "deb/usr/share/doc/syncthing/README.txt", perm: 0644}, + {src: "LICENSE", dst: "deb/usr/share/doc/syncthing/LICENSE.txt", perm: 0644}, + {src: "AUTHORS", dst: "deb/usr/share/doc/syncthing/AUTHORS.txt", perm: 0644}, + {src: "syncthing", dst: "deb/usr/bin/syncthing", perm: 0755}, + } + + for _, file := range listFiles("extra") { + files = append(files, archiveFile{src: file, dst: "deb/usr/share/doc/syncthing/" + filepath.Base(file), perm: 0644}) + } + + for _, af := range files { + if err := copyFile(af.src, af.dst, af.perm); err != nil { + log.Fatal(err) + } + } + + control := `Package: syncthing +Architecture: {{goarch}} +Depends: libc6 +Version: {{version}} +Maintainer: Jakob Borg +Description: Open Source Continuous File Synchronization + Syncthing does bidirectional synchronization of files between two or + more computers. +` + changelog := `syncthing ({{version}}); urgency=medium + + * Packaging of {{version}}. + + -- Jakob Borg {{date}} +` + + control = strings.Replace(control, "{{goarch}}", goarch, -1) + control = strings.Replace(control, "{{version}}", version[1:], -1) + changelog = strings.Replace(changelog, "{{goarch}}", goarch, -1) + changelog = strings.Replace(changelog, "{{version}}", version[1:], -1) + changelog = strings.Replace(changelog, "{{date}}", time.Now().Format(time.RFC1123), -1) + + os.MkdirAll("deb/DEBIAN", 0755) + ioutil.WriteFile("deb/DEBIAN/control", []byte(control), 0644) + ioutil.WriteFile("deb/DEBIAN/compat", []byte("9\n"), 0644) + ioutil.WriteFile("deb/DEBIAN/changelog", []byte(changelog), 0644) + +} + +func copyFile(src, dst string, perm os.FileMode) error { + dstDir := filepath.Dir(dst) + os.MkdirAll(dstDir, 0755) // ignore error + srcFd, err := os.Open(src) + if err != nil { + return err + } + defer srcFd.Close() + dstFd, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, perm) + if err != nil { + return err + } + defer dstFd.Close() + _, err = io.Copy(dstFd, srcFd) + return err +} + func listFiles(dir string) []string { var res []string filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error { @@ -480,8 +551,9 @@ func runPipe(file, cmd string, args ...string) { } type archiveFile struct { - src string - dst string + src string + dst string + perm os.FileMode } func tarGz(out string, files []archiveFile) {