MAJOR=4
MINOR=15
DEVNAME=tty15
 ?÷     #!/usr/bin/perl
# vim:ts=4:sw=4:expandtab
# Â© 2013-2014 Michael Stapelberg <stapelberg@debian.org>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#
#     * Neither the name of Michael Stapelberg nor the
#       names of contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
# .
# THIS SOFTWARE IS PROVIDED BY Michael Stapelberg ''AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Michael Stapelberg BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=head1 NAME

deb-systemd-helper - subset of systemctl for machines not running systemd

=head1 SYNOPSIS

B<deb-systemd-helper> enable | disable | purge | mask | unmask | is-enabled | was-enabled | debian-installed | update-state | reenable S<I<unit file> ...>

=head1 DESCRIPTION

B<deb-systemd-helper> is a Debian-specific helper script which re-implements
the enable, disable, is-enabled and reenable commands from systemctl.

The "enable" action will only be performed once (when first installing the
package). On the first "enable", a state file is created which will be deleted
upon "purge".

The "mask" action will keep state on whether the service was enabled/disabled
before and will properly return to that state on "unmask".

The "was-enabled" action is not present in systemctl, but is required in Debian
so that we can figure out whether a service was enabled before we installed an
updated service file. See http://bugs.debian.org/717603 for details.

The "debian-installed" action is also not present in systemctl. It returns 0 if
the state file of at least one of the given units is present.

The "update-state" action is also not present in systemctl. It updates
B<deb-systemd-helper>'s state file, removing obsolete entries (e.g. service
files that are no longer shipped by the package) and adding new entries (e.g.
new service files shipped by the package) without enabling them.

B<deb-systemd-helper> is intended to be used from maintscripts to enable
systemd unit files. It is specifically NOT intended to be used interactively by
users. Instead, users should run systemd and use systemctl, or not bother about
the systemd enabled state in case they are not running systemd.

=head1 ENVIRONMENT

=over 4

=item B<_DEB_SYSTEMD_HELPER_DEBUG>

If you export _DEB_SYSTEMD_HELPER_DEBUG=1, deb-systemd-helper will print debug
messages to stderr (thus visible in dpkg runs). Please include these when
filing a bugreport.

=item B<DPKG_ROOT>

Instead of working on the filesystem root /, perform all operations on a chroot
system in the directory given by DPKG_ROOT.

=back

=cut

use strict;
use warnings;
use File::Path qw(make_path); # in core since Perl 5.001
use File::Basename; # in core since Perl 5
use File::Temp qw(tempfile); # in core since Perl 5.6.1
use Getopt::Long; # in core since Perl 5
# Make Data::Dumper::Dumper available if present (not present on systems that
# only have perl-base, not perl).
eval { require Data::Dumper;