Skip to content

Commit ef8163c

Browse files
committed
Merge branch 'nd/t1509-chroot-test'
Correct test bitrot. * nd/t1509-chroot-test: t1509: update prepare script to be able to run t1509 in chroot again
2 parents 67e5a00 + 64f2589 commit ef8163c

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

t/t1509/prepare-chroot.sh

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,45 @@ xmkdir() {
1414

1515
R="$1"
1616

17+
[ "$(id -u)" -eq 0 ] && die "This script should not be run as root, what if it does rm -rf /?"
1718
[ -n "$R" ] || die "usage: prepare-chroot.sh <root>"
1819
[ -x git ] || die "This script needs to be executed at git source code's top directory"
19-
[ -x /bin/busybox ] || die "You need busybox"
20+
if [ -x /bin/busybox ]; then
21+
BB=/bin/busybox
22+
elif [ -x /usr/bin/busybox ]; then
23+
BB=/usr/bin/busybox
24+
else
25+
die "You need busybox"
26+
fi
2027

2128
xmkdir "$R" "$R/bin" "$R/etc" "$R/lib" "$R/dev"
22-
[ -c "$R/dev/null" ] || die "/dev/null is missing. Do mknod $R/dev/null c 1 3 && chmod 666 $R/dev/null"
29+
touch "$R/dev/null"
2330
echo "root:x:0:0:root:/:/bin/sh" > "$R/etc/passwd"
2431
echo "$(id -nu):x:$(id -u):$(id -g)::$(pwd)/t:/bin/sh" >> "$R/etc/passwd"
2532
echo "root::0:root" > "$R/etc/group"
2633
echo "$(id -ng)::$(id -g):$(id -nu)" >> "$R/etc/group"
2734

28-
[ -x "$R/bin/busybox" ] || cp /bin/busybox "$R/bin/busybox"
29-
[ -x "$R/bin/sh" ] || ln -s /bin/busybox "$R/bin/sh"
30-
[ -x "$R/bin/su" ] || ln -s /bin/busybox "$R/bin/su"
35+
[ -x "$R$BB" ] || cp $BB "$R/bin/busybox"
36+
for cmd in sh su ls expr tr basename rm mkdir mv id uname dirname cat true sed diff; do
37+
ln -f -s /bin/busybox "$R/bin/$cmd"
38+
done
3139

3240
mkdir -p "$R$(pwd)"
3341
rsync --exclude-from t/t1509/excludes -Ha . "$R$(pwd)"
34-
ldd git | grep '/' | sed 's,.*\s\(/[^ ]*\).*,\1,' | while read i; do
35-
mkdir -p "$R$(dirname $i)"
36-
cp "$i" "$R/$i"
42+
# Fake perl to reduce dependency, t1509 does not use perl, but some
43+
# env might slip through, see test-lib.sh, unset.*PERL_PATH
44+
sed 's|^PERL_PATH=.*|PERL_PATH=/bin/true|' GIT-BUILD-OPTIONS > "$R$(pwd)/GIT-BUILD-OPTIONS"
45+
for cmd in git $BB;do
46+
ldd $cmd | grep '/' | sed 's,.*\s\(/[^ ]*\).*,\1,' | while read i; do
47+
mkdir -p "$R$(dirname $i)"
48+
cp "$i" "$R/$i"
49+
done
3750
done
38-
echo "Execute this in root: 'chroot $R /bin/su - $(id -nu)'"
51+
cat <<EOF
52+
All is set up in $R, execute t1509 with the following commands:
53+
54+
sudo chroot $R /bin/su - $(id -nu)
55+
IKNOWWHATIAMDOING=YES ./t1509-root-worktree.sh -v -i
56+
57+
When you are done, simply delete $R to clean up
58+
EOF

0 commit comments

Comments
 (0)