Skip to content

Commit

Permalink
fix: Improve systemd service packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Mar 31, 2022
1 parent 1e1599a commit b776ca6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
30 changes: 14 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
prefix ?= /usr
sysconfdir ?= /etc
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
includedir = $(prefix)/include
datarootdir = $(prefix)/share
datadir = $(datarootdir)
datadir = $(prefix)/share

SRC = Cargo.toml Cargo.lock Makefile $(shell find src -type f -wholename '*src/*.rs')

.PHONY: all clean distclean install uninstall update

BIN=system76-power
RDD=com.system76.PowerDaemon
POLICY=com.system76.powerdaemon
ID=com.system76.PowerDaemon

DEBUG ?= 0
ifeq ($(DEBUG),0)
ARGS += "--release"
TARGET = release
endif

VENDORED ?= 0
ifeq ($(VENDORED),1)
VENDOR ?= 0
ifeq ($(VENDOR),1)
ARGS += "--frozen"
endif

Expand All @@ -35,17 +32,18 @@ distclean:
rm -rf .cargo vendor vendor.tar.xz

install: all
install -D -m 0644 "data/$(ID).conf" "$(DESTDIR)$(datadir)/dbus-1/system.d/$(ID).conf"
install -D -m 0644 "data/$(ID).policy" "$(DESTDIR)$(datadir)/polkit-1/actions/$(ID).policy"
install -D -m 0644 "data/$(ID).service" "$(DESTDIR)$(libdir)/systemd/system/$(ID).service"
install -D -m 0644 "data/$(ID).xml" "$(DESTDIR)$(datadir)/dbus-1/interfaces/$(ID).xml"
install -D -m 0755 "target/release/$(BIN)" "$(DESTDIR)$(bindir)/$(BIN)"
install -D -m 0644 "data/$(RDD).xml" "$(DESTDIR)$(sysconfdir)/dbus-1/interfaces/$(RDD).xml"
install -D -m 0644 "data/$(BIN).conf" "$(DESTDIR)$(sysconfdir)/dbus-1/system.d/$(BIN).conf"
install -D -m 0644 "debian/$(BIN).service" "$(DESTDIR)$(sysconfdir)/systemd/system/$(BIN).service"
install -D -m 0644 "data/$(POLICY).policy" $(DESTDIR)$(datadir)/polkit-1/actions/$(POLICY).policy

uninstall:
rm -f "$(DESTDIR)$(bindir)/$(BIN)"
rm -f "$(DESTDIR)$(sysconfdir)/dbus-1/system.d/$(BIN).conf"
rm -f "$(DESTDIR)$(sysconfdir)/systemd/system/$(BIN).service"
rm -f "$(DESTDIR)$(sysconfdir)/dbus-1/interfaces/$(RDD).xml"
rm -f "$(DESTDIR)$(bindir)/$(ID)"
rm -f "$(DESTDIR)$(datadir)/dbus-1/interfaces/$(ID).xml"
rm -f "$(DESTDIR)$(datadir)/dbus-1/system.d/$(ID).conf"
rm -f "$(DESTDIR)$(datadir)/polkit-1/actions/$(ID).policy"
rm -f "$(DESTDIR)$(libdir)/systemd/system/$(ID).service"

update:
cargo update
Expand All @@ -58,7 +56,7 @@ vendor:
rm -rf vendor

target/release/$(BIN): $(SRC)
ifeq ($(VENDORED),1)
ifeq ($(VENDOR),1)
tar pxf vendor.tar.xz
endif
cargo build $(ARGS)
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/usr/bin/make -f

export sysconfdir = "/usr/share/"
export VENDORED ?= 1
export VENDOR ?= 1
CLEAN ?= 1

%:
dh $@

override_dh_auto_build:
env CARGO_HOME="$$(pwd)/target/cargo" \
dh_auto_build
dh_auto_build

override_dh_auto_install:
dh_auto_install --destdir="debian/tmp"

override_dh_installsystemd:
dh_installsystemd --name=com.system76.PowerDaemon

override_dh_auto_clean:
ifeq ($(CLEAN),1)
make clean
Expand Down
11 changes: 11 additions & 0 deletions debian/system76-power.com.system76.PowerDaemon.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=System76 Power Daemon

[Service]
ExecStart=/usr/bin/system76-power daemon
Restart=on-failure
Type=dbus
BusName=com.system76.PowerDaemon

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions debian/system76-power.preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -e

# Fixes upgrade from previous packaging.
rm -rf /etc/systemd/system/system76-power.service

#DEBHELPER#

exit 0

0 comments on commit b776ca6

Please sign in to comment.