aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mageia.org>2023-11-26 21:38:04 +0000
committerPascal Terjan <pterjan@mageia.org>2023-11-26 21:51:06 +0000
commit7ff06658a899afdc3a3445b66a88cb67ddc00fed (patch)
tree53112dc9809995274eadee07733392333d265893
parent92a5f7b1c1980be0ed210f03d44b1160d1d801de (diff)
downloadiurt-7ff06658a899afdc3a3445b66a88cb67ddc00fed.tar
iurt-7ff06658a899afdc3a3445b66a88cb67ddc00fed.tar.gz
iurt-7ff06658a899afdc3a3445b66a88cb67ddc00fed.tar.bz2
iurt-7ff06658a899afdc3a3445b66a88cb67ddc00fed.tar.xz
iurt-7ff06658a899afdc3a3445b66a88cb67ddc00fed.zip
iurt: Fix / of the chroot belonging to the user instead of root
-rw-r--r--NEWS1
-rwxr-xr-xiurt_root_command12
-rw-r--r--lib/Iurt/Chroot.pm19
3 files changed, 19 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index de39941..2ab56eb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
- iurt: Sort packages.arch.log
- rebuild_perl_iurt: set --target to correctly build for armv7hl on aarch64
machines
+- iurt: Fix / of the chroot belonging to the user instead of root
0.8.2.2
- ulri: Fix a crash after build failures
diff --git a/iurt_root_command b/iurt_root_command
index 87b5c5e..e64b1f7 100755
--- a/iurt_root_command
+++ b/iurt_root_command
@@ -45,7 +45,7 @@ $run{todo} = [];
#
[ "", $program_name, 0, "[--verbose <level>]
[--modprobe <module>]
- [--mkdir [--parents] <dir1> <dir2> ... <dirn>]",
+ [--mkdir [--parents] [--mode <mode>] <dir1> <dir2> ... <dirn>]",
"$program_name is a perl script to execute commands which need root privilege, it helps probram which needs occasional root privileges for some commands.",
sub { $arg or usage($program_name, \@params) }, String::Escape::elide(join(' ', "Running $program_name", @ARGV), 120) ],
@@ -77,7 +77,7 @@ $run{todo} = [];
\&ln, "Linking files" ],
[ "", "mkdir", [
- ["", "mkdir", -1, "[--parents] <dir1> <dir2> ... <dirn>", "mkdir create the given path",
+ ["", "mkdir", -1, "[--parents] [--mode <mode>] <dir1> <dir2> ... <dirn>", "mkdir create the given path",
sub {
my ($tmp, @arg) = @_;
$tmp->[0] ||= {};
@@ -87,7 +87,10 @@ $run{todo} = [];
["p", "parents", 0, "",
"Also create needed parents directories",
sub { my ($tmp) = @_; $tmp->[0]{parents} = 1; 1 }, "Set the parents flag"],
- ], "[--parents] <dir1> <dir2> ... <dirn>",
+ ["m", "mode", 1, "",
+ "Set the given mode on created directories",
+ sub { my ($tmp, $arg) = @_; $tmp->[0]{mode} = $arg; 1 }, "Set the mode flag"],
+ ], "[--parents] [--mode <mode>] <dir1> <dir2> ... <dirn>",
"mkdir create the given path",
\&mkdir, "Creating the path" ],
@@ -244,6 +247,9 @@ sub mkdir {
} else {
mkdir $path;
}
+ if ($opt->{mode}) {
+ chmod $opt->{mode}, $path;
+ }
}
1;
}
diff --git a/lib/Iurt/Chroot.pm b/lib/Iurt/Chroot.pm
index 34520d1..4949828 100644
--- a/lib/Iurt/Chroot.pm
+++ b/lib/Iurt/Chroot.pm
@@ -272,12 +272,13 @@ sub check_mounted {
}
sub check_chroot_need_update {
- my ($tmp_chroot, $run) = @_;
+ my ($tmp_chroot, $run, $config) = @_;
- my $tmp_urpmi = mktemp("$tmp_chroot/tmp.XXXXXX");
+ sudo($config, '--mkdir', "-m", 01777, "$tmp_chroot/tmp");
+ my $tmp_urpmi = mktemp("$tmp_chroot/tmp/tmp.XXXXXX");
mkdir_p("$tmp_urpmi/tmp");
my @installed_pkgs = grep { !/^gpg-pubkey/ } chomp_(cat_("$tmp_chroot/var/log/qa"));
- my @available_pkgs = chomp_(`urpmq --urpmi-root $tmp_urpmi --use-distrib $run->{urpmi}{distrib_url} --list -f 2>/dev/null`);
+ my @available_pkgs = chomp_(`urpmq --urpmi-root $tmp_urpmi --use-distrib $run->{urpmi}{distrib_url} --list -f`);
my @removed_pkgs = difference2(\@installed_pkgs, \@available_pkgs);
rm_rf($tmp_urpmi);
@@ -325,14 +326,15 @@ sub create_build_chroot_tar {
plog('NOTIFY', "creating chroot");
- mkdir_p($tmp_chroot);
+ # Create this directory as root as it will be / of the chroot
+ sudo($config, "--mkdir", "-p", "$tmp_chroot");
if (!-f $chroot_tar) {
plog("rebuild chroot tarball");
$rebuild = 1;
} elsif (!$run->{fixed_media}) {
plog('DEBUG', "decompressing /var/log/qa from $chroot_tar in $tmp_chroot");
sudo($config, '--untar', $chroot_tar, $tmp_chroot, "./var/log/qa");
- $rebuild = check_chroot_need_update($tmp_chroot, $run);
+ $rebuild = check_chroot_need_update($tmp_chroot, $run, $config);
}
if ($rebuild) {
@@ -343,15 +345,12 @@ sub create_build_chroot_tar {
return;
}
sudo($config, "--tar", $chroot_tar, $tmp_chroot);
- # This rename may fail if for example tmp chroots are in another FS
- # This does not matter as it will then be rm + untar
- rename $tmp_chroot, $chroot;
}
if (!-d $chroot) {
plog('DEBUG', "recreate chroot $chroot");
plog('NOTIFY', "recreate chroot");
- mkdir_p $chroot;
+ sudo($config, "--mkdir", "-p", "$tmp_chroot");
sudo($config, '--untar', $chroot_tar, $chroot);
plog('NOTIFY', "chroot recreated in $chroot_tar (live in $chroot)");
}
@@ -367,7 +366,7 @@ sub create_build_chroot_btrfs {
plog('NOTIFY', "creating btrfs chroot");
# TODO: Handle $run{fixed_media}
- if (check_chroot_need_update($chroot_ref, $run)) {
+ if (check_chroot_need_update($chroot_ref, $run, $config)) {
sudo($config, '--btrfs_delete', $chroot_ref);
if (!sudo($config, '--btrfs_create', $chroot_ref)) {
plog('ERROR', "creating btrfs subvolume failed.");