1 #!/bin/sh 2 3 THIS_DIR=$(realpath $(dirname "$0")) 4 5 if [ "$1" = '-q' ] ; then 6 QUIET=$1 7 shift 1 8 else 9 QUIET= 10 fi 11 12 PKGDIR=$1 13 E2ACCESS_DIR=$2 14 TARGET=$3 15 16 if [ ! -e "$PKGDIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then 17 echo "Usage: $0 [ -q ] <package directory> <e2access directory> <target>" 1>&2 18 exit 1 19 fi 20 21 PKGDIR=`realpath "$PKGDIR"` 22 E2ACCESS_DIR=`realpath "$E2ACCESS_DIR"` 23 TARGET=`realpath "$TARGET"` 24 25 # Initialise the program details and environment. 26 27 E2ACCESS="$E2ACCESS_DIR"/e2access 28 export LD_LIBRARY_PATH="$E2ACCESS_DIR" 29 30 # Make a filesystem for the example. 31 32 mkdir tmp_e2test 33 cd tmp_e2test 34 mkdir -p home/paulb/many 35 cd home/paulb/many 36 37 # Populate the directory with plenty of files. 38 39 for N in `seq 1 400`; do 40 echo "Contents of #$N." > "file-$N".txt 41 done 42 43 cd .. 44 45 # Put a file in the directory above. 46 47 cp "$PKGDIR/../docs/LICENCE.txt" . 48 49 # Leave the filesystem root. 50 51 cd ../.. 52 53 # Create a filesystem image. 54 55 EXTRA=2000 56 SIZE=$(du -s -k home | cut -f 1) 57 TOTAL=$(($SIZE + $EXTRA)) 58 59 dd if=/dev/zero of="$TARGET" bs=1024 count=$TOTAL 60 61 if ! $(/sbin/mkfs.ext2 -q "$TARGET") ; then 62 exit 1 63 fi 64 65 # Add the directory and files to the image. 66 67 "$E2ACCESS" "$TARGET" --make-dirs home/paulb/many 68 69 "$E2ACCESS" "$TARGET" --copy-in $(find home/paulb/many -maxdepth 1 -type f | sort) home/paulb/many 70 "$E2ACCESS" "$TARGET" --copy-in $(find home/paulb -maxdepth 1 -type f | sort) home/paulb 71 72 # Leave the root of the filesystem. 73 74 cd .. 75 76 if [ ! "$QUIET" ] ; then 77 "$E2ACCESS" "$TARGET" --list-dirs '' 78 "$E2ACCESS" "$TARGET" --list-dirs 'home' 79 "$E2ACCESS" "$TARGET" --list-dirs 'home/paulb' 80 "$E2ACCESS" "$TARGET" --list-dirs 'home/paulb/many' 81 fi 82 83 rm -r tmp_e2test