t / t1509 / prepare-chroot.shon commit t5004: fix issue with empty archive test and bsdtar (24676f0)
   1#!/bin/sh
   2
   3die() {
   4        echo >&2 "$@"
   5        exit 1
   6}
   7
   8xmkdir() {
   9        while [ -n "$1" ]; do
  10                [ -d "$1" ] || mkdir "$1" || die "Unable to mkdir $1"
  11                shift
  12        done
  13}
  14
  15R="$1"
  16
  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"
  20
  21xmkdir "$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"
  23echo "root:x:0:0:root:/:/bin/sh" > "$R/etc/passwd"
  24echo "$(id -nu):x:$(id -u):$(id -g)::$(pwd)/t:/bin/sh" >> "$R/etc/passwd"
  25echo "root::0:root" > "$R/etc/group"
  26echo "$(id -ng)::$(id -g):$(id -nu)" >> "$R/etc/group"
  27
  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"
  31
  32mkdir -p "$R$(pwd)"
  33rsync --exclude-from t/t1509/excludes -Ha . "$R$(pwd)"
  34ldd git | grep '/' | sed 's,.*\s\(/[^ ]*\).*,\1,' | while read i; do
  35        mkdir -p "$R$(dirname $i)"
  36        cp "$i" "$R/$i"
  37done
  38echo "Execute this in root: 'chroot $R /bin/su - $(id -nu)'"