Am Montag, den 06.01.2020, 17:26 +0100 schrieb Johannes Schauer: > > > As you know from my private mail, there are now some basic > > > special hooks to > > > copy stuff in and out of the chroot. Just like with guestfish > > > hooks, > > > globbing is not (yet) supported. This could be fixed but would > > > require > > > implementing a full shell quoting parser as well as a symlink > > > resolver > > > which the current solution is working around by utilizing /bin/sh > > > inside > > > the chroot. If you want globbing, then create one hook that > > > utilizes > > > globbing in sh to create a tarball of the files you want and a > > > second hook > > > to move that tarball out of the chroot. Like this: > > > > > > --customize-hook='chroot "$1" sh -c "cd /boot && tar -cf > > > /tmp/boot.tar vmlinuz* initrd.img*"' > > > --customize-hook='copy-out /tmp/boot.tar .' > > > --customize-hook='rm "$1"/tmp/boot.tar' > > > > > > Or like this: > > > > > > --customize-hook='chroot "$1" sh -c "mkdir /tmp/boot && cp > > > /boot/vmlinuz* /boot/initrd.img* /tmp/boot"' > > > --customize-hook='copy-out /tmp/boot .' > > > --customize-hook='rm -r "$1"/tmp/boot' > > > > I tried this solution and are fine with using it. Compared to > > implementing > > globbing in mmdebstrap, this solution adds two more hooks and > > copies the > > files twice (should not have a big performance impact). > > > > The only remaining issues is that copy-out copies the directory as- > > is instead > > of copying the content of the directory. So in this your example > > above, the > > current directory would contain a directory 'boot' containing the > > kernel and > > initrd, but I like to have the kernel and initrd in the current > > directory > > (instead of the 'boot' subdirectory). Any good idea how to do > > that? > > Some ideas: > > --customize-hook='chroot "$1" sh -c "cp /boot/vmlinuz* /tmp/vmlinuz > && cp /boot/initrd.img* /tmp/initrd"' > --customize-hook='copy-out /tmp/vmlinuz .' > --customize-hook='copy-out /tmp/initrd.img .' > --customize-hook='rm "$1"/tmp/vmlinuz "$1"/tmp/initrd.img' > > or like this: > > --customize-hook='chroot "$1" sh -c "cd /boot && tar -cf > /tmp/boot.tar vmlinuz* initrd.img*"' > --customize-hook='copy-out /tmp/boot.tar .' > --customize-hook='rm "$1"/tmp/boot.tar' > --customize-hook='tar -xf boot.tar && rm boot.tar' > > or like this: > > --customize-hook='chroot "$1" sh -c "mkdir /tmp/boot && cp > /boot/vmlinuz* /boot/initrd.img* /tmp/boot"' > --customize-hook='tar-out /tmp/boot boot.tar' > --customize-hook='rm -r "$1"/tmp/boot' > --customize-hook='tar --strip-components=1 -xf boot.tar && rm > boot.tar'
I had another idea (without need for wildcard support) and wrote a patch for it (attached). Enhance the copy-out and tar-out commands to implement the behavior of rsync: Atrailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name", but in both cases the attributes of the containing directory are transferred to the containing directory on the destination. Feel free to use better variable names than used in the patch and write test cases. -- Benjamin Drung System Developer and Debian & Ubuntu Developer Platform Engineering Compute (IONOS Cloud) 1&1 IONOS SE | Greifswalder Str. 207 | 10405 Berlin | Germany E-mail: [email protected] | Web: www.ionos.de Hauptsitz Montabaur, Amtsgericht Montabaur, HRB 24498 Vorstand: Dr. Christian Böing, Hüseyin Dogan, Hans-Henning Kettler, Matthias Steinberg, Achim Weiß Aufsichtsratsvorsitzender: Markus Kadelke Member of United Internet
From e6caab3d621c2e1e2b6b7fff28f78e540c29940f Mon Sep 17 00:00:00 2001 From: Benjamin Drung <[email protected]> Date: Tue, 7 Jan 2020 09:54:20 +0100 Subject: [PATCH] copy-out/tar-out: Copy content of directory if source ends with '/' Implement the behavior of rsync for the copy-out and tar-out commands: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name", but in both cases the attributes of the containing directory are transferred to the containing directory on the destination. Bug-Debian: https://bugs.debian.org/942761 Signed-off-by: Benjamin Drung <[email protected]> --- mmdebstrap | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mmdebstrap b/mmdebstrap index 1b3dfd7..49165f6 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -2071,7 +2071,16 @@ sub main() { # the requested directory inside the chroot and writes it to # stdout. To emulate the behaviour of cp, change to the # dirname of the requested path first. - open $fh, '-|', @cmdprefix, @tarcmd, '--directory', dirname($directory), '--create', '--file', '-', basename($directory) // error "failed to fork(): $!"; + my $tar_directory; + my $relative_directory; + if (substr($directory, -1) eq '/') { + $tar_directory = $directory; + $relative_directory = '.'; + } else { + $tar_directory = dirname($directory); + $relative_directory = basename($directory); + } + open $fh, '-|', @cmdprefix, @tarcmd, '--directory', $tar_directory, '--create', '--file', '-', $relative_directory // error "failed to fork(): $!"; } if ($command eq 'copy-out') { -- 2.20.1
signature.asc
Description: This is a digitally signed message part

