#!/usr/bin/perl =encoding UTF-8 =head1 NAME dh_testroot - ensure that a package is built with necessary level of root permissions =head1 SYNOPSIS B [S>] =head1 DESCRIPTION B is used to determine if the package has access to at least the level of root access that it declared it needed via the Rules-Requires-Root (R³) field. The following is how B behaves based on the effective value of the R³ field: =over 4 =item "binary-targets" B asserts that it is run as root or under L. =item "no" B returns successfully. =item Any other value than the above B asserts that it is either run as root (or under L) or the builder has provided the B environment variable (e.g. via dpkg-buildpackage -r). =back For backwards compatibility, B will consider the absence of the R³ field as if the R³ field was set to "binary-targets". =cut use strict; use warnings; use Debian::Debhelper::Dh_Lib; our $VERSION = DH_BUILTIN_VERSION; inhibit_log(); my $requirements = Debian::Debhelper::Dh_Lib::root_requirements(); if (! -f 'debian/control') { warning('dh_testroot must be called from the source root'); } # By declaration; nothing requires root and this command must be a no-op in that case. exit 0 if $requirements eq 'none'; # The builder /can/ choose to ignore the requirements and just call us as root. # If so, we do not bother checking the requirements any further. exit 0 if $< == 0; if ($requirements eq 'legacy-root') { error("You must run this as root (or use fakeroot)."); } else { my $env = $ENV{DEB_GAIN_ROOT_CMD}; error("Package needs targeted root but builder has not provided a gain-root command via \${DEB_GAIN_ROOT_CMD}") if not $env; } =head1 SEE ALSO L This program is a part of debhelper. =head1 AUTHOR Joey Hess =cut