1#!/bin/sh 2 3die() { 4echo>&2"$@" 5exit1 6} 7 8xmkdir() { 9while[-n"$1"];do 10[-d"$1"] ||mkdir"$1"|| die "Unable to mkdir$1" 11shift 12done 13} 14 15R="$1" 16 17["$(id -u)"-eq0] && die "This script should not be run as root, what if it does rm -rf /?" 18[-n"$R"] || die "usage: prepare-chroot.sh <root>" 19[-x git ] || die "This script needs to be executed at git source code's top directory" 20if[-x/bin/busybox ];then 21 BB=/bin/busybox 22elif[-x/usr/bin/busybox ];then 23 BB=/usr/bin/busybox 24else 25 die "You need busybox" 26fi 27 28xmkdir "$R""$R/bin""$R/etc""$R/lib""$R/dev" 29touch"$R/dev/null" 30echo"root:x:0:0:root:/:/bin/sh">"$R/etc/passwd" 31echo"$(id -nu):x:$(id -u):$(id -g)::$(pwd)/t:/bin/sh">>"$R/etc/passwd" 32echo"root::0:root">"$R/etc/group" 33echo"$(id -ng)::$(id -g):$(id -nu)">>"$R/etc/group" 34 35[-x"$R$BB"] ||cp$BB"$R/bin/busybox" 36for cmd in sh su ls expr tr basename rm mkdir mv id uname dirname cat true sed diff;do 37ln-f -s/bin/busybox "$R/bin/$cmd" 38done 39 40mkdir-p"$R$(pwd)" 41rsync --exclude-from t/t1509/excludes -Ha . "$R$(pwd)" 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 44sed's|^PERL_PATH=.*|PERL_PATH=/bin/true|' GIT-BUILD-OPTIONS>"$R$(pwd)/GIT-BUILD-OPTIONS" 45for cmd in git $BB;do 46 ldd $cmd|grep'/'|sed's,.*\s\(/[^ ]*\).*,\1,'|whileread i;do 47mkdir-p"$R$(dirname $i)" 48cp"$i""$R/$i" 49done 50done 51cat<<EOF 52All is set up in$R, execute t1509 with the following commands: 53 54sudo chroot$R/bin/su -$(id -nu) 55IKNOWWHATIAMDOING=YES ./t1509-root-worktree.sh -v -i 56 57When you are done, simply delete$Rto clean up 58EOF