From e02665c9a37cf6177d6bf81cbe6223fce0d92bd5 Mon Sep 17 00:00:00 2001 From: Matt Schreiber Date: Wed, 20 Feb 2019 15:18:43 -0500 Subject: [PATCH 1/2] p11-kit.install: add sd_booted and sd_running functions that test whether systemd is booted and in a running state. Short-circuit the hook functions that use systemctl unless sd_running returns success. --- trunk/p11-kit.install | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/trunk/p11-kit.install b/trunk/p11-kit.install index d85de7cf7..a72228e56 100644 --- a/trunk/p11-kit.install +++ b/trunk/p11-kit.install @@ -1,14 +1,34 @@ +sd_booted() { + [[ -d run/systemd/system ]] && ! [[ -L run/systemd/system ]] +} + +sd_running() { + sd_booted || return + + sd_status='' + if ! sd_status="$(systemd is-system-running)"; then + case "$sd_status" in + offline|unknown) return 1 ;; + *) return 0 ;; + esac + fi +} + post_install() { # Enable socket by default - systemctl --global enable p11-kit-server.socket + if sd_running; then + systemctl --global enable p11-kit-server.socket + fi } post_upgrade() { - if (( $(vercmp $2 0.23.13-1) < 0)); then + if (( $(vercmp $2 0.23.13-1) < 0)) && sd_running; then systemctl --global enable p11-kit-server.socket fi } pre_remove() { - systemctl --global disable p11-kit-server.socket + if sd_running; then + systemctl --global disable p11-kit-server.socket + fi } -- 2.20.1