summaryrefslogtreecommitdiffstats
path: root/dh_installsysusers
blob: 9536b66ad9958dd41df383ba0c0def1b7e2dcc20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/perl -w

=head1 NAME

dh_installsysusers - install and integrates systemd sysusers files

=cut

use strict;
use warnings;
use Debian::Debhelper::Dh_Lib;

our $VERSION = DH_BUILTIN_VERSION;

=head1 SYNOPSIS

B<dh_installsysusers> [S<I<debhelper options>>]

=head1 DESCRIPTION

B<dh_installsysusers> is a debhelper program that is responsible for
installing package maintainer supplied systemd sysusers files.

It also finds the systemd sysusers files installed in a package and
generates relevant integration snippets for enabling the users on
installation.  These snippets are added to the package by
L<dh_installdeb(1)>.

=head1 FILES

=over 4

=item debian/I<package>.sysusers

If the file exist, it will be installed as
F<< /usr/lib/sysusers.d/I<package>.conf >>.

=back

=head1 OPTIONS

=over 4

=item B<--name=>I<name>

When this parameter is used, B<dh_installsysusers> looks for and
installs files named debian/I<package>.I<name>.sysusers instead
of the usual debian/I<package>.sysusers.

Furthermore, the file is installed as F<< /usr/lib/sysusers.d/I<name>.conf >>
rather than F<< /usr/lib/sysusers.d/I<package>.conf >>.

=back

=head1 NOTES

This command is not idempotent. L<dh_prep(1)> should be called between
invocations of this command (with the same arguments). Otherwise, it
may cause multiple instances of the same text to be added to
maintainer scripts.

=cut

init();


# PROMISE: DH NOOP WITHOUT pkgfile(sysusers) tmp(usr/lib/sysusers.d) cli-options()


foreach my $package (@{$dh{DOPACKAGES}}) {
	my $tmpdir = tmpdir($package);
	my $sysusers = pkgfile($package,"sysusers");
	my $sysusers_targetdir = "${tmpdir}/usr/lib/sysusers.d";
	my $target = $dh{NAME} // $package;
	my $typoed_name = pkgfile($package, "sysuser");

	if ($sysusers eq '' and $typoed_name ne '') {
		# Warn people in case they typo this as much as I did.
		my $correct_name = $typoed_name;
		$correct_name =~ s{^(?:.*[./])\Ksysuser}{sysusers};
		warning("Possible typo in ${typoed_name} (expected ${correct_name}): File has been ignored");
	}

	if ($sysusers ne '') {
		install_dir($sysusers_targetdir);
		install_file($sysusers, "${sysusers_targetdir}/${target}.conf");
	}

	if (! $dh{NOSCRIPTS} && ($sysusers ne '' || -d $sysusers_targetdir)) {
		my $has_sysuser = 0;
		opendir(my $dir_fd, $sysusers_targetdir) or error("opendir(${sysusers_targetdir}) failed: $!");
		while (defined(my $entry = readdir($dir_fd))) {
			next if $entry eq '.' or $entry eq '..' or $entry !~ m{[.]conf$};
			autoscript($package, 'postinst', 'postinst-sysusers', { 'CONFILE_BASENAME' => $entry });
			$has_sysuser = 1;
		}
		closedir($dir_fd);
		addsubstvar($package, "misc:Depends", "systemd | systemd-standalone-sysusers | systemd-sysusers")
			if $has_sysuser;
	}

}



=head1 SEE ALSO

L<debhelper(7)>

=cut