aboutsummaryrefslogtreecommitdiffstats
path: root/iurt2
diff options
context:
space:
mode:
authorFlorent Villard <warly@mandriva.com>2006-08-28 18:31:57 +0000
committerFlorent Villard <warly@mandriva.com>2006-08-28 18:31:57 +0000
commitaec82322751b5e0d2f242bdb4008537c72766281 (patch)
tree682261635c0fbaceb989f89cf1a2fd5bf97fc9b9 /iurt2
parent5ab191a5aaf782ecb8f5e1600815847bf58f0b5b (diff)
downloadiurt-aec82322751b5e0d2f242bdb4008537c72766281.tar
iurt-aec82322751b5e0d2f242bdb4008537c72766281.tar.gz
iurt-aec82322751b5e0d2f242bdb4008537c72766281.tar.bz2
iurt-aec82322751b5e0d2f242bdb4008537c72766281.tar.xz
iurt-aec82322751b5e0d2f242bdb4008537c72766281.zip
use $sudo0.5.8
Diffstat (limited to 'iurt2')
-rwxr-xr-xiurt243
1 files changed, 29 insertions, 14 deletions
diff --git a/iurt2 b/iurt2
index b8acbf1..dd7055a 100755
--- a/iurt2
+++ b/iurt2
@@ -36,7 +36,7 @@ use Data::Dumper;
use URPM;
use Iurt::DKMS;
use Iurt::Urpmi;
-use Iurt::Chroot qw(clean_chroot add_local_user create_temp_chroot remove_chroot clean_all_chroot_tmp clean_unionfs clean_chroot_tmp check_build_chroot);
+use Iurt::Chroot qw(add_local_user create_temp_chroot remove_chroot clean_all_chroot_tmp clean_unionfs check_build_chroot);
use Iurt::Process qw(perform_command clean kill_for_good);
use Iurt::Mail qw(sendmail);
use File::NCopy qw(copy);
@@ -47,7 +47,9 @@ use MDK::Common;
use Filesys::Df qw(df);
my $program_name = 'iurt2';
+my $VERSION = '0.5.8';
# sessing parameters
+my $sudo = '/usr/bin/sudo';
my $arg = @ARGV;
my (@params, %run);
$run{program_name} = $program_name;
@@ -237,6 +239,7 @@ $run{todo} = [ ];
open(my $LOG, ">&STDERR");
$run{LOG} = $LOG;
+print "$program_name version $VERSION\n";
my $todo = parseCommandLine($program_name, \@ARGV, \@params);
@ARGV and usage($program_name, \@params, "@ARGV, too many arguments");
@@ -273,6 +276,7 @@ my %config_usage = (
basesystem_media => { desc => 'Where to find basesystem packages', default => 'main/release' },
cache_home => { desc => 'Where to store the cache files', default => "$HOME/.bugs" },
cache_min_size => { desc => 'Minimal size to consider a cache file valid', default => 1000000 },
+ iurt_root_command => { desc => 'Program to run sudo command', default => '/usr/local/bin/iurt_root_command' },
distribution => { desc => 'Name of the packages distribution', default => 'Mandriva Linux' },
home => { desc => 'Home dir', default => $HOME },
install_chroot_binary => { desc => 'Tool used to create initial chroot', default => 'install-chroot-tar.sh' },
@@ -413,6 +417,8 @@ $run{uid} = getpwnam $run{user};
print {$run{LOG}} "$program_name: using local user $run{user}, id $run{uid}\n" if $run{verbose} > 3;
my $luser = $run{user} || 'builder';
+check_sudo_access() or die "FATAL $program_name: you need to have sudo access to run $program_name";
+
if ($run{unionfs}) {
# FIXME need to grep /proc/modules not ot try to load it if already loaded
open my $modules, '/proc/modules';
@@ -425,8 +431,7 @@ if ($run{unionfs}) {
}
if (!$ok) {
print {$run{LOG}} "$program_name: adding unionfs module\n" if $run{verbose} > 0;
- system("sudo /sbin/depmod -a");
- system("sudo /sbin/modprobe -f unionfs") and $run{unionfs} = 0;
+ system($sudo, "$config->{iurt_root_command}", "--modprobe", "unionfs") or $run{unionfs} = 0;
}
if ($run{unionfs}) {
$run{unionfs_dir} = "$config->{local_home}/iurt_unionfs$debug_tag/";
@@ -470,14 +475,14 @@ if ($df->{per} == 100) {
}
if ($run{shell}) {
- ($union_id, my $chroot_tmp) = create_temp_chroot(\%run, $config, $cache, $union_id) or die "FATAL $program_name: could not create temporary chroot";
+ ($union_id, my $chroot_tmp) = create_temp_chroot(\%run, $config, $cache, $union_id, $chroot_tmp, $chroot_tar) or die "FATAL $program_name: could not create temporary chroot";
add_local_user($chroot_tmp, \%run, $config, $luser, $run{uid}) or die "FATAL $program_name: could not add local user";
$urpmi->set_command($chroot_tmp);
$urpmi->install_packages('chroot', $chroot_tmp, $local_spool, \%pack_provide, 'configure', "[ADMIN] installation of urpmi and sudo failed in the chroot $run{my_arch}", $config->{admin}, 'urpmi', 'sudo') or die "FATAL $program_name: could not add urpmi and sudo in the chroot";
add_sudoers(\%run, $chroot_tmp, $luser);
if ($run{shell}) {
print {$run{LOG}} "$program_name: dumping to a chrooted shell into $chroot_tmp\n";
- exec "sudo chroot $chroot_tmp /bin/su $luser -c bash";
+ exec "$sudo chroot $chroot_tmp /bin/su $luser -c bash";
die "FATAL $program_name: could not exec chroot to $chroot_tmp ($!)"
}
}
@@ -579,8 +584,8 @@ do {
}
# try to workarround the rpm -qa db4 error(2) from dbcursor->c_get: No such file or directory
# system("sudo chroot $chroot_tmp rm -rf /var/lib/rpm/__db* &> /dev/null");
- system("sudo chroot $chroot_tmp rpm --rebuilddb &> /dev/null");
- perform_command("sudo chroot $chroot_tmp rpm -qa",
+ system("$sudo chroot $chroot_tmp rpm --rebuilddb &> /dev/null");
+ perform_command("$sudo chroot $chroot_tmp rpm -qa",
\%run, $config, $cache,
hash => "rpm_qa_$srpm",
timeout => 60,
@@ -593,7 +598,7 @@ do {
add_sudoers(\%run, $chroot_tmp, $luser);
$command = "rpm -b$run{stop} /home/$luser/rpm/SPECS/*.spec"
}
- if (!perform_command(qq{TMP=/home/$luser/tmp/ sudo chroot $chroot_tmp /bin/su $luser -c "$command"},
+ if (!perform_command(qq{TMP=/home/$luser/tmp/ $sudo chroot $chroot_tmp /bin/su $luser -c "$command"},
\%run, $config, $cache,
mail => $maintainer,
error => "[REBUILD] $srpm from $run{distro_tag} does not build correctly on $run{my_arch}",
@@ -609,7 +614,7 @@ do {
if ($run{stop}) {
print {$run{LOG}} "$program_name: dumping to a chrooted shell into $chroot_tmp (pid $$)\n";
# exec does not work because it seems stdin and out are shared between children
- system("sudo chroot $chroot_tmp /bin/su $luser -c bash");
+ system("$sudo chroot $chroot_tmp /bin/su $luser -c bash");
exit
}
print {$run{LOG}} "$program_name: calling callback for $opt->{hash}\n" if $run{verbose} > 4;
@@ -681,8 +686,8 @@ do {
opendir my $rpmfh, "$chroot_tmp/home/$luser/rpm/RPMS/$bindir";
push @packages, map { "$chroot_tmp/home/$luser/rpm/RPMS/$bindir/$_" } grep { !/src\.rpm$/ && /\.rpm$/ } readdir $rpmfh;
}
- # We should fail here, but rpm is currently segfaulting when trying to install packages
- $urpmi->install_packages($srpm, $chroot_tmp, $local_spool, \%pack_provide, 'binary_test', "[REBUILD] binaries packages generated from $srpm do not install correctly", @packages);# or next;
+ # 20060810 warly We should fail here, but rpm is currently segfaulting when trying to install packages
+ # $urpmi->install_packages($srpm, $chroot_tmp, $local_spool, \%pack_provide, 'binary_test', "[REBUILD] binaries packages generated from $srpm do not install correctly", @packages);# or next;
$run{status}{$srpm} = 'ok';
delete $cache->{failure}{$srpm} if defined $cache->{failure}{$srpm};
@@ -1056,7 +1061,7 @@ sub add_sudoers {
my ($run, $chroot, $user) = @_;
my $file = "$chroot/etc/sudoers";
my $f;
- if (!open $f, qq{| sudo sh -c "cat > $file"}) {
+ if (!open $f, qq{| $sudo sh -c "cat > $file"}) {
print {$run->{LOG}} "ERROR $program_name: could not open $file ($!)\n";
return 0
}
@@ -1102,7 +1107,7 @@ sub recreate_srpm {
1
});
print {$run->{LOG}} "$program_name: recreating src.rpm...\n" if $run->{verbose};
- if (!perform_command(qq{sudo chroot $chroot_tmp su $luser -c "rpm -i /home/$luser/rpm/SRPMS/$srpm"},
+ if (!perform_command(qq{$sudo chroot $chroot_tmp su $luser -c "rpm -i /home/$luser/rpm/SRPMS/$srpm"},
\%run, $config, $cache, %opt)) {
print {$run->{LOG}} "ERROR $program_name: chrooting failed (retry $opt{retry}\n" if $run->{debug};
if ($opt{retry}) {
@@ -1113,7 +1118,7 @@ sub recreate_srpm {
}
# 20060515 This should not be necessairy any more if urpmi *.spec works, but it doesn't
#
- perform_command(qq{sudo chroot $chroot_tmp su $luser -c "rpm --nodeps -bs /home/$luser/rpm/SPECS/*.spec"},
+ perform_command(qq{$sudo chroot $chroot_tmp su $luser -c "rpm --nodeps -bs /home/$luser/rpm/SPECS/*.spec"},
\%run, $config, $cache,
mail => $config->{admin},
error => "[REBUILD] cannot create $srpm in $chroot_tmp",
@@ -1220,3 +1225,13 @@ sub find_provides {
}
@rpm
}
+
+sub check_sudo_access {
+ open my $right, "$sudo -l |";
+ return 1 if ! $<;
+ while(<$right>) {
+ /\(ALL\)\s+NOPASSWD:\s+ALL/ and return 1
+ }
+ 0
+}
+