From 042b703fe487f5ade99ed42f82b3653e400217e5 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 19 Jan 2016 09:49:41 -0800 Subject: [PATCH 1/2] Templatize Debian files --- build.go | 47 ++++++++++++++++++++++------------------------- debian/changelog | 5 +++++ debian/compat | 1 + debian/control | 8 ++++++++ 4 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control diff --git a/build.go b/build.go index a7d64458..b2166b3a 100644 --- a/build.go +++ b/build.go @@ -26,6 +26,7 @@ import ( "runtime" "strconv" "strings" + "text/template" "time" ) @@ -331,33 +332,29 @@ func buildDeb() { } } - control := `Package: syncthing -Architecture: {{arch}} -Depends: libc6 -Version: {{version}} -Maintainer: Syncthing Release Management -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, "{{arch}}", debarch, -1) - control = strings.Replace(control, "{{version}}", version[1:], -1) - changelog = strings.Replace(changelog, "{{arch}}", debarch, -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) + data := map[string]string{ + "arch": debarch, + "version": version[1:], + "date": time.Now().Format(time.RFC1123), + } + for _, file := range listFiles("debian") { + tpl, err := template.New(filepath.Base(file)).ParseFiles(file) + if err != nil { + log.Fatal(err) + } + out, err := os.Create(filepath.Join("deb/DEBIAN", filepath.Base(file))) + if err != nil { + log.Fatal(err) + } + if err := tpl.Execute(out, data); err != nil { + log.Fatal(err) + } + if err := out.Close(); err != nil { + log.Fatal(err) + } + } } func copyFile(src, dst string, perm os.FileMode) error { diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 00000000..49b74501 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +syncthing ({{.version}}); urgency=medium + + * Packaging of {{.version}}. + + -- Syncthing Release Management {{.date}} diff --git a/debian/compat b/debian/compat new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 00000000..bdd8bc6e --- /dev/null +++ b/debian/control @@ -0,0 +1,8 @@ +Package: syncthing +Architecture: {{.arch}} +Depends: libc6, procps +Version: {{.version}} +Maintainer: Syncthing Release Management +Description: Open Source Continuous File Synchronization + Syncthing does bidirectional synchronization of files between two or + more computers. From 99372c69e552170c74e2b4460c441c1ed9341d3d Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 19 Jan 2016 09:54:47 -0800 Subject: [PATCH 2/2] Add postinst script to restart after upgrade --- build.go | 5 ++++- debian/postinst | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100755 debian/postinst diff --git a/build.go b/build.go index b2166b3a..265172f1 100644 --- a/build.go +++ b/build.go @@ -344,7 +344,8 @@ func buildDeb() { if err != nil { log.Fatal(err) } - out, err := os.Create(filepath.Join("deb/DEBIAN", filepath.Base(file))) + outFile := filepath.Join("deb/DEBIAN", filepath.Base(file)) + out, err := os.Create(outFile) if err != nil { log.Fatal(err) } @@ -354,6 +355,8 @@ func buildDeb() { if err := out.Close(); err != nil { log.Fatal(err) } + info, _ := os.Lstat(file) + os.Chmod(outFile, info.Mode()) } } diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 00000000..0289794c --- /dev/null +++ b/debian/postinst @@ -0,0 +1,6 @@ +#!/bin/bash +set -euo pipefail + +if [[ ${1:-} == configure ]]; then + pkill -x -HUP syncthing || true +fi