From 1d0b451857a58613deb0366cc3436a0bad25a938 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 2 Mar 2017 13:48:19 +0300 Subject: Introduce new binary package 'runit-helper', allowing packages to access fixes and improvements in 'dh-runit' without rebuild. --- debian/changelog | 2 ++ debian/control | 12 +++++++++ debian/runit-helper.install | 1 + dh_runit | 1 + postrm-runit | 42 ++--------------------------- runit-helper | 66 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 40 deletions(-) create mode 100644 debian/runit-helper.install create mode 100755 runit-helper diff --git a/debian/changelog b/debian/changelog index 2e667cb..cf18f07 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,8 @@ dh-runit (2.7) UNRELEASED; urgency=medium backward-incompatible change, hence the version major bump, but I am unaware of any actual users of this option. * Ensure that after package removal logs belong to root. + * Introduce new binary package 'runit-helper', allowing packages to + access fixes and improvements in 'dh-runit' without rebuild. -- Dmitry Bogatov Wed, 01 Mar 2017 18:38:17 +0300 diff --git a/debian/control b/debian/control index 74b3dba..03f464d 100644 --- a/debian/control +++ b/debian/control @@ -20,3 +20,15 @@ Description: debhelper add-on to handle runit runscripts The dh_runit command installs runscripts and adds the appropriate code to the postinst, prerm and postrm maint scripts to properly enable/disable runscripts. + +Package: runit-helper +Architecture: all +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: dh-sysuser implementation detail + runit-helper provides code, which actually perform actions on system + users on behalf of dh-runit package. This separation allows packages + take advantage of improvement or fixes in 'dh-runit' without + rebuilding. + . + This package is implementation detail of 'dh-runit'. It should never + be installed manually. No assumption about its content can be made. diff --git a/debian/runit-helper.install b/debian/runit-helper.install new file mode 100644 index 0000000..3d377d2 --- /dev/null +++ b/debian/runit-helper.install @@ -0,0 +1 @@ +runit-helper /lib/runit-helper/ diff --git a/dh_runit b/dh_runit index 3be25bb..36031ed 100755 --- a/dh_runit +++ b/dh_runit @@ -100,6 +100,7 @@ HERE } } addsubstvar($pkg, 'misc:Depends', 'runit', '>= 2.1.2-7'); + addsubstvar($pkg, 'misc:Depends', 'runit-helper'); } # PROMISE: DH NOOP WITHOUT runit diff --git a/postrm-runit b/postrm-runit index 5ce6acf..edd9ee7 100644 --- a/postrm-runit +++ b/postrm-runit @@ -1,44 +1,6 @@ # -*- shell-script -*- - -if [ "$1" = 'purge' ] ; then - # If runscript was never invoked, there will be no files - # in this directory, and `dpkg' will remove it. In this case, - # we have nothing to do. - for supervise in '/var/lib/runit/supervise/#NAME#' \ - '/var/lib/runit/log/supervise/#NAME#' ; do - if [ -d "$supervise" ] ; then - - # Actually only `down' may be absent, but it does not - # matter. - - for file in control lock ok pid stat status down ; do - rm -f "$supervise/$file" - done - - # It should be empty now. If it is not, it means that - # system administrator put something there. It is very - # stupid, but will of user is sacred, and directory is - # left as-is in such case. - # - # NOTE: Non-POSIX option is used. The day coreutils will - # no longer be essential, it will require a fix. - rmdir --ignore-fail-on-non-empty "$supervise" - fi - done -fi - -# Following code makes sure, that after removal of package, in default -# setup, the only files belonged to log user, belong to root. -# -# This way user can be safely removed, solving part of #848239 (need -# interoperation from dh-sysuser). -# -# Sure, system administrator can make stupid thing and chown some file -# to log user, but consequences do not seem to be so severe. After -# all, with great power comes great responsibility. -if [ -d '/var/log/runit/#NAME#' ] ; then - chown --recursive root:root '/var/log/runit/#NAME#' -fi +export NAME='#NAME#' +/lib/runit-helper/runit-helper postrm "$@" # Local Variables: # eval: (sh-set-shell "sh" t nil) diff --git a/runit-helper b/runit-helper new file mode 100755 index 0000000..e48020b --- /dev/null +++ b/runit-helper @@ -0,0 +1,66 @@ +#!/bin/sh +# Copyright (C) 2017 Dmitry Bogatov + +# Author: Dmitry Bogatov + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set -e + +postrm () { + + # Following code makes sure, that after removal of package, in default + # setup, the only files belonged to log user, belong to root. + # + # This way user can be safely removed, solving part of #848239 (need + # interoperation from dh-sysuser). + # + # Sure, system administrator can make stupid thing and chown some file + # to log user, but consequences do not seem to be so severe. After + # all, with great power comes great responsibility. + if [ -d "/var/log/runit/$NAME" ] ; then + chown --recursive root:root "/var/log/runit/$NAME" + fi + + if [ "$1" != 'purge' ] ; then + return + fi + + # If runscript was never invoked, there will be no files + # in this directory, and `dpkg' will remove it. In this case, + # we have nothing to do. + for supervise in "/var/lib/runit/supervise/$NAME" \ + "/var/lib/runit/log/supervise/$NAME" ; do + if [ -d "$supervise" ] ; then + + # Actually only `down' may be absent, but it does not + # matter. + + for file in control lock ok pid stat status down ; do + rm -f "$supervise/$file" + done + + # It should be empty now. If it is not, it means that + # system administrator put something there. It is very + # stupid, but will of user is sacred, and directory is + # left as-is in such case. + # + # NOTE: Non-POSIX option is used. The day coreutils will + # no longer be essential, it will require a fix. + rmdir --ignore-fail-on-non-empty "$supervise" + fi + done +} + +"$@" -- cgit v1.2.3