# HG changeset patch # User Floris Bruynooghe # Date 1562534669 -7200 # Sun Jul 07 23:24:29 2019 +0200 # Node ID b715e2d6c871e1b4987b93d7dbef2653dfc26f9b # Parent 154781f18bae5890c0a3cea3026a731851331edf 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. diff --git a/Cargo.toml b/Cargo.toml --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,38 @@ 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" diff --git a/README.rst b/README.rst --- a/README.rst +++ b/README.rst @@ -60,6 +60,30 @@ 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 @@ 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. diff --git a/build.rs b/build.rs --- a/build.rs +++ b/build.rs @@ -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); } diff --git a/debian/postinst b/debian/postinst new file mode 100644 --- /dev/null +++ b/debian/postinst @@ -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 diff --git a/debian/prerm b/debian/prerm new file mode 100644 --- /dev/null +++ b/debian/prerm @@ -0,0 +1,11 @@ +#!/bin/sh + +case $1 in + remove) + if systemctl --quiet is-active brightd.service; then + systemctl stop brightd.service + fi + ;; + *) + ;; +esac diff --git a/session/brightd.service b/session/brightd.service --- a/session/brightd.service +++ b/session/brightd.service @@ -3,7 +3,7 @@ [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 diff --git a/system/brightd.service b/system/brightd.service --- a/system/brightd.service +++ b/system/brightd.service @@ -3,7 +3,7 @@ [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 @@ 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