#!/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 target is being run with suffient access to root(-like) features. The definition of sufficient access depends on whether the builder (the tool invoking the F target) supports the I (R³) field. If the builder supports R³, then it will set the environment variable I and B will validate that the builder followed the minimum requirements for the given value of I. If the builder does not support I, then it will not set the I environment variable. This will in turn make B (and the rest of debhelper) fall back to assuming that (fake)root is implied. The following is a summary of how B behaves based on the I environment variable (leading and trailing whitespace in the variable is ignored). =over 4 =item - If unset, or set to C, then B asserts that it is run as root or under L. =item - If set to C, then B returns successfully (without performing any additional checks). =item - If set to any other value than the above, then 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 Please note that B does I read the I field. Which implies that B may produce incorrect result if the builder lies in I. On the flip side, it also enables things like testing for what will happen when I is set to a given value. =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'); } # PROMISE: DH NOOP WITHOUT internal(rrr) # 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