From b0cddccbd802077204f021a81b2546182a1f4d2f Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 13 Feb 2016 13:14:10 +0000
Subject: [PATCH] drop libleveldb dependency from Debian package metadata

---
 debian/changelog      |  6 ++++++
 debian/control        |  4 ++--
 debian/liber.default  |  8 ++++++--
 debian/liber.init     |  4 ++--
 debian/liber.postinst |  8 ++++----
 debian/liber.service  | 14 ++++++++++++++
 debian/rules          | 18 +++++++++++++++---
 7 files changed, 49 insertions(+), 13 deletions(-)
 create mode 100644 debian/liber.service

diff --git a/debian/changelog b/debian/changelog
index a3f9691..42a9bd0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+liber (0.2) unstable; urgency=medium
+
+  * Migrated to new on-disk database format.
+
+ -- ale <ale@incal.net>  Sat, 13 Feb 2016 13:00:07 +0000
+
 liber (0.1p6) unstable; urgency=medium
 
   * Fixed issues with user input.
diff --git a/debian/control b/debian/control
index 4a17cd1..311d06b 100644
--- a/debian/control
+++ b/debian/control
@@ -2,13 +2,13 @@ Source: liber
 Section: net
 Priority: extra
 Maintainer: ale <ale@incal.net>
-Build-Depends: debhelper (>= 8.0.0), libicu-dev, libleveldb-dev (>=1.15)
+Build-Depends: debhelper (>= 8.0.0), dh-systemd (>= 1.5)
 Standards-Version: 3.9.4
 Homepage: https://git.autistici.org/ale/liber
 
 Package: liber
 Architecture: any
-Depends: libleveldb1 (>=1.15), libicu48, ${shlibs:Depends}, ${misc:Depends}
+Depends: ${shlibs:Depends}, ${misc:Depends}
 Description: Ebook collection indexer.
  Index and search an ebook collection.
 
diff --git a/debian/liber.default b/debian/liber.default
index 2b126d4..be75f2f 100644
--- a/debian/liber.default
+++ b/debian/liber.default
@@ -3,7 +3,11 @@
 #ENABLE_SERVER=true
 
 # Set the address (host:port) to listen on.
-#ADDR=:4040
+ADDR="--http-server=127.0.0.1:4040"
 
 # Directory where books are stored.
-#BOOK_DIR=/var/lib/liber/books
+BOOK_DIR="--book-dir=/var/lib/liber/books"
+
+# Put any other options here.
+LIBER_OPTIONS=
+
diff --git a/debian/liber.init b/debian/liber.init
index 08ac676..398a429 100755
--- a/debian/liber.init
+++ b/debian/liber.init
@@ -56,13 +56,13 @@ case "$1" in
     stop)
         do_stop
         ;;
-    restart)
+    restart|force-reload)
         $0 stop
         sleep 1
         $0 start
         ;;
     *)
-        echo "Usage: $0 {start|stop|restart}" >&2
+        echo "Usage: $0 {start|stop|restart|force-reload}" >&2
         exit 3
         ;;
 esac
diff --git a/debian/liber.postinst b/debian/liber.postinst
index 5101812..2edbe03 100755
--- a/debian/liber.postinst
+++ b/debian/liber.postinst
@@ -18,14 +18,14 @@ esac
 
 #DEBHELPER#
 
-adduser --quiet --system --home /var/lib/liber --no-create-home --ingroup nogroup liber
+if ! getent passwd liber >/dev/null; then
+    useradd --system --home-dir /var/lib/liber -M liber
+fi
 
 for dir in /var/lib/liber /var/lib/liber/books; do
     test -d $dir || mkdir $dir
     chmod 700 $dir
-    chown liber:nogroup $dir
+    chown liber $dir
 done
 
-update-rc.d liber defaults >/dev/null
-
 exit 0
diff --git a/debian/liber.service b/debian/liber.service
new file mode 100644
index 0000000..a302008
--- /dev/null
+++ b/debian/liber.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Ebook collection indexer
+After=network.target
+
+[Service]
+User=liber
+EnvironmentFile=/etc/default/liber
+ExecStart=/usr/bin/liber $BOOK_DIR $ADDR $LIBER_OPTIONS
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
+
+
diff --git a/debian/rules b/debian/rules
index 268071d..12af07b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -7,17 +7,29 @@
 # This has to be exported to make some magic below work.
 export DH_OPTIONS
 
+export DH_GOPKG = git.autistici.org/ale/liber
+
 DEBDIR = $(CURDIR)/debian
 PKGDIR = $(DEBDIR)/liber
 
 %:
-	dh $@ 
+	dh $@ --with systemd
 
 override_dh_install:
 	# Build the sources using your locally-installed Go version.
-	# This is crazy, clearly, but it's a temporary workaround for wheezy.
+	# NB: This is not an acceptable way to build a proper Debian package.
 	install -m 755 -o root -g root -d $(PKGDIR)/usr/bin
 	install -m 755 -o root -g root -d $(PKGDIR)/usr/share/liber
-	go build -o $(PKGDIR)/usr/bin/liber cmd/liber/liber.go
+	-mkdir build
+	(export PATH=$$PATH:/usr/local/go/bin ; export GOPATH=$(CURDIR)/build ; mkdir -p build/src/$(shell dirname $(DH_GOPKG)) ; ln -s $(CURDIR) build/src/$(DH_GOPKG) ; cd build/src/$(DH_GOPKG) && go install -v ./...)
+	(for f in liber liberdbtool ; do \
+	 install -m 755 -o root -g root build/bin/$$f $(PKGDIR)/usr/bin/$$f ; done)
 	(umask 022; cp -R --preserve=timestamps htdocs $(PKGDIR)/usr/share/liber/htdocs)
 
+override_dh_clean:
+	-rm -fr build
+	dh_clean
+
+# Do not enable the liber HTTP server by default.
+override_dh_systemd_enable:
+
-- 
GitLab