Package using cargo-deb

Using cargo-deb now produces a reasonably decent package.  It installs
command line completions, the binaries, udev rules, D-Bus
configuration and the systemd system service, leaving the service started.
7 files changed, 108 insertions(+), 15 deletions(-)

M Cargo.toml
M README.rst
M build.rs
A => debian/postinst
A => debian/prerm
M session/brightd.service
M system/brightd.service
M Cargo.toml +32 -0
@@ 8,6 8,38 @@ authors = ["Floris Bruynooghe <flub@devo
 build = "build.rs"
 edition = "2018"
 
+[package.metadata.deb]
+license-file = ["LICENSE", "0"]
+extended-description = """\
+A D-Bus daemon and tool to control the screen backlight.  The daemon
+can also directly listen for ACPI events from acpid while the tool can
+also work without the daemon, though may need a little more setup for
+permissions.  The daemon will also detect changes made outside of it's
+control and publish the relevant D-Bus events, ensuring it integrates
+seamlessly with other tooling.
+
+By default a systemd system service is installed and enabled, running
+the daemon with acpi support.  It is also possible to run the daemon
+in a user-session and using the Session D-Bus.
+"""
+depends = "$auto, dbus, acpid, systemd, init-system-helpers"
+assets = [
+    ["target/release/brightctl", "usr/bin/", "755"],
+    ["target/release/brightd", "usr/bin/", "755"],
+    ["README.rst", "usr/share/doc/bright/", "644"],
+    ["system/be.devork.dbus.bright.conf", "etc/dbus-1/system.d/", "644"],
+    ["system/brightd.service", "usr/lib/systemd/system/", "644"],
+    ["be.devork.dbus.bright.service", "usr/share/dbus-1/system-services/", "644"],
+    ["50-bright.rules", "etc/udev/rules.d/", "644"],
+    ["target/release/completions/brightctl.bash", "usr/share/bash-completion/completions/brightctl", "644"],
+    ["target/release/completions/brightd.bash", "usr/share/bash-completion/completions/brightd", "644"],
+    ["target/release/completions/brightctl.fish", "usr/share/fish/completions/", "644"],
+    ["target/release/completions/brightd.fish", "usr/share/fish/completions/", "644"],
+    ["target/release/completions/_brightctl", "usr/share/zsh/vendor-completions/", "644"],
+    ["target/release/completions/_brightd", "usr/share/zsh/vendor-completions/", "644"],
+]
+maintainer-scripts = "debian"
+
 [dependencies]
 failure = "0.1.5"
 failure_derive = "0.1.5"

          
M README.rst +25 -1
@@ 60,6 60,30 @@ build --release`` in the project's direc
 Installing
 ==========
 
+Using cargo-deb
+---------------
+
+If you are using a Debian-based distribution the easiest is to use
+`cargo-deb` to create and install a Debian package:
+
+```
+$ cargo install cargo-deb
+$ cargo deb --install
+```
+
+This will install the binaries, D-Bus configuration, udev-rules and
+systemd service unit.  The systemd service will be started with ACPI
+support.  After installation your brightness buttons should "just
+work" and you should be able to use `brightctl` to control the
+brightness as well, thanks to the udev rules even when stopping the
+`brightd` daemon.
+
+Read on for more details about all the parts involved.
+
+
+Manual Installation
+-------------------
+
 To use the ``brightctl`` tool without daemon support simply install
 the tool in any bin directory of your choice which is on your path.
 To allow the tool to access the devices directly, in case you're not

          
@@ 100,7 124,7 @@ system to use the D-Bus service.
 To install the systemd service unit install the supplied
 ``system/brightd.service`` file into
 ``/etc/systemd/system/brightd.service``.  If you installed the binary
-somewhere other than ``/usr/local/bin/`` be sure to update the path.
+somewhere other than ``/usr/bin/`` be sure to update the path.
 Since we'll start the service using D-Bus bus-activation this is all
 which needs to be done for systemd.
 

          
M build.rs +21 -10
@@ 1,22 1,33 @@ 
 #[macro_use]
 extern crate clap;
 
+use std::env;
+use std::fs;
+use std::path::PathBuf;
+
 use clap::Shell;
 
 #[path = "src/cli.rs"]
 mod cli;
 
 fn main() {
-    let outdir = match std::env::var_os("OUT_DIR") {
-        None => return,
-        Some(outdir) => outdir,
-    };
+    let outdir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
+    let targetdir = outdir.join("../../..");
+    let completionsdir = targetdir.join("completions");
+    if !completionsdir.is_dir() {
+        fs::create_dir(&completionsdir).unwrap();
+    } else {
+        for entry in fs::read_dir(&completionsdir).unwrap() {
+            let fname = entry.unwrap().path();
+            fs::remove_file(&fname).unwrap();
+        }
+    }
     let mut brightctl = cli::brightctl_app();
-    brightctl.gen_completions("brightctl", Shell::Bash, &outdir);
-    brightctl.gen_completions("brightctl", Shell::Fish, &outdir);
-    brightctl.gen_completions("brightctl", Shell::Zsh, &outdir);
+    brightctl.gen_completions("brightctl", Shell::Bash, &completionsdir);
+    brightctl.gen_completions("brightctl", Shell::Fish, &completionsdir);
+    brightctl.gen_completions("brightctl", Shell::Zsh, &completionsdir);
     let mut brightd = cli::brightd_app();
-    brightd.gen_completions("brightd", Shell::Bash, &outdir);
-    brightd.gen_completions("brightd", Shell::Fish, &outdir);
-    brightd.gen_completions("brightd", Shell::Zsh, &outdir);
+    brightd.gen_completions("brightd", Shell::Bash, &completionsdir);
+    brightd.gen_completions("brightd", Shell::Fish, &completionsdir);
+    brightd.gen_completions("brightd", Shell::Zsh, &completionsdir);
 }

          
A => debian/postinst +15 -0
@@ 0,0 1,15 @@ 
+#!/bin/sh
+
+case $1 in
+    configure|abort-upgrade|abort-deconfigure|abort-remove)
+        if deb-systemd-helper --quiet was-enabled brightd.service; then
+            deb-systemd-helper enable brightd.service >/dev/null || true
+        else
+            deb-systemd-helper update-state 'nullmailer.service' >/dev/null || true
+        fi
+        systemctl daemon-reload
+        systemctl restart brightd
+        ;;
+    *)
+        ;;
+esac

          
A => debian/prerm +11 -0
@@ 0,0 1,11 @@ 
+#!/bin/sh
+
+case $1 in
+    remove)
+        if systemctl --quiet is-active brightd.service; then
+            systemctl stop brightd.service
+        fi
+        ;;
+    *)
+        ;;
+esac

          
M session/brightd.service +1 -1
@@ 3,7 3,7 @@ Description=Backlight brightness control
 
 [Service]
 Type=dbus
-ExecStart=/usr/local/bin/brightd --bus=session --loglevel=debug --systemd
+ExecStart=/usr/local/bin/brightd --bus=session --loglevel=debug --acpi --systemd
 BusName=be.devork.dbus.bright
 Restart=always
 WatchdogSec=4

          
M system/brightd.service +3 -3
@@ 3,7 3,7 @@ Description=Backlight brightness control
 
 [Service]
 Type=dbus
-ExecStart=/usr/local/bin/brightd --bus=system --loglevel=debug --systemd
+ExecStart=/usr/bin/brightd --bus=system --loglevel=info --acpi --systemd
 BusName=be.devork.dbus.bright
 Restart=always
 WatchdogSec=4

          
@@ 24,5 24,5 @@ LockPersonality=yes
 IPAddressDeny=any
 ReadWritePaths=/sys/class/backlight
 
-# [Install]
-# WantedBy=default.target
  No newline at end of file
+[Install]
+WantedBy=default.target
  No newline at end of file