Git 1.7.3 rc1
[git/mingw/4msysgit/kblees.git] / t / t1509 / prepare-chroot.sh
blobc5334a8fa416aedd66a12416c75e85dbd9b6ac70
1 #!/bin/sh
3 die() {
4 echo >&2 "$@"
5 exit 1
8 xmkdir() {
9 while [ -n "$1" ]; do
10 [ -d "$1" ] || mkdir "$1" || die "Unable to mkdir $1"
11 shift
12 done
15 R="$1"
17 [ -n "$R" ] || die "Usage: prepare-chroot.sh <root>"
18 [ -x git ] || die "This script needs to be executed at git source code's top directory"
19 [ -x /bin/busybox ] || die "You need busybox"
21 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"
23 echo "root:x:0:0:root:/:/bin/sh" > "$R/etc/passwd"
24 echo "$(id -nu):x:$(id -u):$(id -g)::$(pwd)/t:/bin/sh" >> "$R/etc/passwd"
25 echo "root::0:root" > "$R/etc/group"
26 echo "$(id -ng)::$(id -g):$(id -nu)" >> "$R/etc/group"
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"
32 mkdir -p "$R$(pwd)"
33 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"
37 done
38 echo "Execute this in root: 'chroot $R /bin/su - $(id -nu)'"