#!/bin/sh proc die { echo >&2 @Argv> !2 "$@" exit 1 } proc xmkdir { while test -n $1 { test -d $1 || mkdir $1 || die "Unable to mkdir $1" shift } } setglobal R = $1 test $[id -u] -eq 0 && die "This script should not be run as root, what if it does rm -rf /?" test -n $R || die "usage: prepare-chroot.sh " test -x git || die "This script needs to be executed at git source code's top directory" if test -x /bin/busybox { setglobal BB = '/bin/busybox' } elif test -x /usr/bin/busybox { setglobal BB = '/usr/bin/busybox' } else { die "You need busybox" } xmkdir $R "$R/bin" "$R/etc" "$R/lib" "$R/dev" touch "$R/dev/null" echo "root:x:0:0:root:/:/bin/sh" > "$R/etc/passwd" echo "$[id -nu]:x:$[id -u]:$[id -g]::$[pwd]/t:/bin/sh" >> "$R/etc/passwd" echo "root::0:root" > "$R/etc/group" echo "$[id -ng]::$[id -g]:$[id -nu]" >> "$R/etc/group" test -x "$R$BB" || cp $BB "$R/bin/busybox" for cmd in [sh su ls expr tr basename rm mkdir mv id uname dirname cat true sed diff] { ln -f -s /bin/busybox "$R/bin/$cmd" } mkdir -p "$R$[pwd]" rsync --exclude-from t/t1509/excludes -Ha . "$R$[pwd]" # Fake perl to reduce dependency, t1509 does not use perl, but some # env might slip through, see test-lib.sh, unset.*PERL_PATH sed 's|^PERL_PATH=.*|PERL_PATH=/bin/true|' GIT-BUILD-OPTIONS > "$R$[pwd]/GIT-BUILD-OPTIONS" for cmd in [git $BB]{ ldd $cmd | grep '/' | sed 's,.*\s\(/[^ ]*\).*,\1,' | while read i { mkdir -p "$R$[dirname $i]" cp $i "$R/$i" } } cat << """ All is set up in $R, execute t1509 with the following commands: sudo chroot $R /bin/su - $[id -nu] IKNOWWHATIAMDOING=YES ./t1509-root-worktree.sh -v -i When you are done, simply delete $R to clean up """