/usr/share/perl5/Sbuild/ChrootSetup.pm is in libsbuild-perl 0.65.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | #
# ChrootSetup.pm: chroot maintenance operations
# Copyright © 2005-2009 Roger Leigh <rleigh@debian.org
#
# 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 2 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
# <http://www.gnu.org/licenses/>.
#
#######################################################################
package Sbuild::ChrootSetup;
use strict;
use warnings;
use File::Temp qw(tempfile);
use Sbuild qw($devnull);
BEGIN {
use Exporter ();
our (@ISA, @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(basesetup shell hold_packages unhold_packages
list_packages set_package_status generate_keys);
}
sub basesetup ($$);
sub shell ($$);
sub hold_packages ($$@);
sub unhold_packages ($$@);
sub list_packages ($$@);
sub set_package_status ($$$@);
sub generate_keys ($$);
sub basesetup ($$) {
my $session = shift;
my $conf = shift;
# Add sbuild group
$session->run_command(
{ COMMAND => ['getent', 'group', 'sbuild'],
USER => 'root',
STREAMIN => $devnull,
STREAMOUT => $devnull,
DIR => '/' });
if ($?) {
# This will require root privileges. However, this should
# only get run at initial chroot setup time.
my $groupfile = $session->get('Location') . "/etc/group";
system '/bin/sh', '-c', "getent group sbuild >> $groupfile";
if ($?) {
print STDERR "E: Failed to create group sbuild\n";
return $?
}
}
$session->run_command(
{ COMMAND => ['/bin/sh', '-c',
'set -e; if [ ! -d /build ] ; then mkdir -m 0775 /build; fi'],
USER => 'root',
DIR => '/' });
if ($?) {
print STDERR "E: Failed to create build directory /build\n";
return $?
}
$session->run_command(
{ COMMAND => ['chown', 'sbuild:sbuild', '/build'],
USER => 'root',
DIR => '/' });
if ($?) {
print STDERR "E: Failed to set sbuild:sbuild ownership on /build\n";
return $?
}
$session->run_command(
{ COMMAND => ['chmod', '02770', '/build'],
USER => 'root',
DIR => '/' });
if ($?) {
print STDERR "E: Failed to set 0750 permissions on /build\n";
return $?
}
$session->run_command(
{ COMMAND => ['/bin/sh', '-c',
'set -e; if [ ! -d /var/lib/sbuild ] ; then mkdir -m 2770 /var/lib/sbuild; fi'],
USER => 'root',
DIR => '/' });
if ($?) {
print STDERR "E: Failed to create build directory /var/lib/sbuild\n";
return $?
}
$session->run_command(
{ COMMAND => ['/bin/sh', '-c',
'set -e; if [ ! -d /var/lib/sbuild/srcdep-lock ] ; then mkdir -m 2770 /var/lib/sbuild/srcdep-lock; fi'],
USER => 'root',
DIR => '/' });
if ($?) {
print STDERR "E: Failed to create sbuild directory /var/lib/sbuild/srcdep-lock\n";
return $?
}
$session->run_command(
{ COMMAND => ['chown', '-R', 'sbuild:sbuild', '/var/lib/sbuild'],
USER => 'root',
DIR => '/' });
if ($?) {
print STDERR "E: Failed to set sbuild:sbuild ownership on /var/lib/sbuild/\n";
return $?
}
$session->run_command(
{ COMMAND => ['chmod', '02770', '/var/lib/sbuild'],
USER => 'root',
DIR => '/' });
if ($?) {
print STDERR "E: Failed to set 02770 permissions on /var/lib/sbuild/\n";
return $?
}
# Set up debconf selections.
my $pipe = $session->pipe_command(
{ COMMAND => ['/usr/bin/debconf-set-selections'],
PIPE => 'out',
USER => 'root',
PRIORITY => 0,
DIR => '/' });
if (!$pipe) {
warn "Cannot open pipe: $!\n";
} else {
foreach my $selection ('man-db man-db/auto-update boolean false') {
print $pipe "$selection\n";
}
close($pipe);
if ($?) {
print STDERR "E: debconf-set-selections failed\n";
return $?
}
}
return 0;
}
sub shell ($$) {
my $session = shift;
my $conf = shift;
$session->run_command(
{ COMMAND => ['/bin/sh'],
PRIORITY => 1,
USER => $conf->get('BUILD_USER'),
STREAMIN => \*STDIN,
STREAMOUT => \*STDOUT,
STREAMERR => \*STDERR });
return $?
}
sub hold_packages ($$@) {
my $session = shift;
my $conf = shift;
my $status = set_package_status($session, $conf, "hold", @_);
return $status;
}
sub unhold_packages ($$@) {
my $session = shift;
my $conf = shift;
my $status = set_package_status($session, $conf, "install", @_);
return $status;
}
sub list_packages ($$@) {
my $session = shift;
my $conf = shift;
$session->run_command(
{COMMAND => ['dpkg', '--list', @_],
USER => 'root',
PRIORITY => 0});
return $?;
}
sub set_package_status ($$$@) {
my $session = shift;
my $conf = shift;
my $status = shift;
my $pipe = $session->pipe_command(
{COMMAND => ['dpkg', '--set-selections'],
PIPE => 'out',
USER => 'root',
PRIORITY => 0});
if (!$pipe) {
print STDERR "Can't run dpkg --set-selections in chroot\n";
return 1;
}
foreach (@_) {
print $pipe "$_ $status\n";
}
if (!close $pipe) {
print STDERR "Can't run dpkg --set-selections in chroot\n";
}
return $?;
}
sub generate_keys ($$) {
my $host = shift;
my $conf = shift;
my ($tmpfh, $tmpfilename) = tempfile();
print $tmpfh <<"EOF";
Key-Type: RSA
Key-Length: 1024
Name-Real: Sbuild Signer
Name-Comment: Sbuild Build Dependency Archive Key
Name-Email: buildd-tools-devel\@lists.alioth.debian.org
Expire-Date: 0
EOF
print $tmpfh '%secring ' . $conf->get('SBUILD_BUILD_DEPENDS_SECRET_KEY') . "\n";
print $tmpfh '%pubring ' . $conf->get('SBUILD_BUILD_DEPENDS_PUBLIC_KEY') . "\n";
print $tmpfh '%commit' . "\n";
close($tmpfh);
$host->run_command(
{ COMMAND => ['chown', ':sbuild', $tmpfilename],
USER => $conf->get('USERNAME'),
DIR => '/' });
if ($?) {
print STDERR "E: Failed to set :sbuild ownership on $tmpfilename\n";
return $?
}
$host->run_command(
{ COMMAND => ['chmod', '0660', $tmpfilename],
USER => $conf->get('USERNAME'),
DIR => '/' });
if ($?) {
print STDERR "E: Failed to set 0660 permissions on $tmpfilename\n";
return $?
}
my @command = ('gpg', '--no-options', '--no-default-keyring', '--batch', '--gen-key',
$tmpfilename);
$host->run_command(
{ COMMAND => \@command,
USER => $conf->get('BUILD_USER'),
PRIORITY => 0,
DIR => '/'});
if ($?) {
return $?;
}
# Secret keyring needs to be readable by 'sbuild' group.
@command = ('chmod', '640',
$conf->get('SBUILD_BUILD_DEPENDS_SECRET_KEY'));
$host->run_command(
{ COMMAND => \@command,
USER => $conf->get('BUILD_USER'),
PRIORITY => 0,
DIR => '/'});
return $?;
}
1;
|