forked from josch/mmdebstrap
preserve permissions of /etc/resolv.conf and /etc/hostname and resolve symlinks as debootstrap does it
This commit is contained in:
parent
a7c557644e
commit
165cc82f97
2 changed files with 135 additions and 15 deletions
120
coverage.sh
120
coverage.sh
|
@ -118,9 +118,8 @@ if [ ! -e shared/hooks/eatmydata/customize.sh ] || [ hooks/eatmydata/customize.s
|
||||||
cp -a /usr/share/mmdebstrap/hooks/eatmydata/customize.sh shared/hooks/eatmydata/
|
cp -a /usr/share/mmdebstrap/hooks/eatmydata/customize.sh shared/hooks/eatmydata/
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
starttime=
|
starttime=
|
||||||
total=165
|
total=166
|
||||||
skipped=0
|
skipped=0
|
||||||
runtests=0
|
runtests=0
|
||||||
i=1
|
i=1
|
||||||
|
@ -2452,6 +2451,123 @@ else
|
||||||
skipped=$((skipped+1))
|
skipped=$((skipped+1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
print_header "mode=$defaultmode,variant=custom: preserve mode of /etc/resolv.conf and /etc/hostname"
|
||||||
|
cat << END > shared/test.sh
|
||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
export LC_ALL=C.UTF-8
|
||||||
|
if [ ! -e /mmdebstrap-testenv ]; then
|
||||||
|
echo "this test modifies the system and should only be run inside a container" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
for f in /etc/resolv.conf /etc/hostname; do
|
||||||
|
# preserve original content
|
||||||
|
cat "\$f" > "\$f.bak"
|
||||||
|
# in case \$f is a symlink, we replace it by a real file
|
||||||
|
if [ -L "\$f" ]; then
|
||||||
|
rm "\$f"
|
||||||
|
cp "\$f.bak" "\$f"
|
||||||
|
fi
|
||||||
|
chmod 644 "\$f"
|
||||||
|
[ "\$(stat --format=%A "\$f")" = "-rw-r--r--" ]
|
||||||
|
done
|
||||||
|
$CMD --variant=custom --mode=$defaultmode $DEFAULT_DIST /tmp/debian-chroot $mirror
|
||||||
|
for f in /etc/resolv.conf /etc/hostname; do
|
||||||
|
[ "\$(stat --format=%A "/tmp/debian-chroot/\$f")" = "-rw-r--r--" ]
|
||||||
|
done
|
||||||
|
rm /tmp/debian-chroot/dev/console
|
||||||
|
rm /tmp/debian-chroot/dev/fd
|
||||||
|
rm /tmp/debian-chroot/dev/full
|
||||||
|
rm /tmp/debian-chroot/dev/null
|
||||||
|
rm /tmp/debian-chroot/dev/ptmx
|
||||||
|
rm /tmp/debian-chroot/dev/random
|
||||||
|
rm /tmp/debian-chroot/dev/stderr
|
||||||
|
rm /tmp/debian-chroot/dev/stdin
|
||||||
|
rm /tmp/debian-chroot/dev/stdout
|
||||||
|
rm /tmp/debian-chroot/dev/tty
|
||||||
|
rm /tmp/debian-chroot/dev/urandom
|
||||||
|
rm /tmp/debian-chroot/dev/zero
|
||||||
|
rm /tmp/debian-chroot/etc/apt/sources.list
|
||||||
|
rm /tmp/debian-chroot/etc/fstab
|
||||||
|
rm /tmp/debian-chroot/etc/hostname
|
||||||
|
rm /tmp/debian-chroot/etc/resolv.conf
|
||||||
|
rm /tmp/debian-chroot/var/lib/apt/lists/lock
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/available
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/cmethopt
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/status
|
||||||
|
# the rest should be empty directories that we can rmdir recursively
|
||||||
|
find /tmp/debian-chroot -depth -print0 | xargs -0 rmdir
|
||||||
|
for f in /etc/resolv.conf /etc/hostname; do
|
||||||
|
chmod 755 "\$f"
|
||||||
|
[ "\$(stat --format=%A "\$f")" = "-rwxr-xr-x" ]
|
||||||
|
done
|
||||||
|
$CMD --variant=custom --mode=$defaultmode $DEFAULT_DIST /tmp/debian-chroot $mirror
|
||||||
|
for f in /etc/resolv.conf /etc/hostname; do
|
||||||
|
[ "\$(stat --format=%A "/tmp/debian-chroot/\$f")" = "-rwxr-xr-x" ]
|
||||||
|
done
|
||||||
|
rm /tmp/debian-chroot/dev/console
|
||||||
|
rm /tmp/debian-chroot/dev/fd
|
||||||
|
rm /tmp/debian-chroot/dev/full
|
||||||
|
rm /tmp/debian-chroot/dev/null
|
||||||
|
rm /tmp/debian-chroot/dev/ptmx
|
||||||
|
rm /tmp/debian-chroot/dev/random
|
||||||
|
rm /tmp/debian-chroot/dev/stderr
|
||||||
|
rm /tmp/debian-chroot/dev/stdin
|
||||||
|
rm /tmp/debian-chroot/dev/stdout
|
||||||
|
rm /tmp/debian-chroot/dev/tty
|
||||||
|
rm /tmp/debian-chroot/dev/urandom
|
||||||
|
rm /tmp/debian-chroot/dev/zero
|
||||||
|
rm /tmp/debian-chroot/etc/apt/sources.list
|
||||||
|
rm /tmp/debian-chroot/etc/fstab
|
||||||
|
rm /tmp/debian-chroot/etc/hostname
|
||||||
|
rm /tmp/debian-chroot/etc/resolv.conf
|
||||||
|
rm /tmp/debian-chroot/var/lib/apt/lists/lock
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/available
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/cmethopt
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/status
|
||||||
|
# the rest should be empty directories that we can rmdir recursively
|
||||||
|
find /tmp/debian-chroot -depth -print0 | xargs -0 rmdir
|
||||||
|
for f in /etc/resolv.conf /etc/hostname; do
|
||||||
|
rm "\$f"
|
||||||
|
ln -s "\$f.bak" "\$f"
|
||||||
|
[ "\$(stat --format=%A "\$f")" = "lrwxrwxrwx" ]
|
||||||
|
done
|
||||||
|
$CMD --variant=custom --mode=$defaultmode $DEFAULT_DIST /tmp/debian-chroot $mirror
|
||||||
|
for f in /etc/resolv.conf /etc/hostname; do
|
||||||
|
[ "\$(stat --format=%A "/tmp/debian-chroot/\$f")" = "-rw-r--r--" ]
|
||||||
|
done
|
||||||
|
rm /tmp/debian-chroot/dev/console
|
||||||
|
rm /tmp/debian-chroot/dev/fd
|
||||||
|
rm /tmp/debian-chroot/dev/full
|
||||||
|
rm /tmp/debian-chroot/dev/null
|
||||||
|
rm /tmp/debian-chroot/dev/ptmx
|
||||||
|
rm /tmp/debian-chroot/dev/random
|
||||||
|
rm /tmp/debian-chroot/dev/stderr
|
||||||
|
rm /tmp/debian-chroot/dev/stdin
|
||||||
|
rm /tmp/debian-chroot/dev/stdout
|
||||||
|
rm /tmp/debian-chroot/dev/tty
|
||||||
|
rm /tmp/debian-chroot/dev/urandom
|
||||||
|
rm /tmp/debian-chroot/dev/zero
|
||||||
|
rm /tmp/debian-chroot/etc/apt/sources.list
|
||||||
|
rm /tmp/debian-chroot/etc/fstab
|
||||||
|
rm /tmp/debian-chroot/etc/hostname
|
||||||
|
rm /tmp/debian-chroot/etc/resolv.conf
|
||||||
|
rm /tmp/debian-chroot/var/lib/apt/lists/lock
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/available
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/cmethopt
|
||||||
|
rm /tmp/debian-chroot/var/lib/dpkg/status
|
||||||
|
# the rest should be empty directories that we can rmdir recursively
|
||||||
|
find /tmp/debian-chroot -depth -print0 | xargs -0 rmdir
|
||||||
|
END
|
||||||
|
if [ "$HAVE_QEMU" = "yes" ]; then
|
||||||
|
./run_qemu.sh
|
||||||
|
runtests=$((runtests+1))
|
||||||
|
else
|
||||||
|
echo "HAVE_QEMU != yes -- Skipping test..." >&2
|
||||||
|
skipped=$((skipped+1))
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
|
||||||
print_header "mode=$defaultmode,variant=essential: test not having to install apt in --include because a hook did it before"
|
print_header "mode=$defaultmode,variant=essential: test not having to install apt in --include because a hook did it before"
|
||||||
cat << END > shared/test.sh
|
cat << END > shared/test.sh
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
30
mmdebstrap
30
mmdebstrap
|
@ -1662,19 +1662,23 @@ sub run_setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# allow network access from within
|
# allow network access from within
|
||||||
if (-e "/etc/resolv.conf") {
|
foreach my $file ("/etc/resolv.conf", "/etc/hostname") {
|
||||||
copy("/etc/resolv.conf", "$options->{root}/etc/resolv.conf")
|
if (-e $file) {
|
||||||
or error "cannot copy /etc/resolv.conf: $!";
|
# this will create a new file with 644 permissions and copy
|
||||||
} else {
|
# contents only even if $file was a symlink
|
||||||
warning("Host system does not have a /etc/resolv.conf to copy into the"
|
copy($file, "$options->{root}/$file")
|
||||||
. " rootfs.");
|
or error "cannot copy $file: $!";
|
||||||
}
|
# if the source was a regular file, preserve the permissions
|
||||||
if (-e "/etc/hostname") {
|
if (-f $file) {
|
||||||
copy("/etc/hostname", "$options->{root}/etc/hostname")
|
my $mode = (stat($file))[2];
|
||||||
or error "cannot copy /etc/hostname: $!";
|
$mode &= oct(7777); # mask off bits that aren't the mode
|
||||||
} else {
|
chmod $mode, "$options->{root}/$file"
|
||||||
warning("Host system does not have a /etc/hostname to copy into the"
|
or error "cannot chmod $file: $!";
|
||||||
. " rootfs.");
|
}
|
||||||
|
} else {
|
||||||
|
warning("Host system does not have a $file to copy into the"
|
||||||
|
. " rootfs.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options->{havemknod}) {
|
if ($options->{havemknod}) {
|
||||||
|
|
Loading…
Reference in a new issue